The Function I Was Too Proud To Split

by Serguey Shinder

For most of a year I kept a single function that I was quietly proud of. It was clever. It did five things at once, threaded a bit of state through each of them, and saved a few lines compared to the obvious version. When a teammate asked why it was shaped that way, I would explain the cleverness and they would nod, and I took the nodding as agreement.

The trouble started when the function needed a small change. Not a rewrite, just a new branch for a new case. I opened it expecting a two-minute edit and lost an afternoon. Every one of the five things it did was entangled with the others, so touching one meant re-reasoning about all of them. My own cleverness had built a room with no doors.

I remember sitting there, slightly ashamed, realising that the compression I had been proud of was never really for the reader. It was for me, and for a version of me that had already forgotten how the thing worked. The code was a monument to a moment of understanding I no longer had.

So I did the unglamorous thing. I split it into five plainly named functions, each doing one job, each boring enough to read at a glance. The line count went up. The cleverness disappeared entirely. And the change I had been fighting became the two-minute edit I had originally expected.

What surprised me was how much lighter I felt afterward. I had been carrying that function around in my head, holding its whole shape in memory every time I went near it. Once it was five small honest pieces, I could forget most of them. I only had to think about the one I was changing. That, I have come to believe, is what good structure actually buys you: permission to forget.

I still feel the pull toward clever compression. It flatters the part of me that wants to be seen as sharp. But I have learned to distrust the feeling of pride that comes from code being hard to follow. Real craft, the kind that survives contact with next year's problems, tends to feel almost embarrassingly simple. It reads like something anyone could have written, which is exactly why anyone can change it.

Now when I catch myself admiring my own cleverness, I take it as a warning rather than a reward. Somewhere in that admiration is a room I am building with no doors, and eventually I will be the one locked inside.

– Serguey Asael Shinder

Leave a comment