Why does code go bad?

In short, the code goes bad because we are afraid to change it. Why would the code not changing cause it to be bad? You would hope that, when the code was written, it was the best code that the developer was capable of producing at the time. So, that code should have been good, right? This is a complicated answer but assume, for the moment, that the code was something to be proud of when it was originally written. That still begs the question, how did it go bad?

The answer is staring you in the face. The only reason you are seeing this code is because it needs to change. Chances are, you are not the first person that has needed to make a change in this code. So, this is not the code that was written by a developer doing his or her best to write good code. This code was written by many developers. Still, each of those developers should have been doing their best to write good code. So, again, how did this code go bad?

This is where the fear comes in because we are afraid to change the code. When we have to change it, we generally try to change the code as little as possible to get the requested update working. After all, we don't want to force ourselves or QA to do a full regression test because we refactored the whole thing, do we? So, we modify the code; we change the way it is expected to work. But we can't change the structure, and we can't modify the decisions of the developer who originally wrote the code.

Over time, making these small changes and being afraid to modify the structure and architectural decisions of the original developer causes severe code rot. Soon, the code will have massive conditional statements and methods that no longer fit on the page. The class containing the code will grow to tens of methods and the file will be thousands of lines long.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.7.131