The positives of negative code

In programming, it’s not always easy to monitor progress. This is because the art of programming isn’t about writing code, it’s about solving problems. A productive week in programming can often result in fewer lines of code, not more.

In these weeks, programmers have been writing negative code. Negative code is a process of coding that sees programmers reducing the number of lines of code written into a program. Initially, that may sound counterproductive. Negative code is essentially erasing the work you put into writing those lines of code (LOC) in the first place, right?

Well, not quite. In fact, there are some distinct positives of negative code.



Where the term came from

Negative code – or removing redundant code for cleaner results – has been around as a concept since the dawn of programming. However, it found its name thanks to a pert programmer called Bill Atkinson.

In 1982, while working on optimising Quickdraw, Bill Atkinson was asked to provide the number of LOC he’d written each week to his project managers. (A process that Bill found absurd.) In fact, Bill had actually spent his week deleting code – not creating it.

Having rewritten a section of code with a simpler algorithm, making it perform smoother and faster, Bill had improved the program and removed 2000 lines of code in the process. So, when it came to filling out the form declaring how many LOC he had written, Bill wrote ‘-2000’. And so, the idea of ‘negative code’ was born.



Quality, not quantity

The process of programming fluctuates from writing many LOC in a short space of time, to writing almost none. This is usually dependant on which stage a product is in, or what frame of mind the programmer is in. Much of development time is spent staring at a screen, thinking rather than doing.

Unfortunately, too many people fall foul of using the number of lines of code written as a metric to monitor productivity. This practice is extremely problematic for programmers. As Bill Gates said:


“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.”


Writing line after line of code doesn’t necessarily mean that you’re making progress. A screen filled with code isn’t always a productive days’ work, and you might well be able to achieve the same – or improved – functionality with less code. Negative code reduces quantity in the name of quality.



Essential complexity

Writing negative code is a way to work towards achieving essential complexity. That is, the absolute minimum complexity required to completely solve a problem. It’s all too easy to overcomplicate when coding. Code is often many times bigger, messier, and more confusing than it needs to be to perform the required function.


“Everything should be made as simple as possible, but not simpler”

— Albert Einstein


Negative code answers this problem by striving for simplicity. Because you’re reducing the LOC in your program, you’re forced to analyse your work with a critical eye and remove any redundant code. The result is clarity and efficiency.



Positives of simplicity

  1. Makes code easier to maintain

Code maintenance is essential. Keeping old code and merely building on top of it can make for a mess of spaghetti code that’s impossible to understand or fix. By keeping it simple with negative code, you make your software easier to understand and read. This, in turn, makes code easier to maintain and keeps your software running smoothly.


  1. Code becomes more efficient

Finding the simplest way to code a problem can also make your program more efficient. In cases where all the code must be repeatedly read by a machine for the program to run, for example, less code can help everything load faster. So, by ‘writing’ negative code, you could reduce power consumption and make for a smooth user experience.


  1. Reduces instances of bugs

Negative code can also lead to a reduction in the number of bugs and faults that occur in your software. Less code means less opportunity to write in errors, and more time to find any that do make it into the program.



Negative code simplicity

Negative code is far from negative. It’s a great practice for improving software quality, and can help you clean up your code.

However, that doesn’t mean that you should start stripping your code for the sake of it. There is a sweet spot between brevity and understandability for code. That is, it still needs to be understandable to be maintained.

So, when ‘writing’ negative code, remember to make it as simple as it can be, and no simpler than that.



Useful links

How do you deal with another developer’s bad code?

Legacy code dangers: code is inventory

A guide to conducting effective code reviews