Really cool post from Adam on programming anti-idioms.
Knowing a programming language's idioms is the key to being fluent in that language.
It is also important to know what not to do. Just because a language allows a certain coding style doesn't mean that style is a good one.
The anti-idiom he uses as an example is one where you can butcher C++'s exception handling to be able to "return" a value of any type. Read the post for specifics... however, I say that this type of thing is actually an anti-pattern, not an anti-idiom. In fact, I don't think you can even have "anti-idioms". An idiom doesn't really carry a value judgement along with it; an idiom is just a thing people commonly do. [Design] Patterns on the other hand, do carry a value judgement.
I like the way wiki says it, "an AntiPattern is a pattern that tells how to go from a problem to a bad solution", whereas a pattern tells us how to go from a problem to a good solution.
Seen on LtU.
Another reason this is an anti-pattern instead of an anti-idiom which I didn't mention before is that this is a large-scale design rather than a small scale bit of code that would be called an idiom.
Ehud brings up a good possible use for the term anti-idiom:
Perhaps the term anti-idiom should be reserved for incorrect code people repeatedly produce, esp. if related to well known idioms.
Maybe something like for(n=0;n<=count;n++){...} would be an anti-idiom? Or to use Adam's example, something like while(*++n = *++m);?
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):