I had a professor in college tell me that strong, dynamically typed languages give developers just enough rope to hang themselves — and that, in particular, warned me against changing return types. At the time, I didn’t really believe her.
Today, I broke the live MobileWorks site because I changed the return type of a function. It was returning a Decimal (Python’s class for slow, clean floating-point numbers); as part of a series of other changes, I changed it to a float. In Python 2.6, floats and Decimals cannot directly interact, so I checked everywhere else in the code the function was used to ensure compatibility with the new return type. I ran a few tests, and everything was working well.
So I checked the code in, got it peer-reviewed, played around with it on staging for a while, and we deployed live at about 7 PM. Lean, agile startup-style. Oorah. I left the office at 10.
About an hour and a half later, I got a text from the company’s CEO. “The build is broken. Can you revert the live site?” Shit. Sure. I checked my work mail account to find a dozen crashmails. What went wrong?
Turns out, in a use case not covered by our unit tests, the output of the function I changed is played with a bit before being passed back into the same function. Where I expected it to be a Decimal. Causing a run-time type error. Woops.
The point of this post is that I want to remember this mistake. I got cocky and fucked up. This time, it didn’t cause much damage. But next time, who know? Writing things down helps you to remember things. I want to remember this.