Posts

Showing posts from April, 2017

The 7 Worst Atrocities of Cleverness

We know we shouldn't be clever , but what is clever? There are seven particularly bad forms of cleverness, from very small to very large. Bitwise Logic and Ternary Statements This is the lowest-level cleverness. We write a one-liner that uses bitwise logic or a ternary statement. They start out innocently. We have an assignment based on a simple condition. A full-blown if-else block feels like overkill. Then that turns into this: int i = 16 + (!(a & 4 == 0 ? thing : other).getValue().equals(b & 1 == 0 ? first : last) ^ (b & 2 != 0 ? w[0][1] : w[0][0])) ? counter - 1 : counter << 1; That's not clever. That's a train wreck. Singletons and Lying About Dependencies Design patterns are general solutions to common problems, and are often useful. But Singleton is one "pattern" (actually an anti-pattern ) that can be destructive to a codebase. Singletons are easy to write and easy to use, but they are just another form of global state. Pro