CodeAndMoreCode

codeandmorecode01.png

The more sourcecode you have, the higher the complicatedness of the code will be - it is hard to find a new place to add code cleanly, so new code will be more complicated. As there is more complicated code, it will be even harder to find a clean place to add code, so copy-pasting and writing more new code besides or around existing complicated code becomes more attractive. This can go on until the sourcecode is so large and complicated it is no longer viable to add new functionality.

How can we break this cycle? By making a choice to not let complicated code lead to more code for example. If we find complicated code, we may decide to refactor first, so we end up with less complicated code. With the green arrows we indicate that there is a choice here. The blue arrow indicates that more Refactoring will lower the complicatedness of the code.

codeandmorecode02.png

So now we have two loops, a self-reinforcing loop (in this case, a vicious cycle) of code leading to complicated code leading to more code and another reinforcing loop to balance the first one out, consisting of Refactoring leading to less complicated code (wich in turn can lead to more Refactoring, since less complicated code is easier to refactor).

Refactoring not only makes code simpler, it often also removes duplication (e.g. by extracting functions for duplicated code, or adding a superclass to share similar behaviour over a number of objects). So now we can add another blue arrow to indicate that Refactoring lowers the amount of code.

codeandmorecode03.png