D naming style?
Stewart Gordon
smjg_1998 at yahoo.com
Sun Sep 6 09:46:07 PDT 2009
Michel Fortin wrote:
<snip>
> Here it is: <http://www.digitalmars.com/d/2.0/dstyle.html>.
My style more or less resembles this, except:
- Each indentation level is a tab character (by far the most sensible
way to do things)
- Usually one blank line between class methods, and two between
module-level declarations
- I nearly always use /+ ... +/ or // to comment out code
- I've variously used UpperCamelCase or ALL_CAPS for enum names, though
for enum value names it's always ALL_CAPS. (Phobos breaks both these
rules in places, e.g. FileMode.Out.)
> I've also written a guide on how to name things, but, as far as I know,
> nobody is following it at the moment. Hopefully it can be improved and
> serve as the basis for naming things in Phobos (although I'm beginning
> to be skeptical about that). See
> <http://prowiki.org/wiki4d/wiki.cgi?DProgrammingGuidelines>.
1. That page contradicts itself - first
`Accessor functions can be nouns, adjectives, or third-person verbs with
an object.`
then
`Boolean properties should start with "is", "has", or a modal verb such
as "can" and "should".`
even giving "enabled" as an example in each case.
2. `[should we allow some exceptions here? sin(x) comes to mind] `
What is this supposed to mean?
3. One-letter parameter names are, IMO, OK for property setters and
maybe other cases where the nature of the parameter is obvious from the
function name. And when they're the likes of 'x' and 'y' for Cartesian
coordinates and what they're the coordinates of is obvious. But
otherwise, I agree that they ought to be avoided.
4. Maybe you could add something on the question of what to name the
internal variable that keeps track of a property's value, in order to
distinguish it from the property itself. I personally tend to use the
property name prefixed by an underscore.
Stewart.
More information about the Digitalmars-d
mailing list