[论文解读] Why Nominal-Typing Matters in OOP
本文主张,在面向对象编程(OOP)中,名义类型系统通过将类型名称与行为契约关联,提供了关键的语义清晰性,从而在继承与子类型之间实现一一对应关系,这与结构化OOP模型相反。通过领域理论的对比分析,本文表明名义类型支持更稳健、可维护的软件设计,主张未来的基础OOP研究应优先考虑名义模型而非结构化模型。
The statements `inheritance is not subtyping' and `mainstream OO languages unnecessarily place restrictions over inheritance' have rippled as mantras through the PL research community for years. Many mainstream OO developers and OO language designers however do not accept these statements. In \emph{nominally-typed} OO languages that these developers and language designers are dearly familiar with, inheritance simply is subtyping; and they believe OO type inheritance is an inherently nominal notion not a structural one. Nominally-typed OO languages are among the most used programming languages today. However, the value of nominal typing to mainstream OO developers, as a means for designing robust OO software, seems to be in wait for full appreciation among PL researchers--thereby perpetuating an unnecessary schism between many OO developers and language designers and many OO PL researchers, with each side discounting, if not even disregarding, the views of the other. In this essay we strengthen earlier efforts to demonstrate the semantic value of nominal typing by presenting a technical comparison between nominal OO type systems and structural OO type systems. Recently, a domain-theoretic model of nominally-typed OOP was compared to well-known models of structurally-typed OOP. Combined, these comparisons provide a clear and deep account for the relation between nominal and structural OO type systems that has not been presented before, and they help demonstrate the key value of nominal typing and nominal subtyping to OO developers and language designers. We believe a clearer understanding of the key semantic advantage of pure nominal OO typing over pure structural OO typing can help remedy the existing schism. We believe future foundational OO PL research, to further its relevance to mainstream OOP, should be based less on structural models of OOP and more on nominal ones instead.
研究动机与目标
- 挑战当前编程语言研究领域中关于在OOP中继承与子类型是分离的观点,特别是在名义类型语言中。
- 证明名义类型相较于结构类型,为OOP提供了更具有语义意义且实用的基础。
- 通过展示名义类型的技术与语义价值,弥合主流OOP开发者/语言设计者与编程语言研究者之间的分歧。
- 主张未来的基础OOP研究应从结构化模型转向名义模型,以提升其相关性与实际影响力。
提出的方法
- 对名义类型OOP的领域理论模型与知名结构类型OOP模型进行技术性比较。
- 分析名义类型语言中类名如何作为行为契约的引用,将语义意义嵌入类型之中。
- 对比名义系统中类型名称(固定且与契约关联)与结构系统中类型名称(同义词且无固有意义)的作用差异。
- 研究名义性在子类型、继承与类型实例化方面的含义,特别是在二进制方法与递归类型背景下的表现。
- 使用表3系统比较名义系统与结构系统在契约包含、类型实例化与子类型行为等关键特性上的差异。
- 强调Java等语言中的泛型与F-有界多态性进一步支持了名义类型的可行性与表达力。
实验结果
研究问题
- RQ1为何主流OOP开发者与语言设计者在Java、C#等语言中会将继承与子类型视为等同?
- RQ2名义类型在OOP类型系统中相较于结构类型具有哪些语义优势?
- RQ3名义与结构化OOP的领域理论模型在处理行为契约与类型身份时有何不同?
- RQ4名义类型在多大程度上能实现继承与子类型之间的一一对应?
- RQ5对名义类型的更清晰理解是否有助于弥合编程语言研究者与主流OOP实践者之间的分歧?
主要发现
- 名义类型允许类型名称直接引用行为契约,使对象规范更加明确且可静态检查。
- 在名义类型OOP中,类型继承与子类型是一一对应的,保持了开发者的心理模型并确保了一致性。
- 结构化OOP模型忽略了行为契约,导致虚假的子类型化与二进制方法问题,而名义类型可避免此类问题。
- 名义类型天然支持递归类型与二进制方法,而结构化系统则需特殊构造或面临表达力限制。
- 名义系统中类型名称不可重新绑定,确保了类型稳定性并防止了继承过程中的语义混淆。
- 本文结论认为,未来的基础OOP研究应优先采用名义模型,以更好地服务于主流软件开发。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。