How I Lost $5000 With Bad Code

Erm…. maybe it was more. You see, around 2 years ago, when I first started writing code professionally (a term I’m using pretty loosely here), I was tasked with building an app that allowed store owners to request reimbursements for damaged and expired items. The app used SQL, C#, an archaic IDE called BPM and Javascript, the former 3 of which I had been introduced to while on the job.

The app was a complete mess. From lengthy SQL queries that slowed to a snails pace when the app grew to handle 10,000 rows, a particularly embarrassing 100 line long if else statement (not kidding) and a UI which looked like it might have belonged to the late 1990’s. Still, it was finished! And to me, at the time, working meant finished.

I should also mention our team was not using test driven development while making this app. We relied on a one-man (at the time) QA Engineer to test all our apps. With little oversight and no real way to test the many edge cases that the app presented, it was shipped and it kinda worked for a couple weeks.

Then, a woman from accounting came over. She was curious to know why we were rounding up every transaction. Was this a new policy? Oh shit. You see I had been dealing with decimal number types using Javascript. In order to get them to two decimal places, I was calling a combination of `round` and `toFixed()`.

It’s amazing, in retrospect, that no one caught this bug. We had the habit of using the same items for testing and in this case, those items worked perfectly. It took around 300 stores, using this app apparently around the clock to return meat, popsicles and Hawaiian shirts. Around 10,000 requests later, all that rounding had cost our company around 5k.

I was sure I’d be fired. Fuck, just a few months in to my first software job and I’d wrecked the company. I waited for the team to kick me out, their disapproving fingers wagging back and forth after I walked out the door with my items in a sad cardboard box.

That day never came, thank Bob. I fucked up. We came together as a team and fixed that app and I learned a $5000 lesson. Our company was making around 2Bil a year, so that amount didn’t exactly tip the scale. Still, it taught me a lot about getting the requirements for an app before you code, understanding the code you end up writing and most importantly, test that shit.

That wasn’t my first or last mistake involving writing bad code but I pray it’s my most expensive.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s