There is a story that I remember reading during my childhood. It was about a boy who had a cat. The cat would meow at the door when it wanted someone to open the door for it. The boy had an idea and cut a hole (a semi-circular one, shaped like a doorway) at the bottom of the door, so that the cat could go in and out as it pleased. His mother praised him for his brilliant thinking.
Then the cat had kittens, and the boy cut four small holes in the door beside the big one, so that each kitten would have its own doorway. This resulted in him getting told off by his mother, because “The kittens could just use the same hole as their mother!”
Now let me ask you, what if instead of getting four kittens, the boy got a new cat, bigger than the first one? Should he cut a new bigger hole for the new cat, or should he just make the existing hole bigger?
I can hear you saying, “Make the existing hole bigger, of course!” Yes, of course… but in our code we often see developers duplicating an existing piece of code just for their “new cat”.
Now that I am losing your attention, here are some extracts from online articles, together with their sources so that you can go and find out more. (I’m not gonna duplicate the existing articles and modify them to cater for your needs!)
“Writing lots of code does not mean that you’ve written lots of software. Indeed, some code can actually negatively affect the amount of software you have—it gets in the way, causes faults, and reduces the quality …”
- from Write Less Code!
“You can improve a system by adding new code. You can also improve a system by removing code.”
Dead code won’t kill you, but it will make your life harder than it needs to be.
- Unnecessary code [...] requires maintenance over time. It costs time and money.
- Extra code [...] makes it harder to learn the project, and requires extra understanding and navigating.
- from Improve Code by Removing It
Note: This article is drafted for our Tetra newsletter. I actually recalled this article about developers who delete code, which I had read before. While searching for the article (using keywords that I roughly recalled), I stumbled across the other two gems, that are more concise, and with more powerful words.