- Easy to understand
in that order. If you write code that isn’t easy to understand, then you aren’t being clever and nor is your code. I suggested this idea on StackOverflow in response to the “What is the most clever code you’ve ever seen?” question. It generated a lot of negative feedback from some folk, though the positive score (at the time of writing at least 😉 ) suggests more folk agree with me than disagree.
The fact that “clever” code often is anything but was highlighted by a recent article on The Daily WTF. It gives an example of a classic piece of “clever” code that not only resulted in an incomprehensible mess, but also ran far slower than could be achieved with a simple, easy to understand solution. In this case, the developer used the obscure C feature of long jumps, rather than a simple for or while loop.
So next time you are tempted to write a “clever” programming solution to some problem, ask yourself whether you are really being clever, or whether you are being a Homer Simpson.