loke.dev
Cover image for Boring Code is a Feature

Boring Code is a Feature

Complexity is a debt that compounds faster than you think, so stop trying to be clever and start being readable.

· 4 min read

I once spent four hours tracing a production bug through a "beautiful" chain of three nested higher-order functions and a custom regex that looked like a cat had walked across the keyboard. When I finally found the logic error, I realized I was the one who had written it six months prior. I hadn't been writing a solution; I had been building a monument to my own ego.

We often treat "clever" as a compliment in software engineering. We hunt for the one-liner, the esoteric language feature, or the abstraction that handles ten different edge cases with a single generic class. But clever code is a liability. It’s a high-interest loan taken out against your future self’s sanity.

The Debugging Ratio

Brian Kernighan, co-author of _The C Programming Language_, famously noted that debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

The goal isn't to prove you're the smartest person in the room. The goal is to write code that makes the next person (who might be a tired, caffeinated version of you at 3 AM) feel like a genius because they understood your logic in five seconds.

Clever vs. Boring: A Comparison

Let’s look at a common task: grouping an array of objects by a specific key.

The "Clever" developer might try to flex their functional programming muscles:

// The "Look Ma, No Hands" approach
const groupBy = (arr, key) =>
  arr.reduce(
    (acc, item) => ((acc[item[key]] = [...(acc[item[key]] || []), item]), acc),
    {}
  )

This works. It's concise. It's also a nightmare. You have a comma operator, a spread operator inside a loop (which, by the way, is $O(n^2)$ for performance due to array cloning), and a nested assignment. It’s a puzzle, not a piece of logic.

Now, consider the "Boring" approach:

interface User {
  id: number
  role: 'admin' | 'editor' | 'viewer'
}

function groupUsersByRole(users: User[]): Record<string, User[]> {
  const grouped: Record<string, User[]> = {}

  for (const user of users) {
    const role = user.role

    if (!grouped[role]) {
      grouped[role] = []
    }

    grouped[role].push(user)
  }

  return grouped
}

Is it longer? Yes. Is it "exciting"? Not at all. But you can scan this in a heartbeat. You see the types, the intent, and the lack of side effects. If a bug appears—say, a null check is needed—you know exactly where to put it.

The Maintenance Tax

Every time you use a "clever" trick, you are increasing the cognitive load of the codebase. Cognitive load is the amount of mental effort required to understand a piece of information.

When you encounter "Boring" code, your brain operates on autopilot. You recognize standard patterns (loops, conditionals, early returns) and focus on the _business logic_. When you encounter "Clever" code, your brain stops processing the business logic and starts processing the _syntax_.

You have a finite amount of "complexity points" to spend on a project. Spend them on solving the actual problem, not on implementing a custom dependency injection framework for a three-page marketing site.

When Boring is Hard

Paradoxically, writing boring code is often harder than writing clever code. It requires the discipline to:

  1. Resist the New: Just because a new library allows you to write "zero-boilerplate" code doesn't mean it’s the right choice if it adds a layer of magic that obscures how data flows.
  2. Avoid Dry-ing out too early: Sometimes, a little bit of duplication is better than a "god-object" abstraction that links five unrelated modules together.
  3. Prioritize Naming: Boring code relies on extremely descriptive names. If a function is named calculateUserTaxRateAdjustedForRegion, I don't need to read the implementation. If it's named calcT, I'm going in.

The Edge Case of Performance

Sometimes, you _have_ to be clever. If you’re writing a game engine, a high-frequency trading platform, or a core library used by millions, you might need bitwise operations or pointer arithmetic to hit performance targets.

But for 95% of us building web or mobile apps, the bottleneck isn't the for loop; it's the unoptimized SQL query or the 2MB image being served to a mobile device. Don't sacrifice readability for performance gains that are statistically invisible.

The Senior Developer's Arc

There is a common trajectory in a developer's career.

  • Junior: I don't know how to make it work.
  • Mid-level: I know how to make it work using every design pattern I just read about.
  • Senior: I know how to make it work using a simple if statement.

Choose the boring path. Your teammates will thank you, your future self will thank you, and your code will actually survive long enough to become "legacy." And in this industry, surviving long enough to be called legacy is the ultimate mark of success.