Skip to content
TopicTracker
From HackerNewsView original
TranslationTranslation

Postel's Law and Type Annotations

Postel's Law ("be conservative in what you send, be liberal in what you accept") is examined in the context of Python type annotations. Being liberal in accepted types can cause subtle bugs since Python ignores type hints at runtime. The post argues that for type annotations, being stricter in what you accept creates more robust code.

Background

Postel's Law (the Robustness Principle, RFC 1122: "Be liberal in what you accept, conservative in what you send") is a long-standing design guideline for networked systems. This article examines whether the principle applies to programming language type annotations — formal labels that specify the kind of data a function expects or returns. The author argues that type annotations should follow the *opposite* rule: be strict in what you accept (reject bad inputs at compile time) and liberal in what you can express (allow flexible use of types). This relates to ongoing debates in software engineering about static vs. dynamic typing, and how much strictness helps prevent bugs versus how much flexibility helps developers move fast.

Related stories