3 ms·
There are two kinds of cleverness, and both require balance in their application. The first is the more obvious kind: exploiting various conditions that occur
by JesperRavn 11y ago
There are two kinds of cleverness, and both require balance in their application.
The first is the more obvious kind: exploiting various conditions that occur in your code, in order to come up with a nonstandard solution. E.g. using if (x mod 15 == 0) in fizzbuzz. The problem with this kind of cleverness is that it's hard to understand the code, and it breaks whenever the conditions it relies on stop holding.
The second kind of more subtle. It is where you organize code to properly express the nature of the problem, but this organization is itself conceptually complex. A typical example is using C++ templates where they make logical sense, but they make the code that much harder to read.
The second kind is where balance is needed most. If you use too little cleverness (or maybe too much humility), you end up with spaghetti code, or code where all the organization is done via convention instead of enforced by the compiler. If you use too much cleverness, you end up with code that is hard to read, and brittle, since so many assumptions are embedded in the code.