← 返回规律列表
决策

奥卡姆剃刀

在能够解释事实的方案中,较简单的解释通常更值得优先验证。

显示原始英文内容

Occam's Razor

The simplest explanation is often the most accurate one.

Takeaways

  • Simple code is easier to understand, maintain, and debug, whereas complex code has more potential points of failure. Remove or avoid unnecessary moving parts in system architecture.
  • When debugging, start with the simplest explanation before jumping into complex theories.
  • Adding more features to the app can only complicate a product without adding real value. Occam's Razor reminds us that less is more in many cases.

Overview

Occam's Razor is a problem-solving principle that reminds us that when we have multiple possible solutions, the simplest one is preferred.

In software, this principle supports the KISS ("Keep It Simple, Stupid") approach. When we decide to keep our implementations simple, we reduce the risk of further complications.

For example, if a software architecture can achieve its goals with a monolith and one database, there is no need to split it into five microservices and two databases. These extra components would only introduce complexity and potential integration and coordination issues, but no benefits.

This is a reminder to avoid the temptation of over-engineering and keep things simple.

Examples

A classic example of applying Occam's Razor while debugging is that of the broken build. Let's assume that your build system has failed. A complex thinker might think that there is some subtle regression in the compiler code, or maybe some dependency is damaged. An Occam's Razor thinker would start with simpler explanations: a typo, a missing semicolon, or a misconfiguration.

A saying often attributed to Einstein goes, "Everything should be made as simple as possible, but not simpler," which best applies to this law in engineering.

Origins

Occam's Razor dates back to William of Ockham, a philosopher from 14th-century England. His original version in Latin, "Pluralitas non est ponenda sine necessitate," can be translated to "plurality should not be posited without necessity," or "Don't multiply entities or assumptions beyond what's required."

Over time, Occam's Razor has evolved as a cornerstone of scientific methodology and logical reasoning.

核心含义

排查问题时,先验证不需要额外假设、改动更小、证据更容易获得的解释。简单不是因为它永远正确,而是因为它更容易测试和证伪。

遇到足够证据时,应当接受复杂解释;不能为了“看起来简单”而忽略真实约束。

实践例子

一个接口突然变慢,先检查近期发布、数据库索引和依赖服务,而不是马上假设存在复杂的底层硬件故障。若简单假设被排除,再逐层深入。

来源与边界

原则得名于 14 世纪哲学家 William of Ockham。它是推理启发式,不是证明复杂理论必然错误的规则。