DEV Community

When Hungarian notation lies hidden in plain sight

scottshipp on January 01, 2018

Like all historical artifacts, Hungarian notation once made sense. Namely, it made sense in the absence of type checking. Start with what you think...
Collapse
 
codemouse92 profile image
Jason C. McDonald

We definitely need to bring back Apps Hungarian!

The mangled twin, Systems Hungarian (i.e. intCount or boolIsRaining), is the madness that most people object to. That's where you use the data type as the prefix, and it helps no one. Please, for the love of all things digital, don't use Systems Hungarian!

Incidentally, I do use an odd little version of Hungarian Notation in GUI design. Every time I create a widget, I use a prefix relating to the widget type. It's something of a hybrid between Apps and Systems Hungarian, but it helps me avoid confusing widgets when writing code. For example, chkSubscribe would be a "Subscribe To Emails" checkbox, whereas btnSubscribe would be a "Subscribe" button - which might both have uses in a single interface (albeit a rather weird one, but hey, it's a rough example). Honestly, that's the only place I even come close to Systems Hungarian.

Collapse
 
jamietwells profile image
jamietwells

Whenever I think about Hungarian Notation I'm always reminded of this post:

joelonsoftware.com/2005/05/11/maki...

It's an excellent explaination of what the initial concept of Hungarian Notation was supposed to be.

Basically I think about it as a way to describe some information that the compiler can't check. If you are in a language like F# for example where you can make aliases for simple types then there's virtually no need for it. Simply make an alias for a JSON string and you no longer need to say userJson, you can give it the type JSON and the compiler will make sure you don't use it somewhere that isn't expecting JSON. Back in C# you can't do that so userJson becomes more useful.