paperbot · PL 论文追踪

全部论文 待读 收藏

P2 How C++ Developers Use Immutability Declarations: An Empirical Study

C++ 开发者如何使用不可变性声明:一项实证研究
ICSE 2019 IEEE/ACM 41st International Conference on Software Engineering (ICSE)2019匹配度 3/10 · 论文是 C++ const/不可变性使用情况的实证研究,包含轻量静态分析来识别可加 const 的方法,属于 PL 与软件工程交叉的静态分析背景。但它不涉及机器学习系统、Agentic 程序、LLM 改进静态分析/形式化验证、浮点程序分析或贝叶斯程序分析,与当前核心研究方向仅有泛化关联。引用 3 inbox
Jonathan Eyolfson, Patrick Lam
crossref: 2026-09-12dblp: 2026-09-12

AI 速览

一句话:通过分析 7 个开源项目,实证揭示 C++ 开发者使用 const 表达不可变性的现状与漏标差距。

尽管语言设计中的最佳实践建议尽可能使用不可变性,但开发者实际采纳程度缺乏实证证据。本文研究 C++ 开发者如何使用 const 限定符来表达不可变类与方法。作者分析 7 个中大型开源项目,收集两类数据:开发者书写的 const 标注,以及一个简单静态分析所识别出的明显可加 const 的方法。结果显示,非平凡类(方法数超过 3)中位数仅约 5% 为不可变;但方法层面的不可变性标注相当普遍:开发者对 46% 的方法加了 const,静态分析估计至少 51% 的方法可以加 const,且在未标注方法中至少 6% 被漏标。文章进一步讨论了 const 的实际使用模式与这些发现的含义。

问题
论文关注 C++ 开发者是否以及如何在实践中使用不可变性声明(const),尤其是是否编写非平凡不可变类/方法并为其添加标注。
方法
分析 7 个中大型开源项目,结合开发者书写的 const 标注与一个简单静态分析来识别明显可加 const 的方法。
评估
跨项目统计不可变类比例、const 方法比例、可加 const 方法比例及漏标比例,并定性讨论 const 的实际使用模式。
原文摘要(Abstract)

Best practices for developers, as encoded in recent programming language designs, recommend the use of immutability whenever practical. However, there is a lack of empirical evidence about the uptake of this advice. Our goal is to understand the usage of immutability by C++ developers in practice. This work investigates how C++ developers use immutability by analyzing their use of the C++ immutability qualifier, const, and by analyzing the code itself. We answer the following broad questions about const usage: 1) do developers actually write non-trivial (more than 3 methods) immutable classes and immutable methods? 2) do developers label their immutable classes and methods? We analyzed 7 medium-to-large open source projects and collected two sources of empirical data: 1) const annotations by developers, indicating an intent to write immutable code; and 2) the results of a simple static analysis which identified easily const-able methods---those that clearly did not mutate state. We estimate that 5% of non-trivial classes (median) are immutable. We found the vast majority of classes do carry immutability labels on methods: surprisingly, developers const-annotate 46% of methods, and we estimate that at least 51% of methods could be const-annotated. Furthermore, developers missed immutability labels on at least 6% of unannotated methods. We provide an in-depth discussion on how developers use const and the results of our analyses.

链接与引用

DOI 原文 · DBLP

BibTeX
@inproceedings{Eyolfson019,
  title = {How C++ Developers Use Immutability Declarations: An Empirical Study},
  author = {Jonathan Eyolfson and Patrick Lam},
  booktitle = {ICSE},
  year = {2019},
  doi = {10.1109/icse.2019.00050}
}