Fog Creek Software
Discussion Board




Never write a program longer than 137 lines

Recent JOS discussions about blog aggregators has led to me to signup then read BlogLines daily.  I've found a number of nice gems as a result.  Here' a good one.

Where Bugs Come From
http://fishbowl.pastiche.org/2004/04/27/where_bugs_come_from

"Over the weekend, my father was rather embarrassedly relating a story from the late 80’s. At the time, there was a school of management that believed zero-defect software was possible, so long as we made the effort, and paid attention to detail.

The story was from a workshop for programmers. To cut a long story short, the workshop was a classic tale of slippery assimilation, trying to find that ridiculous cut-off point where a program went from being short enough to be bug-free, to long enough to be inevitably buggy. I vaguely remember the answer being 137 lines of code.

This, of course, is the promise of structured programming, of functions, of objects. If we can write 137 lines of code without a bug, then we can structure our programming style so that we’re always writing units of fewer than 137 lines. We can build those units into components, and voila! No more bugs."

The article goes on to dissect the assumptions behind this last paragraph isolating both the truths and fallacies.

Will
Monday, April 26, 2004

"If we can write 137 lines of code without a bug, then we can structure our programming style so that we’re always writing units of fewer than 137 lines. We can build those units into components, and voila! No more bugs"

Isn't it possible to get bugs in the interactions between the components?

Mr. Analogy
Monday, April 26, 2004

Well, no more than 137 interactions between components then. And then you build those clusters into larger components...

Oh nevermind.

www.MarkTAW.com
Monday, April 26, 2004

ROTFLOL.  haha.

vince
Monday, April 26, 2004

Well, you're leaving out the other main component of the zero-defect theory which was unit testing and bounds checking for EACH of the modules. Its failure was that it was just impractical to create a test harness for each function, plus always check that EVERY parameter was within expected bounds (even when there was only one other function that called it, and it was one screen up in the source code).

But it would have worked, I tell ya!!

Ron
Monday, April 26, 2004

I was pretty sure 12 lines was the limit.  Just the other day I was on a site and got an asp error in line 12... so if the programmer could have wrapped it up by line 11 it would have been bug free. 

Mike
Monday, April 26, 2004

Perhaps I gave the topic too stupid title.  But I recommend the article, it has some nice content, especially the cautions regarding blind reliance on unit testing.

I've gradually ben doing more and more unit testing for my own work.  I must confess that it has occurred to me that the simplest way to ensure my tests always pass is to hardcode the answers. :-)  On a more serious note,  there's a larger issue about the fact that the developer is doing his own testing.  There may be use cases that elicit bugs (especially with regard to component interactions) that the developer will never find if he sticks to a small set of discrete tests based on his own assumptions.

Will
Tuesday, April 27, 2004

The developer can do his own testing successfully ... if he's also doing his own tech support.

The customer is the ultimate tester.


(Not that you shoudl let bugs slip and expect the customer to find it. But, if you let one bug get to the customer, you'll REALLY be motivated to find the next one.)

The key is to have the programmer WANT to find bugs.

Omarosa
Tuesday, April 27, 2004

This sounds a lot like the factoring philsophy of Forth:  Write definitions that are at most seven words and test them each as you go.

Junkster
Tuesday, April 27, 2004

137?  oh my god -- you mean it's NOT "42"?

anon
Tuesday, April 27, 2004

actually it is 237

2*3*7 = 42

keeping everything consistent with previous discoveries.

Tapiwa
Tuesday, April 27, 2004

"2*3*7 = 42"

Eh, and here's me thinking it were 6*9...

has
Tuesday, April 27, 2004

"There is a theory which states that if ever anyone discovers exactly what the universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

"There is another that states that this has already happened."

has
Tuesday, April 27, 2004

For Überprogrammers it is of course 1337 lines.


Wednesday, April 28, 2004

And we don't even know if 137 is hex or ocatal.

RH
Wednesday, April 28, 2004

Of course we know! If it were octal, it would be 0137 .

Justin R. Bendich
Friday, April 30, 2004

*  Recent Topics

*  Fog Creek Home