paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Making the liskov substitution principle happy and sad

让 Liskov 替换原则快乐与悲伤
ICSE Proceedings of the 40th International Conference on Software Engineering: Software Engineering Education and Training2018匹配度 1/10 · 该论文关注的是用笑脸/哭脸视觉助记法帮助学生记忆 LSP 前置/后置条件规则,属于编程教育而非静态分析、LLM/Agent 或浮点/贝叶斯程序分析。虽然涉及类型系统中的 LSP,但未触及用户核心研究方向。引用 5 inbox
Elisa Baniassad
crossref: 2026-09-12

AI 速览

一句话:提出用笑脸/哭脸视觉助记法帮助学生记忆 LSP 的前置/后置条件强化与弱化规则。

该论文关注程序设计课程中 Liskov 替换原则(LSP)的教学难点:两门后续课程的学生都难以记住子类型操作的前置条件不能增强、后置条件不能削弱,尤其混淆前置与后置条件中哪一个可以增强或削弱。作者设计了一个简单的视觉助记法:可替换的方法呈“笑脸”,笑脸顶部较宽对应更弱/更宽的前置条件、底部较窄对应更强/更窄的后置条件;不可替换的方法呈“哭脸”,顶部较窄对应更强的前置条件、底部较宽对应更弱的后置条件。虽然该方法远非完美,但作者发现它能帮助学生跨过记忆障碍,进而讨论 LSP 周围更有趣的设计问题。

问题
学生在学习 LSP 时难以记住子类型操作的前置/后置条件限制:前置条件不能增强,后置条件不能削弱,尤其混淆哪一项可强化、哪一项可弱化。
方法
提出一个简单视觉助记:可替换方法用笑脸表示,顶部宽/底部窄暗示更弱前置条件与更强后置条件;不可替换方法用哭脸表示,形状相反。
评估
作者在两个后续课程中观察到学生困难,并报告该助记法虽远非完美,但能帮助学生越过记忆障碍并转向 LSP 的设计问题。
原文摘要(Abstract)

The Liskov Substitution Principle states, among other constraints, that a subtype is not substitutable for its super type if it strengthens its operations' preconditions, or weakens its operations' postconditions. We found that students in two subsequent courses had trouble remembering these rules. Their major stumbling block appeared to be recalling which condition (pre- or post-) could be strengthened and which could be weakened. We developed a simple visual reminder to help: A method is happy if it is substitutable---A smile is wider at the top than at the bottom, suggesting weaker/looser/wider preconditions, and stronger/tighter/narrower post conditions.; A method is sad if it isn't substitutable---a frown is narrower at the top, suggesting stronger/tighter/narrower preconditions, and wider at the bottom, suggesting weaker/looser/wider postconditions. Though the technique is far from perfect, we found that it allowed students to move on to the more interesting design questions around the LSP.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot4555,
  title = {Making the liskov substitution principle happy and sad},
  author = {Elisa Baniassad},
  booktitle = {ICSE},
  year = {2018},
  doi = {10.1145/3183377.3183392}
}