Flexible vs clean code

In reaction to a reddit post:

I disagree. There are three kinds of code:

  1. simple clean code that works according to the current requirements
  2. “flexible” over-engineered code that does the same thing as (1) only in a more complicated way and has not yet turned into (3).
  3. a total mess

Flexibility almost always means adding complexity. Complex code is harder to reason about, harder to change, harder to optimize.

The goal should be to write clean code that separates logical components of the program. Well-structured, non-repeating and easy to understand code is the best you can do.

Any attempt to make a prediction of the future and somehow make the code “ready” for it makes it worse. You don’t know the future requirements.

If you do, then what you write is not really flexible code, it’s just written according to the spec, version 2.0.

There may be a requirement for a plug-in architecture of some components. For example, you may want to have an easy way to add new types of enemies, weapons, special effects or even game modes. This needs to be part of the specification. Code that enables such things should still do so in the most simple way possible.