Skip to content
TopicTracker
出典 HackerNews原文を表示
翻訳言語翻訳言語

Postel's Law and Type Annotations

Postel's Law (also known as the Robustness Principle) states: "Be conservative in what you do, be liberal in what you accept from others." This article explores how this principle applies to type annotations in programming, discussing the balance between strict type enforcement and flexible acceptance of inputs for building robust systems.

背景メモ

- **Postelの法則(ロバストネス原則)**: 「送信するものには厳密に、受信するものには寛容に」という設計原則。元はTCP/IPなどのネットワークプロトコル設計に由来するが、ソフトウェア全般で引用される。 - **型アノテーション(型注釈)**: Python(PEP 484)やTypeScriptなど、動的型付け言語に「後付け」で追加される静的型システム。コードの可読性向上やツール支援(IDE補完・静的解析)を目的とする。 - この記事の論点: Postelの法則を型アノテーションに適用すると、入力を受け入れすぎる「寛容な型」がかえってバグを生む、という逆説を指摘。API境界などでの型の厳密さと柔軟さのトレードオフを論じている。

関連記事