Desirable Complexity

As a developer, I face complex problems everyday (or should I say complex problems are upon me everyday? :-). I may come up with a rather lengthy serial blurb of code with a couple of conditions & loops. This blurb may neither be an object-oriented nor a clean, maintainable piece of code – yet. The code may look easy-to-understand and simple to me now because I’m still fully engaged in the problem and its solution. There are three key factors which contribute to its complexity:
* Length of methods / scoped code blocks
* Number of conditionals
* Number of loops
Reducing this undesirable complexity is straightfoward: Ruthlessly reducing duplication. During this process, I will most likely introduce new methods and new classes. This sure makes the system itself more complex, too. However this is desirable complexity – complexity which can be easily dealt with in future revisions of the code. Because I reduced duplication and decoupled the different components of my solution.
Or, to rephrase it, reducing unmaintainable complexity with managable & maintainable complexity.
So for any reasonably powerful feature or piece of functionality added to a system, the code won’t be simple. It will add complexity to the system. But doing it right will ensure that the system can still be dealt with in the future.