A couple of days ago, I explained why trying to write beautiful code is a mistake, and suggested that people strive to write virtuous code instead. As the main benefit of ‘virtuous’ over ‘beautiful’ is the ability to define criteria for satisfying the former, I feel like I owe an account of what the virtues are for coding.
As I mentioned in my original post on this topic, I’m not at all certain that this is an exhaustive list of the virtues that code can exhibit. Instead, think of this as a conversation starter, and feel free to add your own suggestions in comments or on your own blogs.
So, with all that out of the way, on to the virtues!
The first and most obvious virtue for code is Correctness. We write code to solve problems; if our code fails at this task, then it useless as anything other than performance art (see: virtually any live demo at a conference). Happily, it’s usually pretty easy to tell when your code is correct - if your code solves the problem you meant it to, then it is correct (we’ll get into the finer points of this later when discussing some of the other virtues, for anyone who cringed at that).
Correctness is the most fundamental of the virtues; code might lack one or another of the other virtues and still be virtuous to a greater or lesser extent, but if it is incorrect then it’s just no good.