Naming Conventions & Style Guide?

Jonathan M Davis jmdavisProg at gmx.com
Sun Jan 23 03:56:39 PST 2011


On Sunday 23 January 2011 03:22:36 spir wrote:
> On 01/23/2011 06:28 AM, Jonathan M Davis wrote:
> > The problem is that constants are used all over the place in D - far more
> > than you'd use in most other languages (primarily because of CTFE, I
> > belive). If you use all-caps for stuff like enums, then you're
> > constantly using variables which are all in caps. It would get really
> > annoying. In particular, Andrei doesn't like that, so he wants constants
> > - which would include all enums - to have the same naming convention as
> > the other variables.
> 
>                                        ---------
> 
> Don't you find this strange: I guess most people agree that enums define (a
> form of) constants --as shown by words used is this thread. Right? Then, we
> have constant variables! ???

Constants in programming languages are pretty much _always_ variables. They just 
can't be mutated. Often, such variables can be optimized away, since their value 
is known (and likely even more so in D than other languages thanks to CTFE), but 
they're still variables.

Not to mention, you have const and immutable modifiers for variables, so you have 
const and immutable variables right there. The term variable in programming 
languages really doesn't have all that much to do with the mathematical term 
variable. Really, it's referring to a block of memory which holds a value. 
Often, that block of memory is mutable, but sometimes not - like with enums. But 
regardless, a variable refers to a block of memory which holds a value. How 
"variable" that value is is irrelevant.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list