Sunday, December 16, 2007

Hungarian Notation

I've never liked Hungarian Notation.

No, that's not true. I used my own form of Hungarian Notation in certain C programs (for a certain company). Looking back, I'm not too proud of the  programs. They were inexpertly written, and the strange naming conventions did nothing to improve readability.

I'm pretty sure that the programs have been retired.

I have been reading Numerical Methods and FORTRAN Programming, a work from 1964. It describes programming in FORTRAN and lists (obliquely) the rules for variable names and function names in FORTRAN-IV. They are:

 - Variable and function names are at most six characters
 - Variables of type REAL must begin with a letter in the set A..H, O..Z
 - Variables of type INTEGER must begin with a letter in the set I..N
 - Function names, if longer than three characters, must end in 'F'
 - Variable names cannot end in 'F'
 - Function names must begin with letters that follow the variables, for their return types

These are Hungarian Notation rules, or at least very close in thought. The name of the variable (or function) tells you the data type.

They are different from today's Hungarian Notation, which is a convention agreed to by programmers on a team (or for Visual Basic, a whole industry). These rules are baked into the language! In FORTRAN-IV (and I specify the 'IV' part), you don't declare variables, you simply use them, and the name tells the compiler the type.

FORTRAN 77 came out with a number of improvements, the biggest being the logical IF statement and the dropping of mandatory Hungarian Notation. (Oh, you could still use it, but you could override the "I-through-N are integers" rule. And the 'functions must end in F' nonsense disappeared.)

FORTRAN 77 came out thirty years ago. It had the sense to drop Hungarian Notation. When will the rest of us?