Problem Solving

Complexity Is the Enemy

7 min read

# Complexity Is the Enemy

Every line of code you write is a liability. The best code is the code you didn't write.

The Cost of Complexity

Complexity has hidden costs: - It takes longer to understand - It's easier to break - It's harder to test - It's harder to modify - It compounds over time

A slightly complex system today is a nightmare next year.

Where Complexity Comes From

  1. **Premature abstraction** - Building generalized solutions for specific problems
  2. **Handling edge cases that don't exist yet** - "Just in case" code
  3. **Mixing concerns** - Code that does too many things
  4. **Poor naming** - Unclear intent requires more mental overhead
  5. **Over-engineering** - Using powerful tools for simple problems

The Single Responsibility Principle

The most underrated principle in software engineering: do one thing well.

If a function does one thing, it's: - Easy to name - Easy to test - Easy to understand - Easy to reuse - Easy to modify

Practical Approach

When faced with a problem, ask: 1. What's the simplest solution that solves this? 2. What complexity am I adding? 3. Is that complexity necessary today? 4. Can I defer this complexity until it's actually needed?

The answer is often "no" to question 3 and "yes" to question 4.

The Real Skill

Writing simple code is harder than writing complex code. It requires: - Deep understanding of the problem - Discipline to not over-engineer - Willingness to refactor - Commitment to clarity

The best engineers write the least code.