Re: How to name variables in a program?



> It's an interesting article, OP should have a look. As you say, Joel
> suggests that in its original form Hungarian noted the _kind_ of
> variable, not the variable _type_. An example from the excel source
> being xl, xw and cb prefixes, all ints, but one is the coordinate
> relative to the layout, the next relative to the window, and the last
> a count of bytes. Then if you name all your functions
> prefixFromWhatever, it becomes clear if you've made an error, e.g.
> xlThis = cbThat;
> is clearly incompatible.

I have already adopted this scheme slightly - and I believe MS has done so
too (actually, there were first ;) ). Especially where dimensions are
concerned, cx and cy are used - e.g. cxScreen and cyScreen. Same goes for
locations (x and y as prefixes), f indicates an integer used as a bool (and
ambiguously, in my case, also a collections of flags crammed into a single
integer) and sz is used instead of lpc to indicate a string instead of a
pointer to a character.

This also brings up the question what to do with arrays. Should it be:

char lpc[10];

or:

char ac[10];

or even:

char vc[10];

(where "v" stands for "vector", but that could clash with C++'s definition
of a "Vector")

And I am still unsure about the "u" for unsigned, though. The prefix "ui"
is a unsigned int and "ul" is an unsigned long. But one could argue that
just "u" would mean "unsigned int" also, just like the "unsigned" can be
used to identify an "unsigned int" in C as well... (although I always
specify the "int"). But I don't worry about it too much ;)

Well, guess I just tossed another 2 cents in the jar...

--
Martijn
http://www.sereneconcepts.nl


.


Quantcast