Hungarian notation: the nomenclature for programmers that Microsoft created, that today rejects… and that is still used (badly)

0

Choosing a name for a variable when you are programming is easy. But choosing a good name? That may not be so much anymore: it must be descriptive (that is, capable of clearly representing the function of said variable), as well as understandable by other developers who may need to review the code at some point.


Therefore, to facilitate the task of naming variables, developers tend to abide by some convention, a more or less fixed criterion to decide how and in what order to put a variable’s ‘first and last names’ (and even when to case-sensitive). And among the multiple conventions available, a call stands out ‘Hungarian notation’.

The programmer career in 2017 and in the future (with Javier Santana)

This is what is usually understood as ‘Hungarian notation’

For example, in the case of ‘productCode’, ‘ProductCode’, ‘product_code’, ‘product.code’ and ‘nProductCode’it is the latter that we would consider to accept the aforementioned notation, since a lowercase prefix is ​​attached to the name in the strict sense, indicating the data type represented (in this case, ‘n’ for number).

In theory (we’ll come back to that later), the credit for its creation should go to Charles Simonyithe creator of Bravo (the first WYSIWYG word processor), of Multiplan (the direct predecessor of Microsoft Excel), of MS Word (in its version for MS-DOS) and, later, of Microsoft Office.

Actually, Simon. he had already described his idea long before he made a name for himself in the world of software development: in his 1976 doctoral thesis, “MetaProgramming: A Software Production Method”.

In any case, the importance of Simony in the development of Office caused this convention (named ‘Hungarian notation’ by his colleagues at Microsoft because Simony, well… he’s Hungarian—they didn’t squeeze the meninges much, no) became the standard for writing software developed by Microsoftas well as for all those developed in certain languages, such as Visual Basic (also from Microsoft).

And the favorite code editor of programmers is… 8 professionals give us their answer

fall from grace

And yet, in the official ‘General Naming Conventions’ of the .NET framework, now (and for 14 years now) the following phrase appears explicitly:

“❌ DO NOT use Hungarian notation.”

It appears just below “Do not use underscores, hyphens, or any non-alphanumeric characters,” and just above “Avoid using identifiers that conflict with programming language keywords.” There is not much room for interpretation: Microsoft now denies this nomenclature. Why?

It is usually considered that the reason that made Simony bet on this notation was that, at that time there were no IDEs with IntelliSense or similar technology, the fastest option to check what type of variable we had in hand was to take a look at the name prefix of it.

But now, as explained in the book The Programmer’s Brain: What every programmer needs to know about cognition,

“When most code editors can easily display the type of a variable, the Hungarian notation doesn’t look like an added value in a typed language, because it just makes the variable names longer“.

“Hence encoding types in a variable name in this way is no longer common practice, and today the use of Hungarian notation is generally frowned upon“.

Simonyi

Let’s see, Simonyi (the one on the left in the photo) doesn’t really care if we messed up with his notation: he’s the only space tourist to have gone up into space twice, he’s on to other things.

There was another Hungarian notation (and that was the good one)

However, the rise and fall of Hungarian notation can only be understood by realizing that, in reality, there are two variants of this notation… and that the one used by Simonyi does not even coincide with the most popular among programmers.

Simonyi really proposed to use what we know today as “Hungarian notation for applications” (or Apps Hungarian), in which the prefix specified the purpose of the variable. Here would be an example of the use of the “lbl” prefix in a label (‘label’) of the interface, or the use of “ix” to signal the index of an array…

…while the example that we put above, limited only to the data type of the variable, is what is known as “Hungarian notation for systems” (Systems Hungarian).

In ‘Systems Hungarian’, the only thing the prefix tells us is the actual data type of the variable

Joel Spolsky explains it perfectly on his website:

“Apps Hungarian was extremely valuable, especially in the days of C programming where the compiler didn’t provide a very useful type system. But then something bad happened: no one seems to know why or how, but it seems that the documentation writers at the Windows team inadvertently invented what became known as Systems Hungarian”.

The confusion lies in a misunderstanding of the language (but of the English language, not a programming language). And it is that Simonyi, there where I could have used ‘kind’ (type, class, category, species…), used the much more restrictive (in Anglo-Saxon computer science) ‘type’.

“Systems Hungarian was spread widely by books like Charles Petzold’s ‘Programming Windows’, the bible for learning Windows programming, and quickly became the dominant form of Hungarian notation, even within Microsoft, where very few programmers outside of the Word and Excel teams understood the mistake they had made“.

Image | Based on original content by Marc-Antoine Lortie

LEAVE A REPLY

Please enter your comment!
Please enter your name here