The ‘It just worked’ Scary Programming Scenario
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

One of the scariest situations when programming is when you write more than 100 lines of code in one go and it ‘just works’. This for me is far worse than it breaking horribly.
However a confident programmer you are there is something very unsettling about things ‘just working’ and it is much more likely that in fact some very nasty hidden bug is present than the slim chance that you got it all ‘perfect’ first time round. This phenomenon gets worse the more code you write without trying it out.
In most programming scenarios you will be performing some form of interim testing and the scary scenario only comes up every so often. Today I was writing a mail queue framework and at the same time adding a required preferences model. All of which had interdependencies which could not be resolved without the whole thing being completed. I ended up with about 800 lines of code (a very rough guess) none of which had been tried before.
First off I was in that kind of pre-’try it out’ bliss where I was happy with the overall look and feel of the code. Any attempt at this point to run it would only leave me with a) scary scenario b) bugs to fix. Option c) Go to the Bahamas was not on the cards so I was forced to run it. The result? A fatal error! “Hurrah” I cried out. I havent been so happy to see a fatal error in a long time.
So is this just me? What stories have you all got about long chunks of code that ‘just worked’. Best story gets put up as a separate post.
Comment by David on 8 August 2007:
In about 1989 I wrote 15 lines of C which compiled first time and ran without apparent error (I found a minor bug a few hours later) … never before or since.
Now though I use Haskell and in generally takes 10 mins to get it all to compile but it Just Works ™
Comment by garry on 8 August 2007:
one scarier scenario is when you’re investigating some code and realize that it cannot possibly work, and yet it does.
Comment by Armandas on 8 August 2007:
Funny thing. About 30 minutes ago, I asked a few of my colleagues if it is a good thing when “you write rather messy piece of code, without thinking about it too much, and it just works”. Now I know why I wasn’t sure about those pieces of code, and wanted to go over them again
Comment by Peter Harkins on 8 August 2007:
If some of those 800 lines of code were unit tests you could be less paranoid.
Comment by Noah Rankins on 9 August 2007:
Right now I’m working on a good-sized program, and one of the things I’m currently focused on is generating a “diff” of a complex data structure used internally. If anyone here has ever used Perl data structures, it’s similar to being able to create anything you want out of 2 by 4’s and nails. One of the most relieving things is that that part of the program took several iterations to “just work.” Since that single part of the program is so complex (and inefficent), if it did work the first time I just might go paranoid.
In that similar topic, I think it’s good to have bugs in programs, because it lets you rethink their design. When I spend the rest of the day thinking about the problem, a more elegant solution usually comes to me.
Comment by GNUnando on 9 August 2007:
I don´t have much experience, but I totally agree with it being a scary scenario. If it works on the first time, you must have forgot something, for sure.
If after a long chunck of code written, you covered every single possibility, and there are NO bugs, you are God or something…
My longest SQL function to date has about 100 lines. I think I re-wrote / modified it 50 times before I made it work.
After those long session of coding, a good coffee, and some testing/bug-solving time ahead…
Comment by Adam on 13 August 2007:
Lol I remember programming for one of my classes. We were making a GPS program that connects to a MySQL db and Google Maps (to display the coordinates). I was debugging a friends program when I found the following comment
/* The next 15 lines works but I have no idea how. DO NOT CHANGE!!! */
Well needless to say I stopped debugging right there and told my friend to figure out what the code does. Code that works is definitely scary
Comment by bryanl on 20 August 2007:
@garry
in some places that is common place.