The worst code I ever saw — or, politics are unavoidable
Many years ago, I was working on a search engine that wanted to compete with Google. I was in the team that rendered query answers on the web. We used an in-house webserver written in C++, and most of our code was C++ that hooked tightly into the webserver, which got us great performance.
Other teams in the company were in charge of crawling, indexing, classifying, and sometimes they’d want to accelerate the adoption of some of their algorithms into the displayed page, and would ask for our collaboration. And so it was that one day my boss asked me to oversee the integration of a piece of code from a team that wanted to showcase their new image carousel technology. I started reading the code. It was big, and truly awful. Messy, incoherent. There were allocations opened that not only were not reclaimed, but that were even unnecessary, I suspected.
The crux of the code was a triply-nested for
loop used for image placement. It
was breaking my brain. I think I spent almost a full day just to get an idea of
what the code did, overall. I had a growing suspicion about the nested loop. I
emailed the author asking her to go over the code together in person. In front
of a whiteboard, I nudged her to explain the iteration informally with
diagrams. She started to show me the working of the algorithm. My suspicion had
been right. There was no need for a triply nested loop. One of the loops was
avoidable, as I explained in front of the whiteboard. After some back and forth,
she agreed. In the code-review tool, I pointed out a large number of issues in
the code that were blockers, including the nested loop.
A day or two later she messaged me that she had addressed all my comments, and
was the code ready to merge, please, people were getting impatient. I went over
the code. Better, but still awful. And as I understood the code better, I
started to realize that even the doubly nested for
was overkill. A single
for
and some conditionals would be enough; the code would also become
clearer. I sent her another round of comments that I considered blockers.
At that point I started getting nudged by my boss. There were complaints from
her team about me: days had passed and the code was still not merged. I kept
coming up with new objections. What was going on? I was wasting their time.
I explained the situation, and my boss agreed to carry on with the reviews.
I asked my friend J.P., whose opinion I valued highly, to look at the code. After an hour he came to my office with a face of disgust. The code was just awful. He didn’t want something like that merged into our codebase. It would be better to chuck the code out and write it ourselves. With renewed conviction, I told my boss we needed to carry on with the successive reviews and improvements.
The following day, my boss called me to his office. The situation had escalated.
The other team’s top guy, who had the rank of director, had sent a strongly worded
email to our director. There were accusations of gatekeeping, almost of
sabotage.
To de-escalate, we would merge the code in its current state. And we did.
A few months later the yearly promotions were announced. The software developer, who had been a Senior when she wrote that awful code, had been promoted to Principal. There were some snide remarks in our team: she happened to be married to one of the highest ranking people in our organization.
Looking back, I regret that I was so unaware and unprepared and innocent. As was my boss.
I find it funny when I hear people asking to take politics out of things. Say, movies, or sports, or music. Or work. As if politics were not an integral part of every collective human endeavor. It’s better to accept that, and to prepare and engage.