digitalmars.D.learn - Naming Conventions & Style Guide?
- %u (3/3) Jan 22 2011 Is there any particular reason that Phobos uses ALL_CAPS (such as
- Jonathan M Davis (17/20) Jan 22 2011 Differences in who wrote the code and when. Some of the code in Phobos l...
- Andrej Mitrovic (4/4) Jan 22 2011 Hmm.. I thought naming enums with capital letters was a standard thing
- %u (7/8) Jan 22 2011 land. I prefer them that way since they're constants, and since I almost...
- spir (6/14) Jan 23 2011 lol!
- Andrej Mitrovic (16/17) Jan 23 2011 Men are from Mars, Women are from Venus? :D
- %u (5/6) Jan 23 2011 Haha I kind of made that up... just meant "My Mileage *Will* Vary" :)
- Jonathan M Davis (8/12) Jan 22 2011 The problem is that constants are used all over the place in D - far mor...
- spir (10/16) Jan 23 2011 ---------
- Jonathan M Davis (13/27) Jan 23 2011 Constants in programming languages are pretty much _always_ variables. T...
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
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
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
Hmm.. I thought naming enums with capital letters was a standard thing in Dland. 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. 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
On 01/23/2011 06:05 AM, %u wrote:lol! -- _________________ vita es estrany spir.wikidot.comHmm.. I thought naming enums with capital letters was a standard thing in Dland. 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. 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 23 2011
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
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
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
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
On Sunday 23 January 2011 03:22:36 spir wrote:On 01/23/2011 06:28 AM, Jonathan M Davis wrote: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 DavisThe 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! ???
Jan 23 2011