Dark Theme | Category:
“Guido van Rossum, why hast thou forsaken me?” I whisper, head in my hands. Of course the problem isn’t Python, the problem is my logic. It’s after 4pm on a Tuesday after I’ve spent literal weeks working on this program and now, the evening before we are set to demo to our biggest client, I have discovered a huge, glaring, soul-crushing flaw. I’d been testing with the real data we had from Dev and some test data that I’d faked and the math had worked out. Now that I’d decided at the 11th hour to test with a larger, more complicated fake data set that better approximated the actual data we would be getting in Prod I could clearly see that values that were supposed to be totaled were not totaling. Fortunately, I could also immediately see why. Unfortunately, I could not figure out how to fix it.
I type out a quick, breezy Slack message to my manager: “Found a bug, know the problem, working on a fix.” It’s 7pm his time, so I don’t expect him to see it. Even if he did and he asked if we need to push the demo (again – we already pushed it once because the API call didn’t return the data the way we expected), I wouldn’t know what to say. I know this program. I know I can fix this. I just don’t know how long it will take me.
I’m on a team with three brilliant people, but only one of them knows code, and not Python. We could maybe step through the logic together first thing in the morning, but I don’t want to count on that. So I grit my teeth and throw a bunch of print statements into the code, following every twist and curve of the data as it slides through the program. I have a list of dictionaries (an array of objects, for my non-Python coders) and I need to check if a particular key with a specific value exists in another list. I’d been using
in, but while I was asking “Does this key with this value appear in any dictionary in this list?”,
in was asking “Does this object, which consists of only this key and this value, exactly match any dictionary in this list?” The answer was always “no”, and so a new value was getting dropped into the new list each time and the values were never getting added together.
After three hours of throwing solutions against the wall with no success, I feel my brain starting to shut down. I think about what I tell students at LEARN Academy every time I give a talk to the current cohorts: when you reach a point at which you can no longer process information, it’s more productive to walk away and come back fresh than to keep banging your head against the same wall. I feel like a hypocrite, but I can’t walk away. There’s no time. Well, technically there’s 15 hours, but I’m not in college anymore; I can’t pull an all-nighter and be coherent the next day no matter how much coffee I drink. Then another part of my talk comes back to me.
In my early Tech Support days my team got stumped by a problem and ended the day without a solution. The next morning, my tech lead excitedly said to the third member of our team, “I thought about you in the shower last night!” What he meant, of course, was “I thought about that question you raised in our mobbing session yesterday while I was in the most sacred of holy places for a programmer, that refuge of rumination from whence the most brilliant epiphanies hail.” The phenomenon isn’t just restricted to tech, either. Astrophysicist Carl Sagan famously said, “I can remember one occasion, taking a shower with my wife while high, in which I had an idea on the origins and invalidities of racism in terms of Gaussian distribution curves. … One idea led to another, and at the end of about an hour of extremely hard work I had found I had written eleven short essays on a wide range of social, political, philosophical, and human biological topics.”
I glance in the direction of the bathroom. Could it really be so simple? Could I force a revelation simply by taking a shower? I look back at the screen, the pixels swimming in front of my tired eyes, and I decide I have to try. Under the scalding hot stream of water I sketch in the steam with my hands and mutter aloud: “I need a way to keep track of this key/value pair, and only this key/value pair, but without losing its association to the other key/value pairs in the dictionary.” I picture each piece of data as a physical object on an assembly line that is my for loop. I think of them as objects and arrays instead of dictionaries and lists, because at the end of the day every variable is just a box anyway – a box. That’s it. I just need another box, and another loop within that loop!
I spring from the shower and drop back in front of my laptop wrapped in only a towel. “This is it, kid, this is what you need,” I whisper to my program as I fill in the missing pieces. I tell myself that if it doesn’t work I won’t panic and I won’t beat myself up, I’ll just hop right back into the shower – but it turns out, I don’t need to. The program runs and spits out two beautifully identical figures: evidence of air-tight logic, pristine math. I sit back in triumph, then quickly jump up as I remember that my chair is ivory fabric and my hair is neon pink dye that has just been treated to a too-hot soaking. I shoot off a “Fixed it!” Slack message to my manager and ride the wave of victory all the way through the presentation the next day.
Enjoy my content and want to show your appreciation? You can share this post, pay it forward by teaching someone else, or buy me a coffee!
[Photo credit: Chandler Cruttenden via Unsplash]