Re: Clojure Naming Conventions

2009-02-21 Thread Mark Volkmann

On Sat, Feb 21, 2009 at 2:47 PM, Howard Lewis Ship  wrote:
>
> I'm kind of used to Java nowadays, where CONSTANTS_ARE_UPPERCASE.  I'm
> trying to figure out if Clojure has equivalent conventions.
>
> What I've seen:
>
> names-with-dashes instead of CamelCase

Right.

> *global* for global variables (?)

I thought that too at first, but it was explained to me that names
surrounded by asterisks indicates that those are variables that are
anticipated to be used with the binding function to bind them to a
different value. Stu talks about this in the beta 7 version of his
book where he discusses "Acting At a Distance" in chapter 6. The point
is that many functions may rely on those "special variables" and
binding them to a different value changes what those functions do.

A good example is *out*. If you bind it to a Writer that writes to a
file, all calls to println that occur within that binding scope will
write the file instead of stdout.

> Parameter name conventions (from Stu's book): val, coll, a, etc.
>
> What are the accepted conventions?

As best I can tell Clojure doesn't have a convention for constant names.

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread Luc Prefontaine
In our software, we use uppercase or +name+ as constant names.
Both Java and RUBY use uppercase, I think it's more a matter of taste
what you decide to use.
Ideally it should be obvious by looking at the name that some name is a
constant name.

Both of the above satisfy this criteria.

Luc

On Sat, 2009-02-21 at 12:47 -0800, Howard Lewis Ship wrote:

> I'm kind of used to Java nowadays, where CONSTANTS_ARE_UPPERCASE.  I'm
> trying to figure out if Clojure has equivalent conventions.
> 
> What I've seen:
> 
> names-with-dashes instead of CamelCase
> *global* for global variables (?)
> Parameter name conventions (from Stu's book): val, coll, a, etc.
> 
> What are the accepted conventions?
> 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread David Nolen
+name+ is also in line with Common Lisp patterns
http://www.cliki.net/Naming%20conventions
On Sat, Feb 21, 2009 at 4:07 PM, Luc Prefontaine <
lprefonta...@softaddicts.ca> wrote:

>  In our software, we use uppercase or +name+ as constant names.
> Both Java and RUBY use uppercase, I think it's more a matter of taste what
> you decide to use.
> Ideally it should be obvious by looking at the name that some name is a
> constant name.
>
> Both of the above satisfy this criteria.
>
> Luc
>
> On Sat, 2009-02-21 at 12:47 -0800, Howard Lewis Ship wrote:
>
> I'm kind of used to Java nowadays, where CONSTANTS_ARE_UPPERCASE.  I'mtrying 
> to figure out if Clojure has equivalent conventions.
> What I've seen:
> names-with-dashes instead of CamelCase*global* for global variables 
> (?)Parameter name conventions (from Stu's book): val, coll, a, etc.
> What are the accepted conventions?
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread Phil Hagelberg

Mark Volkmann  writes:

> As best I can tell Clojure doesn't have a convention for constant names.

Everything that's not expected to be rebound at runtime
(*special-variables*) is by definition a constant (with the exception of
refs, agents, and atoms). You don't need a special "constant naming
convention". Perhaps some kind of convention for naming non-constants
would be more appropriate since they're the exception rather than the
rule, but I don't know of any such convention. The fact that those
identifiers are always prefixed with @ for deref'ing them may be enough.

-Phil

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread David Nolen
The fact that the Clojure data structures are immutable and that some of
those data structures might be used logically constants are two separate
concerns.  When reading Clojure code, we've already internalized the fact
that the data structures are immutable.  Using a naming convention for a
constant just simply marks clearly the intended use.
On Sat, Feb 21, 2009 at 4:29 PM, Phil Hagelberg  wrote:

>
> Mark Volkmann  writes:
>
> > As best I can tell Clojure doesn't have a convention for constant names.
>
> Everything that's not expected to be rebound at runtime
> (*special-variables*) is by definition a constant (with the exception of
> refs, agents, and atoms). You don't need a special "constant naming
> convention". Perhaps some kind of convention for naming non-constants
> would be more appropriate since they're the exception rather than the
> rule, but I don't know of any such convention. The fact that those
> identifiers are always prefixed with @ for deref'ing them may be enough.
>
> -Phil
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread Phil Hagelberg

David Nolen  writes:

> The fact that the Clojure data structures are immutable and that some
> of those data structures might be used logically constants are two
> separate concerns.

I don't understand what this means. What's the difference between using
a value that doesn't change and using a value as a logical constant? Are
you talking about changing the value of a var by calling "def" on it
again instead of using "binding"?

-Phil

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread David Nolen
My point is simply that whether something is immutable or not has nothing to
do with how that data structure is being used in the program.  Naming
conventions signify usage.  You could write a pure Java program and make it
pretty darn functional. You would still want to mark values that are
logically treated as constants as such.
And I don't things are not so different in Clojure. In many programs you
will create structures for the intention of changing them. This is I think
Rich's point about separating state and identity.  Yes data structures are
immutable, but vars help the programmer wrap their head around the
identities.

vars in Clojure are a tool for reasoning about a program that uses immutable
data structures.

And using a naming convention for vars that represent constants is yet
another tool for reasoning about the program.

On Sat, Feb 21, 2009 at 5:24 PM, Phil Hagelberg  wrote:

>
> David Nolen  writes:
>
> > The fact that the Clojure data structures are immutable and that some
> > of those data structures might be used logically constants are two
> > separate concerns.
>
> I don't understand what this means. What's the difference between using
> a value that doesn't change and using a value as a logical constant? Are
> you talking about changing the value of a var by calling "def" on it
> again instead of using "binding"?
>
> -Phil
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread Chouser

On Sat, Feb 21, 2009 at 5:36 PM, David Nolen  wrote:
> My point is simply that whether something is immutable or not has nothing to
> do with how that data structure is being used in the program.
> Naming conventions signify usage.  You could write a pure Java
> program and make it pretty darn functional. You would still want to
> mark values that are logically treated as constants as such.

Most named Vars are given a single value and this is never changed at
all.  They are created with 'def' or some variation thereof, and then
examined in various ways, but not given new values.  They are constant
and they are named in the normal Clojure way: lowercase with dashes.

Sometimes these Vars are changed later with another 'def', but this is
meant to be a development or debugging technique, not something that
should be incorporated into normal program logic.  Anticipating this
kind of change (or not) shouldn't influence the name of the Var.

Some named Vars are expected to be given a thread-local value with
'binding', and in even more rare cases then adjusted using 'set!'.
This usage is unusual enough that the names of such Vars warrant the
*earmuffs*.

Even less commonly than any of the above is changing a Var's root
value with 'alter-var-root'.  This is perhaps unusual enough that it
warrants a naming convention to indicate that this particular Var will
actually be non-constant at its root.

Is there some other distinction that needs to be made?  Does logically
constant mean something different from what I've described above?

--Chouser

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread David Nolen
Thanks for the points.
What I was thinking, was that for things like π, in Clojure (as in CL),
perhaps it makes to sense to mark it like so:

+pi+

On Sat, Feb 21, 2009 at 8:59 PM, Chouser  wrote:

>
> On Sat, Feb 21, 2009 at 5:36 PM, David Nolen 
> wrote:
> > My point is simply that whether something is immutable or not has nothing
> to
> > do with how that data structure is being used in the program.
> > Naming conventions signify usage.  You could write a pure Java
> > program and make it pretty darn functional. You would still want to
> > mark values that are logically treated as constants as such.
>
> Most named Vars are given a single value and this is never changed at
> all.  They are created with 'def' or some variation thereof, and then
> examined in various ways, but not given new values.  They are constant
> and they are named in the normal Clojure way: lowercase with dashes.
>
> Sometimes these Vars are changed later with another 'def', but this is
> meant to be a development or debugging technique, not something that
> should be incorporated into normal program logic.  Anticipating this
> kind of change (or not) shouldn't influence the name of the Var.
>
> Some named Vars are expected to be given a thread-local value with
> 'binding', and in even more rare cases then adjusted using 'set!'.
> This usage is unusual enough that the names of such Vars warrant the
> *earmuffs*.
>
> Even less commonly than any of the above is changing a Var's root
> value with 'alter-var-root'.  This is perhaps unusual enough that it
> warrants a naming convention to indicate that this particular Var will
> actually be non-constant at its root.
>
> Is there some other distinction that needs to be made?  Does logically
> constant mean something different from what I've described above?
>
> --Chouser
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread Chouser

On Sat, Feb 21, 2009 at 9:05 PM, David Nolen  wrote:
> Thanks for the points.
> What I was thinking, was that for things like π, in Clojure (as in CL),
> perhaps it makes to sense to mark it like so:
> +pi+

Is 'pi' more constant than, say, 'rem'?  One implements IFn, the other
doesn't, but neither changes.  This distinction is even more blurred
when the value held by the Var is both a collection and fn, like a map
or vector.

--Chouser

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-21 Thread Luc Prefontaine
We chose to keep a naming convention for constants mainly because we are
mixing Java, Ruby
and Clojure in the same system. We have to replicate constants between
the different languages.
We needed a common anchor somehow to keep track of things and be able to
track down
changes.

We typically use uppercase for shared constants and +name+  for the
Clojure
only stuff that may eventually be shared in the future.

Of course in a pure Clojure system, this may be unnecessary given the
immutability by default behaviour.

Luc

On Sat, 2009-02-21 at 22:55 -0500, Chouser wrote:

> On Sat, Feb 21, 2009 at 9:05 PM, David Nolen  wrote:
> > Thanks for the points.
> > What I was thinking, was that for things like π, in Clojure (as in CL),
> > perhaps it makes to sense to mark it like so:
> > +pi+
> 
> Is 'pi' more constant than, say, 'rem'?  One implements IFn, the other
> doesn't, but neither changes.  This distinction is even more blurred
> when the value held by the Var is both a collection and fn, like a map
> or vector.
> 
> --Chouser
> 
> > 
> 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Naming Conventions

2009-02-22 Thread Laurent PETIT
2009/2/22 Chouser 

>
> On Sat, Feb 21, 2009 at 5:36 PM, David Nolen 
> wrote:
> > My point is simply that whether something is immutable or not has nothing
> to
> > do with how that data structure is being used in the program.
> > Naming conventions signify usage.  You could write a pure Java
> > program and make it pretty darn functional. You would still want to
> > mark values that are logically treated as constants as such.
>
> Most named Vars are given a single value and this is never changed at
> all.  They are created with 'def' or some variation thereof, and then
> examined in various ways, but not given new values.  They are constant
> and they are named in the normal Clojure way: lowercase with dashes.
>
> Sometimes these Vars are changed later with another 'def', but this is
> meant to be a development or debugging technique, not something that
> should be incorporated into normal program logic.  Anticipating this
> kind of change (or not) shouldn't influence the name of the Var.
>
> Some named Vars are expected to be given a thread-local value with
> 'binding', and in even more rare cases then adjusted using 'set!'.
> This usage is unusual enough that the names of such Vars warrant the
> *earmuffs*.
>
> Even less commonly than any of the above is changing a Var's root
> value with 'alter-var-root'.  This is perhaps unusual enough that it
> warrants a naming convention to indicate that this particular Var will
> actually be non-constant at its root.
>
> Is there some other distinction that needs to be made?  Does logically
> constant mean something different from what I've described above?
>


+1

A constant value can be considered as a pure function with no argument, so I
totally agree that we can follow the same naming convention for constant
value than for functions.

So, to summarize my thought and rework the initial categorization attempt
made my Howard :

 * lowercase-names-with-dashes : constant values. Be there global functions
with zero or more arguments, functions arguments, names introduced by let.
When they are global functions, there are some ways to change their value in
Clojure, but this should be done only during development (e.g. for debugging
purpose).
 * lowercase-names-with-dashes inside asterisks : values that are thread
bound. Generally introduced as global vars, or very rarely via
'with-local-vars. Their value is generally re-bound via the 'binding special
form.


Note I added "lowercase" to "names-with-dashes", so that names without
dashes don't interfere with classnames (in java the convention for class
names is to begin with an upper case letter)

HTH,

-- 
Laurent

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---