Naming convention in Phobos

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Mon Mar 7 01:51:03 PST 2011


On Mon, 07 Mar 2011 09:36:11 +0000, %u wrote:

>> The general naming convention as far as variable names go is camelcased
>> with the name starting with a lower case letter - this includes
>> constants. Most of Phobos follows this, and the parts that
> haven't been have been moving towards it. There are likely to be a few
> exceptions, but on the whole, that's how it's supposed to be. Type names
> are the same, except they start with an upper case letter (this includes
> enum names - the enum values are capitalized the same as any other
> variables however). That's the way it has been, and that's the way that
> it's pretty much guaranteed to stay.
> 
> 
> I don't like the idea that enum values (which are constants) would also
> be camelCased; I think they should be PascalCased. Why? Simply because
> something like:
> 
> enum InteropKind
> {
>     import,
>     export
> }
> 
> won't compile.

I don't think I understand your reasoning.  Enum members can't have names 
which are also keywords, hence enums should be capitalised?  You could 
equally well use this argument for *all* D symbols...


> Furthermore, these aren't "variables" (they can't vary
> *at all*, even through casts -- unlike immutables) so I think enum
> values should be CamelCased. (PLEASE DO NOT USE ALL CAPS as it has no
> real benefit, and since it needlessly forces the use of underscores.)

I don't think the distinction is between variables and non-variables.  
Rather, the distinction is between functions and values on one side and 
types on the other.  Functions and values are camel-cased, while types 
are capitalised.

That leaves the question about how to name templates.  In Phobos, the 
rule is extended to templates as follows:

camelCase:
 - function templates
 - templates that evaluate to values

Capitalise:
 - mixin templates
 - class/struct templates


-Lars

-Lars


More information about the Digitalmars-d mailing list