I was reading the Wikipedia article on Douglas McIlroy and found a quote that mentions

"The real hero of programming is the one who writes negative code."

What does that mean?


It means reducing lines of code, by removing redundancies or using more concise constructs.

See for example this famous anecdote from the original Apple Lisa developer team:

When the Lisa team was pushing to finalize their software in 1982, project managers started requiring programmers to submit weekly forms reporting on the number of lines of code they had written. Bill Atkinson thought that was silly. For the week in which he had rewritten QuickDraw?s region calculation routines to be six times faster and 2000 lines shorter, he put "-2000" on the form. After a few more weeks the managers stopped asking him to fill out the form, and he gladly complied.


There's a Bill Gates quote along the lines of measuring programmer productivity by lines of code is like measuring aircraft by weight.

I'd like to add that the LOC metric has encouraged the use of overly long-winded languages and deliberate reinventing the wheel to meet quota.


To quote another great computer scientist, Edsger W. Dijkstra:

My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger.

From EWD 1036 (On the cruelty of really teaching computing science).


One of my most productive days was throwing away 1000 lines of code.
- Ken Thompson


It's tongue-in-cheek. If it costs you $N per average coded line, then coding "negative lines" is surely a winner.

This means, as practical advice, that small code that accomplishes the job, is much better than big code that do the same thing, all other things being equal.


Writing the same program in less code is a goal for everyone.

If a program took 200 LOC to code, and I write it in 150, I wrote -50 LOC. So I wrote negative code.


When I was in high school -- and yes, we had computers back in the 70s, though we had to make them out of animal skins using stone knives -- one of the math teachers ran a programming contest. The rules were that the winning program would be the one that produced the correct output, and that had the smallest product of lines of code times run time. That is, if your program took, say 100 lines of code and ran for 5 seconds, your score was 500. If someone else wrote 90 lines of code and ran for 6 seconds, his score was 540. Low score wins, like golf.

It struck me as a brilliant scoring system, rewarding both conciseness and performance.

But the entry that technically met the winning criteria was disqualified. The problem was to print a list of all prime numbers less than 100. The disqualified entry went something like this (most of the students were using BASIC back then):

100 print "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,"
110 print "67, 71, 73, 79, 83, 87, 89, 91, 97"

The student who wrote that entry pointed out that not only was it short and very efficient, but the algorithm should be obvious to anyone with even a minimal knowledge of programming, making the program highly maintainable.


I came upon this question very late and it already has excellent answers, anyway I thought I´d chip in.

Gabriel García Márquez once wrote:

"I'm writing you a long letter because I´m in a hurry"

(It sounds much better in Spanish)

Efficiency is one of the hardest things to achieve, Frederick Taylor suggested the least possible moves, and though he was talking about industry, it holds true for various matters of life including the logic behind programming.

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take. - Le Petit Prince


I once worked for a company that announced they were going to start rating programmers by lines of code produced per week. My response was, ALL right! I can score very high by this measure!

For example, instead of being lazy and writing


I will write:


Loops? Silly idea! If a task needs to be done 20 times in a row, write the code 20 times in a row.

Subroutines? Nah. Just rewrite the code each place you need it.


Sadly, management dropped the idea.


Programming is something like if you love it its like your girl friend, else its going to be your wife.