G
Guest
I just saw an interesting identifier in a C# book I'm reading...
double dollarsPerHead
This jumped out at me, as it is not common to put units in an identifer. We
don't see "millisecondsSinceStart" ("time"), or "milesPerHour" ("speed").
But, perhaps it's a good idea. If memory serves me right, one of the Mars
landers crashed because two development teams used different units (metric
and imperial), across an interface. Also, when I'm coding, I'm frequenctly
checking units against specs, when it would be easier just to read the
identifier.
I think that a project should be consistent -either always include the
units, or never include them.
My opinion - if the unit is included, then programmers will trust the
identifier, rather than specs, and if the unit ever changes, but the
identifier doesn't, then the identifier is misleading. Therefore, units
should never be included in identifiers. My general approach to "conventions"
is to avoid conventions which can't be enforced automatically.
So I would replace "dollarsPerHead" with "ticketPrice"
Opinions?
Javaman.
oh, the book is "Design Patterns in C#", by Steve Metsker. I highly
recommend it.
double dollarsPerHead
This jumped out at me, as it is not common to put units in an identifer. We
don't see "millisecondsSinceStart" ("time"), or "milesPerHour" ("speed").
But, perhaps it's a good idea. If memory serves me right, one of the Mars
landers crashed because two development teams used different units (metric
and imperial), across an interface. Also, when I'm coding, I'm frequenctly
checking units against specs, when it would be easier just to read the
identifier.
I think that a project should be consistent -either always include the
units, or never include them.
My opinion - if the unit is included, then programmers will trust the
identifier, rather than specs, and if the unit ever changes, but the
identifier doesn't, then the identifier is misleading. Therefore, units
should never be included in identifiers. My general approach to "conventions"
is to avoid conventions which can't be enforced automatically.
So I would replace "dollarsPerHead" with "ticketPrice"
Opinions?
Javaman.
oh, the book is "Design Patterns in C#", by Steve Metsker. I highly
recommend it.