Hungarian notation

You have probably heard that hungarian notation is awful and that it should be avoided. However, in most of the Windows APIs, the notation has been misused. The intention behind Simonyi's notation is akin to dimensional analysis. I recommend you to read this article as well as Simonyi's original paper.

While having a good intention behind it, the idea is actually just a fix for a defficient language, namely C and C++. If typedef were not a mere type alias, but a true new type, this convention would be (almost) unneccessary as the compiler could catch all errors. For example:

typedef int Temperature;
typedef int Volume;

int f(Temperature a, Volume b)
return a+b;

Although it is meaningless to add temperature and volume quantities, this is perfectly legal C and C++ code, because Temperature and Volume are mere aliases for int.

C++ templates have strict compile-time type-checking, but the syntax is unfortunately just horrendous.

1 comment:

Anonymous said...

If the code needs some mechanism by which a type of a variable is obvoious from its name, it is poor code indeed. Simony's idiocy was just an extension of our old FORTRAN rule for making i-n starting variable names integers.