renamepalooza time

Jonathan M Davis jmdavisProg at gmx.com
Fri Jan 21 14:44:34 PST 2011


On Friday, January 21, 2011 13:46:11 Tomek Sowiński wrote:
> Jonathan M Davis napisał:
> > > > These should be expanded a bit and camelCased:
> > > >    LS:        lineSep, lineSeparator
> > > >    PS:        paragraphSep, paragraphSeparator
> > > 
> > > Isn't there a rule that constants all fully uppercase?
> > 
> > That would be typical in C++ or Java, but that's not the case in D.
> > Phobos certainly doesn't work that way in general, and Andrei doesn't
> > want it to. The reasoning is that constants are so common in D (likely
> > due to CTFE) that you'd have variables all over the place which were in
> > all caps, and it would get really annoying.
> 
> Right on.
> 
> > So, no. There is no rule in D that constants should be fully
> > uppercase.
> 
> So if not uppercase, what is the convention for constants then? And, to
> hair-split more, what is a constant to begin with? Would e.g. a big
> immutable configuration tree structure fall into that bucket? Or a logger
> object?

As far as Phobos goes, constants are named the same way that any other variable 
is. I don't think that there are any special naming conventions based on 
variable type or constness or whatnot. It's all based on the type of symbol. 
Typically, everything is camelcase, user-defined types start with a capital 
letter, and everything else starts with a lowercase letter.

The most typical constants are enums, but there are cases where you can't do 
that, because CTFE isn't advanced enough yet (like with you configuration tree 
structure), in which case immutable is used along with static constructors. 
Ideally though, they'd pretty much always be generated with CTFE and be enums.

Generally-speaking, when referring to constants, people are referring to 
variables with a global lifetime which are set to an initial value and never 
(and cannot ever) change once set.

- Jonathan M Davis


More information about the Digitalmars-d mailing list