DRMacIver's Notebook
Implicit vs Explicit
Implicit vs Explicit
- Beautiful is better than ugly.
- Explicit is better than implicit.
- Simple is better than complex.
- Complex is better than complicated.
- Flat is better than nested.
- Sparse is better than dense.
- Readability counts.
- Special cases aren’t special enough to break the rules.
- Although practicality beats purity.
- Errors should never pass silently.
- Unless explicitly silenced.
- In the face of ambiguity, refuse the temptation to guess.
- There should be one– and preferably only one –obvious way to do it.
- Although that way may not be obvious at first unless you’re Dutch.
- Now is better than never.
- Although never is often better than right now.
- If the implementation is hard to explain, it’s a bad idea.
- If the implementation is easy to explain, it may be a good idea.
- Namespaces are one honking great idea – let’s do more of those!
The only one of these people seem to remember is “explicit is better than implicit”. Unfortunately, it falls afoul of the problem that almost all “X is better than Y” advice has, which is that the important qualification “All else being equal” is left, well, implicit.
Explicit is more verbose than implicit. Explicit is more expensive than implicit. If you try to make everything explicit then you will never get anything done, because as with everything, being explicit has costs as well as benefits. Explicit may be better than implicit, but implicit is cheaper than explicit. Everything is a trade-off.
It can be worth adjusting where you are in trade off space though - just because everything is a trade off doesn’t mean you’re automatically in the right region of trade off space, and it’s much easier to err in the direction of making things too explicit rather than too implicit.
Tying into past posts:
- One theme of the making difficult decisions discussion is that making your decision making process explicit is often beneficial when you’re struggling.
- In Try not to think about it I argued that for many decisions it’s actually better to make them implicitly rather than explicitly, by building the answer into your habits and environment, because if you make them explicitly then you open up the possibility of making them incorrectly.