This is a Christmas story about a refactor drama.
🎄 Happy Christmas everyone! 🎄 Continue reading
Alright it’s Friday, 22nd of December. Yes, Christmas is in three days.
🎶 Christmas 🎶
For this occasion I’m gonna tell you what’s the worst thing that can happen to a programmer on this kind of day. What I’m going to describe here, is really the worst thing! And it happened to me on this day. Prepare your tissues and be ready to cry with me. Oh, the destiny. (You’d better read this by the fireplace by the way, with a mug of hot chocolate topped with whipped cream) So much for a cheerful Christmas story, right. Come on, read on. It gets better.
To let you picture the environment where my despair took place, here is how the office looked like today:
Do you feel all the motivation and enthusiasm burning down the place?! That’s right we are boiling to deliver great work here, right, team?!
💤 😴 💃 🏓 👣 🌴 ☕️ 😴💤
No one? Errr…yeah, okay…😞 That’s just me taking a picture of the open space while everyone else is elsewhere between the cafeteria, playing foosball, video games or on holidays. I mean, it is Xmas! Yet I was really working! I was actually very eager to work today because yesterday I spent all day decrypting a tough bug and today I was going to write a neat fix for it. That’s the best setting for this kind of day when you have to work but your mind is already away in its happy place. No need to investigate anymore, you just need to write your code, deliver and voilà: holidays! Indeed, today is our last day before the end of the year shutdown when all the company worldwide is off for one week. So, yeah that’s really the best setting, finish your dev, push it and done, you go on holidays mind free. Unless of course your life has bugs and the ideal setting is really just an edge case begging to be discovered.
That’s when at 4:05pm my mind popped a brilliant idea:
🔊 Hey, let’s clean the code (again)! Let’s do a little more! Let’s prettify and refactor! Come on, it will be fun!
I thought, since I’m done, a small refactor won’t hurt, it can only be better. How many of you haven’t done that, be honest? Your feature is ready, but you refine here and there, just to beautify your masterpiece. Right. So I refactored. Indeed, it was really prettier. This block was now a function, comment here, comment there, it was fine art 👌. That’s when the edge case revealed itself in all its magnificence. Chanting and dancing all over my dead code.
IT WAS NOT WORKING ANYMORE.
NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!! (body falling off cliff)
WHAAAAAAAAAAAAAAAAAAATTTTTTTTTTT!!!!!! (echo from a far distance)
ARE YOU KIDDING ME!!!!!!!! (silence)
Okay. Let’s regroup here. Stay calm. Just retrace all the steps before this. I was getting ready to retrace everything. All of it, all over again. 😭 This. This got me fully awake alright. Suddenly, my mind was 100% with me to solve this. I so wanted to do my PR and leave. One minute ago, it was ready! Now it was all inert. What! Is it the cache? Really? Now?
You got it. Yes, this is it. This is the WORST THING that can happen to a programmer on this kind of day. Now you know. You were close to pushing and bam💥, you had to refactor. Now it doesn’t work anymore. Yet, you feel the fix is there, easy, but you don’t see it. Your mind is gone, and you think of one thing only:
I want to leave!!!
But you leave now with something unfixed, and it will chase you during the holidays. It’s a horrible feeling. I hate it. Thinking about bugs during time away is the worst. Because you can’t stop yourself from imagining possible solutions to try, but then you can’t try because you’re on holidays, you don’t have your computer or whatever. I can’t just drop it, especially when I feel the fix is nothing, I have to fix it, I can’t go on holidays, no way. I told myself “You really can’t do without a shot of adrenaline, can you? Damn!” No response. My peer next to me though, shared my pain and nodded while I was cursing the console with a storm going on in my head. “I understand, it is the worst” he said, “But have a good Christmas!” and then he was gone. I was alone in the dark.
The problem in these moments is that you don’t even see your code clearly anymore so much you know it, and so much you are convinced it was working. What you did is JUST a refactor, it’s the machine that is wrong, not you, it’s always the machine!!! Everything becomes a total black hole sucking up all your light. “It has to be the cache”, you mutter to yourself. You hit the refresh button seven hundred times. Nothing. Then you don’t really want to undo all your refactor because: “it’s a silly mistake, I will find it, it’s just there, I know it. I don’t want to redo everything. I won’t. I swear I won’t!” As you’re shaking, you tell your imaginary friend:
"I will find it".repeat(+∞)
So, I debugged. It was brutal. Every variable got its own breakpoint. Every. Single. One. That’s how you want to play it? Okay! That’s how I’m gonna play it! I stopped at every corner, at every line number, I scanned any dark areas, and monitored any suspicious behaviours. I would randomly stop any uncanny variable passing by and asked “What are you doing here?”, “Looking for the meaning of life”, some of them said, which I found reasonable, so I let them pass. But I knew it, some of them were hiding something, or should I say, someone?… It was visible from the way they would accept to be evaluated only in groups. They would not let themselves be evaluated on their own. Odd. What would they have to hide? Or should I say, whom?… And why? One of them was not clear. Who would suspect that variables were supportive of each other? I had never seen such thing. But I would find out, I had prepared a trick.
As a group approached, I pretended to evaluate the group, but as they stopped I started evaluating them separately! That’s right, I removed the
&& and the
||. That’s when one of them escaped. There! That was my target! Run! You gotta run! A breathless run started for both of us. I chased it through all the validation steps, nothing was going wrong, it was extremely agile. From afar I could not even distinguish its type. But when suddenly I saw it jump a step, I knew what it was. It had exactly the profile you never suspect to be able to bring down the system. It was… a BOOLEAN!
There, I had tracked the little punk. Cornered in a no return zone. It was one silly boolean. It was staring at me, laughing and jumping all around me. What? I yelled, “Freeeeeeeze!”, “Put your hands in the air and…”, that’s when the boolean replied in that terrible high pitched voice “…and wave’em like you just don’t care?… Hahahahahaaha!” I paused a second, I was so mad at it, I wanted to, I wanted to… I wanted to make it
null, you know? That little bastard! But I was on duty, I could not throw my life away like this, so I remained calm and said “Okay. You and I need to have a little talk.” That’s when I grabbed it, and asked it straight in the eyes:
Why are you always
But it kept on laughing, and laughing, and laughing. A laugh that will haunt me in my worst nightmares.
Consternated, I looked aside. Suddenly, a detail caught my eye. I looked closer. That was it. I had understood. I understood why it was laughing so madly. It was lacking a
!. The refactor had wiped off its
! Really?!! You dare doing this to me on Christmas? How much of a heart you have, you cold machine? You have no pity. Anyway, I put the poor boolean down, put back its little
! when suddenly it stopped laughing. During a brief moment, its shaped was changing and becoming a little bigger, when it stopped, it had recovered its mind and said in a deep voice: “Hello, the sun will be brighter tomorrow.” Then it vanished into the runtime continuum, closing the gateway it appeared from.
I cannot explain all of it. But its laugh still resonates in my mind as I’m telling this story.
Fixed. Committed. Pushed.
I was gone.