-
Eddie IS.
Hungarian notation has always sat wrong with me. So has some of Joel on Software’s views in the past. I’m currently revisiting both opinions.
Firstly, Hungarian notation. For those of you not in the know, Hungarian notation is a coding convention that’s been around for a long time. It gets a lot of flak - and in my opinion, usually quite rightly.
You see, the idea in the Windows headers, was to encode the variable type into the variable itself, to great detail. For example, in windows, you’ll often see something like this:
- // Function passing in a variable that’s a long pointer to a zero-terminated string
- MyFunction(lpszBar);
This, in my opinion, is wrong. C++ is already a strongly typed language, so you’ll get a compiler error if you pass in an item of the wrong type, so of what benefit is it to store the variable type in the name?
I always assumed that this was the “only” type of Hungarian notation, and I spurned the idea on the whole because of it.
Reading a post on Joel on Software’s website with great skepticism, I actually ended up changing my mind.
Joel brought to my attention that there’s actually two ‘types’ of Hungarian notation. One of which is called “System Hungarian”, and “Application Hungarian”. The difference is that the former encodes the data type into the variable, whereas the latter encodes the domain-level usage into the variable.
I won’t describe the difference between the two, as I think both Joel’s article and WikiPedia’s do a fantastic job bringing both to light (Joel’s is a good read for the skeptic who wants a narrative to follow, WikiPedia’s is a good reference for those pressed for time). I will however talk about what brainstorm this set off in my head.
I now think that Application Hungarian is a good thing, but the difference I outlined above is huge:
Systems Hungarian is easier to define, because it’s domain agnostic. Application Hungarian is domain-specific.
Take for example Joel’s example of needing to Encode() strings before sending them to a webpage. That’s a domain-specific example. Building a game in C++ doesn’t have the same requirement, so using his ’s’ and ‘us’ prefix doesn’t make sense.
It might even change from application-to-application, depending on what happens. This means you can’t have a blanket statement like “Always prefix [insert-domain-specific-kind-of-type-here] with [prefix]” between projects, unless they have a similar domain, and set of constraints.
I’m trying to think of places where this matters in code. I already do a modified form of “Hungarian” (prefixes such as: ‘m_’ for member variables, ‘b’ for boolean values, ‘p’ for pointers and ‘k’ for constants), but this is project-agnostic (perhaps I’ll call it Eddie Systems Hungarian
). I have yet to see a need for integrating domain-specific/application-specific Hungarian in the games I program, but at least this gives me pause to think about usages for it. If anybody thinks of any, please let me know.
Popularity: 37% [?]
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment

