Simberon Design Minute
 

Convoluted Code

As we approach Halloween, I thought I'd talk about some software design problems that I find truly scary. The first one is convoluted code. Convoluted code is normally the result of many different problems working together. Long methods, many temporary variables, nested control structures, complex conditions and multiple levels of detail mixed together are some factors that contribute to making code convoluted. Usually, the problem is that the developer is focussed on the how - how to make the code work - than the what - what do I want to do. By focussing on the what, you can break down the operation into smaller more understandable steps. When the convoluted code is restricted to a method, it's usually possible to tease it apart with a bit of hard work. When convoluted code starts to extend into many methods or many classes, it can become difficult if not impossible to eliminate. The best way to fix convoluted code is to avoid it in the first place. Whenever you see your code become convoluted, fix it then and there. The real messes are made of many small messes stacked on top of each other.

Download