A women's way to clean code
A few weeks ago the news in Germany was that the average lifespan of German citizens has reached its highest level ever (Statistisches Bundesamt Deutschland). This was good news but I was also surprised to hear that women still live longer than men. I can imagine a lot of contributing factors but maybe that’s a long discussion better done over beers. One thing that I’ve observed, that I think I can say without getting into trouble, is that some women I know, are simply smarter about their health. For example, if they develop symptoms, they’ll go more quickly to the doctor than I would (or other guys I know). Longevity led me to think about the lifetime of code, and how short that can be sometimes. And, how we often ignore symptoms of illness in code too. This would be in the form of warnings during compile time, like in the following example, “death by internal API change”.
With the right compiler settings, a modern IDE like Eclipse displays warnings when something isn’t right e.g. when using internal API. By ignoring these warnings you are vulnerable to the ‘death by internal API change’ malady. One day the owner of the API will change its internal structure. If you’re lucky you can adopt the new structure and your code will survive. But if you’re out of luck, the changes to the internal API are so drastic that you can’t repair your code and your application, built on top of internal API, is completely broken.
This death can be avoided by reacting to the symptoms. Let me explain this with the same example. Every programmer has found himself in the situation were a public API couldn’t do everything you needed. If you’re writing code in a women’s way, you won’t ignore the symptoms. A female would consult a doctor, in this case the creator of the API or the community around it. They would describe the symptoms, and with this kind of information the “doctor” can react by extending the public API of the framework. In this way, all symptoms (warnings) are recognized early and eliminated before the malady can take hold. It’s the same here as with people: if you consult the doctor early, the probability of illness will shrink. So, be nice to your code…
Can you think of other examples where bad code is so easy to ‘catch’? It would be great to hear your examples of maladies like “death by internal API change” and hear your experiences.