1. 13

  2. 1

    I really like this, especially the having others read part. Lately I’ve come across people arguing about readability by simply optimizing purely for scores in some static analysis tool claiming to analyze readability. It’s shocking to see how often this goes wrong.

    Optimizing for good scores way too often leads to intentionally or unintentionally sacrificing readability by other humans. A patter of that is “hiding spaghetti code” by having for example three functions that always have to be called one after another, sometimes wrapping these three functions in a separate function, all of them passing the whole context to the next function. Many static code analysis tools will tell you “great, you fixed both the amounts of lines and the complexity in your code”. This would be true if they were actually independent functions, but if you need to always call them in order (wrapped by a function or not) and share the whole context by passing it along you make code harder to read and maintain, rather than easier.

    So while in many situations they provide good guidelines, on has to keep in mind they are not always true, which brings the next problem. As soon as a person creates a sane exception, because in a particular case it makes things clearer to break some static code analysis rule this spreads and people will start adding exceptions to everything.

    I don’t know a real solution to that problem. Usually experience will show you think, but then we end up at the problem of how to measure experience. But that goes too far.