“Simplicity is prerequisite for reliability.” – Edsger Dijkstra, How do we tell truths that might hurt?
Programs that matter are large and long-lived. It’s disturbingly difficult to write them, and most teams fail. What kills them is usually complexity. Everyone agrees that “simple is better” and “keep it simple”, so why do programmers, when actually coding, choose to do the opposite? Another entry (Write code top-down) discusses one big reason, but here I want to argue for a mindset that values simplicity over almost anything else.
Yes, the program must do what the customer wants it to do. But the next highest priority is simplicity. Specifically:
Don’t future-proof your programs. You can’t predict the future, so any future-proofing is complexity that may not pay off.
Don’t add any code that you don’t need right now. When a co-worker wants to add, say, a level of abstraction to the code, ask them: “What problem that we have right now that this solves?” You’ll be surprised how often they can’t answer the question without ignoring the “right now” part. Ask yourself this question too when tempted to add something.
Strip out complexity that was added but not used. People avoid this because such changes are risky for no perceived benefit (besides, the code might be turn out to be useful after all). But this is just as good for the program’s health as not introducing the complexity in the first place.
YAGNI (You Ain’t Gonna Need It) trumps DRY (Don’t Repeat Yourself). Don’t create infrastructure or re-usable components until you need them. Don’t write a line of code unless it’s solving a problem that you have right now. I sometimes prefer to copy-and-paste code rather than extract the common code to function, if the extraction would be hard to understand. Both involve risk, but complexity is a worse kind of risk.
The above advice goes against best practices. Everyone knows good programmers should plan for the future, should avoid boilerplate, should write elegant abstractions. Don’t. Those “good programmers” write heaps of garbage that get thrown away. Write the least code that will get the job done, and you’ll perhaps have a chance to build a large long-lasting program.