What happened to Hungarian notation?
Microcontroller programmer's point of view.
Hungarian notation had fallen out of use in the mainstream programming, compared to late 1990s and early 2000s. In my observation, today the default setting in the majority of the code writers' minds is Hungarian notation: off
. What had caused this? Are there areas where the Hungarian notation may still be useful?
Refactoring
Refactoring has emerged as an important force in software development. Hungarian notation pre-dates refactoring. It became widespread before refactoring was formalized. Some refactorings involve a change of variable types which would require change of the Hungarian variable names. Renamed variables would appear in version control like shotgun surgery. Change of variable names wouldn't be needed without Hungarian.
An initial version of the code may have status represented by a string
. Later it gets refactored to an enum
which provides condition for switch
statements. Later it gets refactored again, and condition is replaced with polymorphism.
Without Hungarian, the metamorphosis of the member variable (field) might be:
string m_status
→ StatusEnum m_status
→ Status m_status
With Hungarian notation:
string m_strStatus
→ StatusEnum m_iStatus
→ Status m_objStatus
The first case requires less change to the source code. In the second case, both the type and the name changes.
IDEs have evolved
Mainstream Integrated Development Environments (IDE) have been getting increasingly more powerful. Nowadays they provide on-the-fly reference information about variables. That reduces the need to encode meta-information (type, scope) into the name of the variable.
Object-oriented languages vs. non-OO languages
A program written in a modern OO language (such as Java, C#, C++) can have a large number of your own application-specific classes. Remembering (and sometimes inventing) a map of Hungarian prefixes can be tedious.
Embedded programming
Code for microcontrollers (especially, the relatively small 8-bit and 16-bit ones) is usually written in plain C. Most of the microcontroller IDEs are lagging behind the mainstream IDEs when it comes to Intellisense. Hungarian notation may still be useful for microcontroller code.
Related
What's up with hungarian notation? MSDN blog article by Eric Lippert (2003)
Making wrong code look wrong by Joel Spolsky (2005)