Monday, July 26, 2004

Where art thou, O Hungarian!

In the good ol' days, variables named 'i' , 'j' and 'k' were considered too descriptive. In fact, I happened to read that the language "Forth" was so named because of the constraint of the system. It was meant to be "Fourth" but because the name could be only 5 bytes, the author made do with "Forth." How logical!

Coming back to our variable names, I have heard umpteen discussions placing one style on a pedestal as compared to another, and only to tear down the same style a couple of years, nay, even a couple of months down the line. Does Hungarian ring a bell? It was the variable naming convention some years ago! All Windows programming books had a mandatory chapter on the Hungarian notation. It wasn't the least bit funny and logical to code in Hungarian! Given the feudalistic structure of certain development shops, which had one architect who would read DDJ or Programmer's Journal or msdn and proclaim that "Guys! I have the panacea for your variable naming woes!", it was not uncommon to have Hungarian thrust down unsuspecting coder's throats! To read code, one needed to know Hungarian, to write/publish/pass the peer review one needed Hungarian, heck, to claim you did Windows programming you needed to know Hungarian! Such was the clout it enjoyed! And, today? A line from the coding guidelines at msdn states "Do not use Hungarian notation."

In case you have been missing the fun, lets talk a walk around the net and see what's cooking about this topic.

It all started with this paper A monograph on Program Identifier Naming Conventions. (Its also alleged that this was a piece of humor put up by Simonyi to entertain his colleagues during his vacation.)

This became the bible of variable naming and anyone who wasn't a convert was a philistine!

Its my guess that with the arrival of Anders Hejlsberg (during his Java days at Microsoft) Hungarian Notation began to be relegated to the background. If you take a look at the .NET Design Guidelines, it is suggested to use either camel casing or Pascal casing (with Pascal being the preferred one, as can be evidenced by the samples at msdn. No prizes for guessing where the Pascal influence came from ) Slowly, over the past few years, its hold has been loosened and there are dwindling numbers of programmers who prefer Hungarian over Pascal.

You might also lose favors with some interviewers if you use Hungarian to code as this post claims Hahaha, tomorrow if another coding style say, Etruscan notation or armadillo casing becomes the new fad, you better watch out, after all you have a job to keep!

I prefer the off screen readability of the modified Hungarian. After all, we haven't evolved yet to have Intellisense in printouts! So, till that time, I plan to take a few brickbats in my stride and not compromise on *my* preference.

No comments:

Post a Comment