#Unconventional Notation
9 messages in this thread
Some time last year I ran accross an unusual naming convention for variables
in C. Each name included an identifier for the type of variable. This seems
like it would be useful for a project I am doing, where there is a
significant chance of accidentally mixing up types during assignments.
Unfortunately, I can't remember what the convention is called, or exactly
how it is used. I could come up with my own format, but would prefer not to
re-invent the wheel.
Does anyone know what I'm talking about? Thanks. [bk]
The style is called "Hungarian", after its most active proponent, Charles
Simonyi of Microsoft (much like Lukasiewicz's mathematical notation style
is called "Polish") It is probably documented best in Microsoft's internal
publications, but the OS/2 developer's stuff has a lot of it as well.
Lee… That's it! And your right about relating to MS, since I ran across it
while looking at some Windows code. Now, if I could just remember how it
goes…… [bk]
Ben,
Digital Equipment Corporation uses such a convention in their assembly
language coding. <facility-name>_L_<variable> name would designate a
longword (4 bytes) which was used by <facility-name> so that
UCB$_L_MEDIA_TYPE would be a longword in the unit control block which
designated the media type. DECies, please note that I made up this
variable name and don't go looking for it. Other types would be B-byte,
W-word, Q-quadword (8 bytes), V-variable length bit field, etc.
That's not exactly what I had in mind :}. However, Lee Crocker's message did
figure out what I thought I was talking about. Thanks anyway though. [bk]
Ben,
I think Ray Duncan (maybe it was someone else???) discussed the Hungarian
notation in PC Magazine about a year ago…
Warren
I don't understand the need. Doesn't your compiler complain when you try to
assign something to one type to something of another type? With some
compiliers (or the assemblers associated with them) then number of
SIGNIFICANT characters in a name can be limited. If you have to add
characters to a name that don't add to the description of the variables
purpose make sure that they are a suffix not a prefix. – RF
C compilers are notoriously permissive about allowing cross-type
assignments, and indeed its often useful to do, if you are careful. With
pointers though, its often easy to get lost in a large program. Length of
variable names is not a big problem, and the added notation is usually a
suffix. [bk]
Of course, this is a religious question, not a technical one. There was a
thread about this somewhere a month or two ago that came to no conclusion.
But, to put my two cents worth in… If the compiler will check types, let
it do so whether you encode the type in the variable name or not. If the
compiler will not check types, change compilers or find a good lint.