The Hardcode to Success
Rodrigo was but a simple software development intern eager to prove himself. He would always volunteer for the menial tasks that nobody else wanted to do. "Nobody else" mainly consisted of Justin, Rodrigo's supervisor. Justin wasn't a big fan of doing stuff so he was glad to have an intern that was ready and willing.
Justin got a request from the network administrators to create a system status application to interface with their servers. They wanted to receive alert emails every hour on the hour if anything on the servers had a conniption. If everything was ok, maintain radio silence. To do this, a simple app would need to be created to pass system health check results to Pushbullet, which would take care of sending the alerts. Rodrigo didn't even wait for Justin to finish. "I'll do it!"
Rodrigo was excited to get his development environment set up with an instance of Pushbullet so he could start slinging emails. He spent the week coding and extensively testing his app and by Friday, his phone buzzed with an alert. Something about having his code send something out to his phone seemed super cool and futuristic.
Rodrigo wasn't exactly sure how to simulate a system failure so his phone only got emails saying everything was hunky-dory. All he had left to do was to add a condition to not actually send the hunky-dory alerts since the network admins didn't want their phones going off every hour.
Ready to proudly show off his handiwork, Rodrigo called Justin over for a demo. The demo consisted of Justin half paying attention, half texting on his phone, and saying "Yeah, ok" every couple minutes. When Rodrigo was done, Justin nonchalantly said, "Go ahead and throw it out on the production server whenever". Rodrigo wasn't expecting that but he was glad to finally have an app of his go to production.
He threw the code out on the production server, fired it up, sent an email letting the admins know to expect an alert in case of trouble, then checked out for the weekend. He bragged to his friends over several beers about how his code was working all weekend while he got to have fun.
Rodrigo strolled in Monday morning to find a red-faced Justin standing at his desk, arms crossed. "Rodrigo! We had a major system failure over the weekend!"
Confused, Rodrigo played an optimistic card, "So when that happened, my app notified everyone... right?"
"No, it didn't!" Justin shouted, banging his hands down on the desk. "Your app didn't do jack squat to alert anyone, now we've lost nearly 30 hours of production data! Have a seat and think about how we're going to fix this while I review your code."
Justin opened Rodrigo's source code at his computer and began scrolling through it. It didn't take long for him to find the offending line -
"Access-Token: " + accessToken + "\r\n" +"Content-length: 99\r\n""Content-Type: application/json\r\n" +"Connection: close\r\n\r\n" +Justin called Rodrigo over to shove his nose in the code mess he made. "Why on earth did you hardcode the length??"
Rodrigo meekly replied, "I didn't want to create a function to count the bytes so I made a Python script to count the amount of characters in the response. I figured since it always returned 99 characters, I could hardcode it to that. Is that bad?"
Justin angrily explained how when the response was anything but a clean health check, it would return an error message. An error message would most definitely be more than 99 characters, but it would get truncated to 99, where the success message condition he added would think everything was great. Thus, no alert would be passed to Pushbullet.
In the aftermath, Rodrigo was relieved of his internship while Justin was left to explain why he allowed an inexperienced intern to push code that hadn't been reviewed to production. In the end, it was hard to say who learned more from the internship experience.
[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!