A bit of inspiration most weekdays for exploring your mindset .

Deleting code

Khem Raj November 01, 2024 #meta

A regular output of productivity in software is lines of code. We talk about how many lines of code someone writes on average per day.

But a converse question I ask.

How many lines of code did you remove today ?

A lot of software, Open Source or otherwise, we come to touch today has a large body of code already. Typically, more code is added to implement a new feature or property. While doing so, we come across

Dead code - It once was used but not any longer

Unused code - It was added in anticipation at one point of time

Duplicate code - It was not known there was an implementation available

Commented-out code - This is kept for reference, but it adds to distraction more than help

Sub-optimal code - First pass, left over from POC made into product

All of this code is candidate for adding negative number of lines to codebase. However, we do not plan this along with the feature that will require to travel through these code paths. As a result we keep on adding and over time complexity gets us.

Code cleanliness should be part of culture, if developer sees an opportunity to remove code, there should be an easy process for this to become a sub-task in current task at hand. It should be celebrated.

Removing "unneeded" code can help reduce bugs-per-line-of-code, improve compilation speeds, ensure that a program is easy to read, maintain, and understand, especially for other developers who may work on it later