I get rather alarmed at work when I’m told that someone’s idiocy is to be expected, as they’re: new, young, inexperienced, poorly trained, etc. I just expect better.
On the other hand, every so often I run across something truly brilliant, and feel humbled (Any book by Don Box). Today, I ran across “Duff’s Device.”
I’d heard of it before, but never bothered to actually look at the code. It’s an optimization for something I rarely have to deal with in real life.
Looking at the code today, I was at first confused by what the big deal was… then saw where the “do” was located, and was struck by the brilliance. Pick up the odd-numbers-out at the start, rather than at the end…
Only click the link if you don’t mind feeling impressed, and feel comfortable in your knowledge of what exactly a compiler does. Assembly language knowledge might help cushion the wtf factor.