Occam’s Razor

Sean Coates
Aug 24, 2017 · 1 min read

Among competing hypotheses, the one with the fewest assumptions should be selected.


This isn’t exactly a new idea. Actually, one could think of it as a 700 year old programming technique.

Consider two approaches. One method requires you to specify a lot of dependencies. Methods have over seven parameters. Complex machinations occur, requiring all of the objects to be “just so” in order to function. The class assumes that everything is perfect. Unfortunately, this class also has many reasons to change. When any of its dependent parts changes, the class needs to be rebuilt, possibly re-engineered. This makes the code rather fragile, leading to major support issues in the future.

In the second approach, classes and methods are kept small and simple. The number of dependencies is kept to a minimum. Since each method has only one job, it only has one reason to change. With fewer dependencies, the methods are easier to test.

Simpler is generally better. A class that makes fewer assumptions is more testable.

)

Occasional posts from @fooyay about software engineering, crypto, finance, and more. https://about.me/fooyay (Content reflects my opinion and not my employer.)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade