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?
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 building progress 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.
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.
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.
X
lines. Then, over several iterations, reducing the final product by Y
lines. So, the (X-Y)
remaining lines seem to be very costly because the carnage of refactoring has cut away all the cruft.
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.
Thilo's answer is probably most accurate historically, but the "negative code" metaphor can also include performance and memory use - rewarding efforts to defer execution or allocation of something until it is actually needed.
This "procrastination pays" mentality produced such tongue-in-cheek axioms such as "Doing nothing is always faster than doing something", "The fastest code is the code that never executes", and "If you can put it off long enough, you might not ever have to do it" (referring to deferral of expensive operations until actually required)
One technique to realizing negative code is to challenge initial assumptions and definitions of the problem. If you can redefine the problem / input domain such that "sticky issue #3" is categorically impossible, then you don't have to spend time or code dealing with sticky issue #3. You've eliminated code by optimizing the design.