Subject: Hungarian Notation

From: Chen Shapira <[email-masked]>
Date: Sun, 22 Oct 2000 18:43:27 +0200

Hi,

While nameing conventions are always a good reason for a hearty argument
between two programmers who share code, one of the most popular convention
(at least in the Microsoft ruled part of the world) is the Hungarian
Notation.

Invented in the early days of Microsoft, the Hungarian Notation suggests
that a variable name should contain indications about its type, casts, uses,
etc. 

A good way to use the notation is something like sErr which can demonstrate
that this variable is an error string, as opposed to error object or error
code, or that time when the only way I could know what to send that vb
function was because the parameter was called oDate - signifing a date
object, I habitually pass the date as a long - number of seconds since Unix.
Ofcourse this is just an excuse for poor documentation, but you can view the
notation as a documentation, which can be reliable or unreliable as any
documentation

Ofcourse it is easy to abuse the system, the original microsoft document
insist on fTrue and fFalse to denote that these are flags, and szChar to
denote that char is a pointer to the first character in a null terminated
string. Not to mention that if a variable was casted couple of times it may
get to ilchserrdNow, which explains the name Hungarian Notation, this is
certainly not english! and the standard windows library is choke full of
such monsters (vbAsyncReadGetFromCacheIfNetFail is my favorite, good thing
Vb has auto completion).

Almost every programmer I know agrees that marking variable type and usage
can be useful at some cases, most of them use it in one form or another (my
team adds the type at the end of the variable, so sorting a list of variable
names will give us alphabetic sort and not sort by type), it is even more
usefull in scripting language where following types is even more difficult
than the usual.

Why am I writing all this? because I found the original document where
microsoft invented or atleast formalized this notorious notation:
http://msdn.microsoft.com/library/techart/hunganotat.htm

Enjoy!

--
Chen Shapira

---

From: Shlomi Fish <[email-masked]>
Date: Sun, 22 Oct 2000 19:49:14 +0200 (IST)

Well, it seems that the Egroups ads are back in the bottom of the letter.
Did Egroups changed their policy back to this behaviour, or did somebody
of hackers-IL paid them to do this?

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked] 
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

The prefix "God Said" has the extraordinary logical property of 
converting any statement that follows it into a true one.

---

From: "Nadav Har'El" <[email-masked]>
Date: Mon, 23 Oct 2000 00:05:07 +0200

On Sun, Oct 22, 2000, Chen Shapira wrote about "[hackers-il] Hungarian Notation":
>...
>...

Personally, I prefer reverse Polish Notation :)
(sorry, couldn't resist the pun! [1])

And about a party - I'm not studying this year (I've decided not to start
a PhD this year), but it doesn't mean I won't come if you hold a party :)

Nadav.

[1] If somebody didn't understand the joke, or what is "reverse polish
    notation" - well, "reverse polish notation" is used to talk about
    languages that write expressions as "arg1 ... argN op", i.e., the
    operator follows the argument. For example, "dc" is a reverse-polish
    notation calculator. To add 1, 2, and 3, you'd right "1 2 + 3 +" in
    dc, instead of "1 + 2 + 3" in the standard (infix) notation. Postscript
    is another example of a reverse-polish notation language.
    For more useless details about why this notation is "Polish", why
    it is "reverse", or why on earth people use it, see for example
    http://fandango.ch.cam.ac.uk/doc/rrf/rpn.html
    http://www.biochem.ucl.ac.uk/~martin/abs/rpn-intro.html
    (I just found those by searching "reverse polish notation" in av.com)

-- 
Nadav Har'El                        |      Sunday, Oct 22 2000, 24 Tishri 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |"God is dead." - Nietzsche; "Nietzsche
http://nadav.harel.org.il           |is dead" - God

---

From: Oleg Goldshmidt <[email-masked]>
Date: 19 Oct 2000 19:00:06 +0300

Chen Shapira <[email-masked]> writes:

> A good way to use the [Hungarian - OG] notation 

I tend to think that Hungarian notation is a very bad practice (and I
insist that the fact that it was invented at M$ is irrelevant).
Basically, it assumes that no non-trivial useful piece of code (and
there is no reason to use it in a trivial or a useless one) will have
variables whose type will ever change during development and
maintenance. No ints will become long, nothing declared as "long
current_time" will ever become a structure of some sort, etc, etc. I
have yet to see a piece of code that satisfies this assumption.

Strictly speaking, if a variable type changes, you can use one of
those wonderful regexp-based UNIX tools like awk or sed to modify
the variable name everywhere and keep things consistent. It seems to
me though that here the M$ origin suddenly becomes relevant. ;-)

Besides, I don't see any need to carefully craft garbage-looking
names to keep type consistency. A good compiler and/or linter will
flush problems for you. Oh, I forgot: this means using proper
development tools...

On an off-topic wavelength, I claim prior art on Nadav's Hungarian /
Reverse Polish pun:

http://plasma-gate.weizmann.ac.il/Linux/maillists/00/08/msg00462.html

Great minds think alike, don't they, Nadav? ;-)

Other controversies mentioned in that posting are obvious, save for
the Lisp/Forth one that I owe to a profound comment made by Moshe
Zadka (for the record, I am not aware of any Lisp/Forth religious
war).

-- 
Oleg Goldshmidt <[email-masked]> 
"... We work by wit, and not by witchcraft;
 And wit depends on dilatory time." [Shakespeare]

---

From: "Nadav Har'El" <[email-masked]>
Date: Tue, 24 Oct 2000 22:32:40 +0200

> Great minds think alike, don't they, Nadav? ;-)

;)

Sorry for the plagerism :)

> Zadka (for the record, I am not aware of any Lisp/Forth religious

Then what are we waiting for? Let's start one!

-- 
Nadav Har'El                        |     Tuesday, Oct 24 2000, 26 Tishri 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Why do doctors call what they do
http://nadav.harel.org.il           |practice? Think about it.

---

From: Moshe Zadka <[email-masked]>
Date: Wed, 25 Oct 2000 10:09:09 +0200 (IST)

> Zadka (for the record, I am not aware of any Lisp/Forth religious

For the record, I didn't invent that profound comment (so I can safely say
it is profound <wink>). Lisp/Forth religious wars are in fact rare --
the two communities have respect for each other, and they are far enough
apart not to be competing for similar resources. This is different from
Lisp/Scheme (competing for the AI and similar niches) or Python/Perl
(competing for the RAD niche).

In that vain, it's interesting to notice that there are no Perl/VB wars,
because Perl is not really competing for the VB niche, even though it has
the technical ability to do so (Perl/Tk) while Python/Tkinter, with a
simialr technical profile, but a different social one, does battle against
VB.

--
Moshe Zadka <[email-masked]>
There is no IGLU cabal.
http://advogato.org/person/moshez