Clean Code Is Not Elegant Code

Clean Code Is Not Elegant Code

There is a common misconception in software development: believing that elegant code is the same as clean code. But that is far from true.

The main difference is that elegant code impresses the reader, while clean code helps the maintainer.

Sometimes they can be the same thing. Often, they are not.


The problem with excessive elegance

Elegance usually means:

  • High abstraction;
  • Heavy use of patterns;
  • Complex composition;
  • Premature generalization;

It may look sophisticated. But it can create invisible coupling, cognitive complexity, and maintenance difficulties.

Let’s look at real examples.


Example 1 — Strategy Pattern when it wasn’t needed

Imagine a system with only two types of calculation:

function calculateTotal(type: "normal" | "discount", value: number) {
  if (type === "normal") return value;
  if (type === "discount") return value * 0.9;
}        

Simple. Direct. Readable.

Now someone decides to apply the Strategy Pattern:

interface CalculationStrategy {
  execute(value: number): number;
}

class NormalStrategy implements CalculationStrategy {
  execute(value: number) {
    return value;
  }
}

class DiscountStrategy implements CalculationStrategy {
  execute(value: number) {
    return value * 0.9;
  }
}        

Technically correct. Architecturally elegant.

But now we have:

  • 3 files;
  • More indirection;
  • More failure points;
  • Unnecessary complexity;

Now ask yourself: do you really need this extensibility today?

Or are you anticipating complexity that may never come?

Premature elegance is just overengineering.


Example 2 — Overly generic custom hooks

In React, it’s common to see something like this:

const useFetchData = <T>(url: string): {
  data: T | null;
  loading: boolean;
  error: Error | null;
} => { ... }        

Reusable? Yes. Generic? Also yes. Ideal? Not always.

Common problems:

  • No caching;
  • Manual revalidation;
  • Duplicated state;
  • Poorly handled concurrency;
  • Ignored cancellation;

Sometimes using a more specific solution (or even a well-established library) is cleaner than building an elegant abstraction.


Example 3 — Excessive functional composition

Elegant code:

const result = pipe(
  filter(isActive),
  map(transform),
  reduce(accumulate)
)(data);        

Beautiful.

But what about someone who doesn’t know pipe? Someone who has never seen this pattern? A junior developer on the team?

Clean code is code the team understands.

Elegance should never come before clarity.


Where patterns actually help

Now, the other side of the coin.

Patterns are powerful tools when:

  • There is real behavioral variation;
  • There is a clear need for extensibility;
  • The domain is complex;
  • Change is predictable;

Classic example:

If you have multiple payment gateways, then Strategy makes sense.

If you have multiple complex concurrent UI states, specialized hooks make sense.

The problem isn’t the pattern.

The problem is using patterns as decoration.


The real definition of clean code

Clean code is:

  • Easy to read;
  • Easy to modify;
  • Hard to break;
  • Consistent with its context;

It respects:

  • The product stage;
  • The team size;
  • The project maturity;
  • The real probability of change;

Elegant code impresses. Clean code survives.


The most common mistake

Before asking:

“What’s the ideal pattern here?”

Ask:

“Do we need a pattern here?”

That question changes everything.


Architectural maturity

Over time, you learn that:

Not every problem needs abstraction. Not every duplication must be removed immediately. Not every generalization is smart anticipation.

Sometimes, the right code is simply the simplest possible one.


Conclusion

Clean code is not minimalist code. It’s not short code. It’s not sophisticated code.

It is appropriate code.

Elegance is aesthetics.

Cleanliness is sustainability.

And software is a living system.

The real question should never be:

“Does this look beautiful?”

But rather:

“Will this still make sense six months from now?”

To view or add a comment, sign in

More articles by Rafael Kepler

Explore content categories