What is Clever Code, what disadvantages does it cause and what measures help against it?
Clever Code – Seemingly Smart Software Development
Clever Code sounds positive at first, doesn’t it? It sounds like a part of a software that solves a problem particularly elegantly. Or like an algorithm that masters a complicated task by magic. Of course, software should be cleverly programmed, but the term “Clever Code” means something else: it describes the attempt of programmers to master challenges extra cleverly. In an individual way, better and smarter than any other developer would have solved a problem. Unfortunately, programmers who try to programme Clever Code forget three central aspects of software development:
- The main goal of software development is to create useful software with little effort.¹
- Software should be readable, changeable, extensible and maintainable by other software developers. In other words, the principles and practices of Clean Code should be used.
- Technical debt makes it difficult for software to evolve.
Of course, it is possible to write lines of code that can be parsed 10% faster, and writing such lines of code might be clever in a positive sense of the word. However, if at the same time the effort to produce these lines of code increases, if it becomes more difficult for other software developers to read, understand and, if necessary, change this code, then this is anything but clever. Then it is counterproductive.
Clever Code is not Clean Code
“Programming is not like being in the CIA, you don’t get credit for being sneaky” is how Steve McConnell put it back in 2004 in his book “Code Complete”². And that’s exactly how it is. Software development is about
- production efficiency and
- continuous improvement.
This foundation of values is the basis for the development of Clean Code. And Clean Code is the opposite of Clever Code.
The Motivation for Clever Code
What is the motivation of programmers to want to develop code in a particularly clever way? Various motivations are conceivable, among them
- the claim to want to be the best, and thus the attempt to implement a “special” solution.
- a false understanding of good software development.
- the attempt to make oneself indispensable.
- lack of experience in software development.
- an internal competition with colleagues.
- because it can be fun.
Measures against Clever Code
There are several ways to take measures against the development of Clever Code:
- Developing software in teams, e.g. in the form of pair programming or mob programming (before implementation).
- Defining clear coding and documentation guidelines (also before implementation).
- Conducting a software walkthrough or peer review (during implementation).
- Carrying out refactorings for elimination (after implementation).