It will work till infinity

It was friday evening. I was on the train back from work. My phone rang – colleague.

“Dude, is your migration script supposed to run?”

“Er, yes…”

“What were you trying to.. mumble mumble.. cryptic.. mumble.. infinite loop.. mumble.. never going to stop running”

“Erm, okay…”

“I’m putting this on

In programming, loops are used to make a computer perform a tasks over and over again. Usually it is something straightforward like:

“Perform this series of instructions 5 times”

Sometimes it has slightly more dynamic conditionals such as:

“As long as there are words in the list, pop a word off and email it to John”

In the second example, if someone or something else is constantly adding words onto the list, or if for some erroneous reason the program puts the word back into the list after emailling it to John, the program will never stop running. That’s an infinite loop.

Infinite loops have their uses, but it’s more commonly the case where an infinite loop shows up as a result of a mediocre programmer’s incompetance, or a competant programmer’s attempting to code while fatigued, intoxicated or stoned.

I was in neither category at the time of coding – perhaps I was seeped a concoction of hurry and a mild lack of sleep. I even tested it on my machine and it ran just  fine.

Still on the train, I pulled up the code from our code repository and started going through each line – just to make sure – before I responded. I wasn’t offended that he’d called me out on my work. If you’ve done bad, you’ve done bad – everyone has a good laugh at how ridiculous it is, and we move on – lesson learned. I was more concerned that something like that had slipped through.

The code looked fine. The only thing that looked remotely alarming was the fact that I was terminating the script early – a typical diagnostic step that I had forgotten to remove before checking the code in. So, thinking that I’d picked the issue, I texted back:

“shit, it looks stupid. but does it work?”

“it will work till infinity”

“but the doodads will run out and the loop will terminate, no?”

“no because the count does not run out”

“nah there is more wtf there. show you monday. have a good weekend”

Good weekend my bleep.

Late that evening, I pulled up the code on my phone to check it before going to bed.

Saturday morning, I checked.

Sunday, I couldn’t help pulling up the code once more just to see if I could figure out how an infinite loop could possibly materialize.

Monday, I rocked up at the office, fully prepared for a public ridicule.

Nothing. It wasn’t there.

The code was cryptic, I give them that, but there was no infinite loop. They were wading deep through stinking warm shit trying to get a live data migration going so fatigue ensued. The fact that my script terminated early without doing anything coupled with my less than palatable coding style set off a cascade of misjudgements that prevented them from actually running the script.

Not their fault. Migrating live data is a high-risk, time consuming and it saps every ounce of attention out of you for an extended period of time. The last thing you’d want to do is to risk running a cryptic infinite-loop-esque function that may cause the system to blow up.

So there. No for me this time, but all fun and games all around.