I like to read Joel on Software. I don’t know if he’s smart, but I know he’s smarter than me. Recently, I enjoyed reading Making Wrong Code Look Wrong. I’ve long disliked hungarian notation, or what I now know as Systems Hungarian. The reason that I dislike it is because it doesn’t serve any purpose to me, almost. I know that Fname is a file name and thus a string. sFname doesn’t help. I know that Idx is and counter in a loop and thus a long integer. lIdx doesn’t help.
All my code, both the code I publish here and the code I don’t, uses Systems Hungarian. Why? I don’t know, but I suspect it’s a combination of a lack of a better alternative and my conformist personality. It costs me virtually nothing to use sFname instead of just Fname, and if it helps just one person understand the code more easily, then it’s worth it. However, if there was a better way, I think I would latch on to it, so long as I could understand it.
I was writing a function for the Tenth Hole Tracker and I started with the key field of the Players table being a string, namely the players’ names. After some soul searching, I changed the key field to a meaningless autonumber (a long integer). While I was building my WHERE clauses, I used variables like
WHERE Player='” & sPlayer & “‘”
Now I had to change all the code to something like
It was quite helpful to have the ‘s’ in front to remind me to remove the single quotes. If the variable had been simply Player, then I wouldn’t have had that visual clue that I needed or didn’t need to enclose it in quotes. Had it been one function, it may not have been a big deal. By the time I had my epiphany, I had no less than seven functions that needed to be changed. (I shouldn’t be builing so many SQL statements, probably, but I’ll save that for another confession post.
There is, what I consider to be, a good example of why Systems Hungarian is a good system. Knowing that my variable had to match the data type in the database, it was useful to have the data type prefix. Joel gives a pretty good example of Apps Hungarian with his signed v. unsigned strings. I get the example, but I’ve never seen it in practice. Maybe my apps aren’t complicated enough to warrant a different notation system.
Okay, enough of my drunken ramblings. The whole reason for this post is to hear what you do. Are you a strict Hungarian Notator? Have you ever used a system that wasn’t data type based? Do you sometimes deviate and in what situations? Discuss.