www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Naming Conventions & Style Guide?

reply %u <wfunction hotmail.com> writes:
Is there any particular reason that Phobos uses ALL_CAPS (such as
FunctionAttributes.NOTHROW) and PascalCase (such as Endian.BigEndian) for
enums, and yet the D Style Guide recommends lowerCamelCase?
Jan 22 2011
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Saturday 22 January 2011 15:58:47 %u wrote:
 Is there any particular reason that Phobos uses ALL_CAPS (such as
 FunctionAttributes.NOTHROW) and PascalCase (such as Endian.BigEndian) for
 enums, and yet the D Style Guide recommends lowerCamelCase?

Differences in who wrote the code and when. Some of the code in Phobos likely pre-dates the style guide and other code might be written by a developer who wasn't actually paying attention to the style guide. Overall, while the code in Phobos is generally pretty similar in style, the developers have sometimes been a bit lax in following any specific style, and there has been some talk of fixing that. My guess in this case that either the enums in question pre-date the style guide (Endian.BigEndian probably does) or that the developer in question was just doing what is more typical in other languages - which is naming constants in all caps - and didn't remember that that's not how it's typically done in D. The style guide is the sort of thing that people are likely to read once and forget about - particularly if it's very close to what they do normally. There has been some cleanup going on in naming things according to the style guide, so those may get renamed at some point. I really don't think that there's really any big reason though as to why the don't currently match the style guide. - Jonathan M Davis
Jan 22 2011
prev sibling next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Hmm.. I thought naming enums with capital letters was a standard thing
in D land. I prefer them that way since they're constants, and since I
almost always use a tag for an enum I never mistake it for anything
else. YMMV.
Jan 22 2011
next sibling parent reply %u <wfunction hotmail.com> writes:
 Hmm.. I thought naming enums with capital letters was a standard thing in D

use a tag for an enum I never mistake it for anything else. YMMV. Huh, I guess now I see why they are the way they are. :) At first I wrapped Win32 constants, and so they were ALL_CAPS. Then I converted them to Windows/.NET-style, and they became PascalCased (both native and .NET use PascalCase)... then I read the style guide and started making them camelCased, and now I have code in each of these styles. Yeah, MMWV. :]
Jan 22 2011
parent %u <wfunction hotmail.com> writes:
 I don't know what that abbreviation means.

Haha I kind of made that up... just meant "My Mileage *Will* Vary" :) Huh, I never noticed the keyword conflict; that's totally legitimate, although personally I'd prefer PascalCased. But I don't like the "related to the language" idea; it shouldn't be any different. Interesting to know, though, nevertheless. :]
Jan 23 2011
prev sibling parent spir <denis.spir gmail.com> writes:
On 01/23/2011 06:05 AM, %u wrote:
 Hmm.. I thought naming enums with capital letters was a standard thing in D

use a tag for an enum I never mistake it for anything else. YMMV. Huh, I guess now I see why they are the way they are. :) At first I wrapped Win32 constants, and so they were ALL_CAPS. Then I converted them to Windows/.NET-style, and they became PascalCased (both native and .NET use PascalCase)... then I read the style guide and started making them camelCased, and now I have code in each of these styles. Yeah, MMWV. :]

lol! -- _________________ vita es estrany spir.wikidot.com
Jan 23 2011
prev sibling next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Saturday 22 January 2011 20:51:47 Andrej Mitrovic wrote:
 Hmm.. I thought naming enums with capital letters was a standard thing
 in D land. I prefer them that way since they're constants, and since I
 almost always use a tag for an enum I never mistake it for anything
 else. YMMV.

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. - Jonathan M Davis
Jan 22 2011
prev sibling next sibling parent spir <denis.spir gmail.com> writes:
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! ??? Denis -- _________________ vita es estrany spir.wikidot.com
Jan 23 2011
prev sibling next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Jan 23 2011
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 1/23/11, %u <wfunction hotmail.com> wrote:
 Yeah, MMWV. :]

Men are from Mars, Women are from Venus? :D I don't know what that abbreviation means. I think some enums are in all caps because they're a workaround for not being able to use e.g. "in" in a TypeTuple, so they're kind of special. Specifically I saw that: ParameterStorageClassTuple returns a Tuple with enum values that are declared with all caps, while ParameterTypeTuple returns actual types that you can use directly in a new function signature. That's just a guess though. Another guess is that they're in all caps because they're directly related to the language itself. While "LibraryEnum.EmailRegex" is unrelated to the language itself, "ParameterStorageClass.REF" refers directly to a D feature, ref parameters. I'm only speculating, though.
Jan 23 2011