Joel Spolsky, as always, is entertaining and takes a bit of exposition to get to the point in his latest article: Making Wrong Code Look Wrong. In the article, he makes a differentiation between “Apps Hungarian” notation and “Systems Hungarian” notation, and now it makes sense to me. Whenever I saw people talking about Hungarian Notation, I always saw the Systems version which seemed completely nonsensical: why would someone have a variable name that just duplicates information that you’ve already got? Conveying more useful information, as in the unsafe string example Joel gives, is a good thing.
I don’t buy the exceptions argument that Joel makes. When you’re writing the code, if you’re calling some outside function you need to know whether that function throws exceptions or if it returns an error code. Either way, when you’re calling something that can fail, you need to decide how you’re going to handle that failure. If you use error codes, you’re forced to do bookkeeping all the way up the chain until the error hits a point where it can be properly dealt with (sometimes requiring action from the user). With exceptions, you can just say “this method is not in a position to do something about this problem, pass it along”.
CompSci is all about tradeoffs: Joel’s preference is for more explicit code that requires more bookkeeping. My preference is for something that requires a bit less bookkeeping, and saves a bit of time by leaning on the tools a bit more. People writing macros in LISP are all the way at the extreme of hiding much of the bookkeepnig behind the tools provided by the language.
There’s no proveably correct answer to this, so pick your poision as they say.
Regardless of how you feel about exceptions, though, Joel’s article is worth the read because of his Hungarian Notation explanation. If you’ve been turned off by Hungarian Notation in the past, it’s worth taking a look at Joel’s view on it.