paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Natural Software Revisited

重新审视自然软件
ICSE 2019 IEEE/ACM 41st International Conference on Software Engineering (ICSE)2019匹配度 2/10 · 该论文研究代码自然性、n-gram 与图表示在代码推荐中的效果,属于机器学习与程序语言的交叉,但不涉及静态分析、LLM/Agent、形式化验证、浮点程序分析或贝叶斯程序分析,与研究画像的核心问题关联较弱。引用 56 inbox
Musfiqur Rahman, Dharani Palani, Peter C. Rigby
crossref: 2026-09-12dblp: 2026-09-12

AI 速览

一句话:重新检验代码自然性,发现分隔符贡献显著,API 用法高度重复,图表示比 n-gram 更能捕捉代码模式。

既有研究认为源代码比英语文本更重复、更可预测,即更“自然”。本文重新检验该结论,发现表观自然性很大程度来自分号、括号等语法分隔符;在 Java 语料中分隔符占 44% 的 token。按 NLP 惯例去除标点和关键词后,代码仍重复可预测,但程度低于此前认识,故建议代码推荐器过滤 SyntaxTokens 以降低噪声。作者还发现跨项目 API 用法高度重复,将 n-gram 限制在 Java API 后更明显;由于代码常由含控制/数据流的 AST 表示,n-gram 表征不佳,与统计图表示相比,图更重复且含更高层模式。作者建议未来关注能准确捕捉复杂编码模式的统计代码图模型,并公开复现包。

问题
既有“代码比英语文本更自然”的结论是否可靠,以及 n-gram 或统计图表示能否有效刻画代码中的重复与可预测模式。
方法
对 Java 语料进行 token 统计,按 NLP 方式去除分隔符和关键词,比较 API n-gram 与统计图表示对相同代码库的建模效果。
评估
基于 Java 语料和 Java API 的实证分析,衡量去除语法标记后的重复性与可预测性,并比较 n-gram 与图表示的重复性和高层模式覆盖。
原文摘要(Abstract)

Recent works have concluded that software code is more repetitive and predictable, i.e. more natural, than English texts. On re-examination, we find that much of the apparent "naturalness" of source code is due to the presence of language specific syntax, especially separators, such as semi-colons and brackets. For example, separators account for 44% of all tokens in our Java corpus. When we follow the NLP practices of eliminating punctuation (e.g., separators) and stopwords (e.g., keywords), we find that code is still repetitive and predictable, but to a lesser degree than previously thought. We suggest that SyntaxTokens be filtered to reduce noise in code recommenders. Unlike the code written for a particular project, API code usage is similar across projects: a file is opened and closed in the same manner regardless of domain. When we restrict our n-grams to those contained in the Java API, we find that API usages are highly repetitive. Since API calls are common across programs, researchers have made reliable statistical models to recommend sophisticated API call sequences. Sequential n-gram models were developed for natural languages. Code is usually represented by an AST which contains control and data flow, making n-grams models a poor representation of code. Comparing n-grams to statistical graph representations of the same codebase, we find that graphs are more repetitive and contain higherlevel patterns than n-grams. We suggest that future work focus on statistical code graphs models that accurately capture complex coding patterns. Our replication package makes our scripts and data available to future researchers[1].

链接与引用

DOI 原文 · DBLP

BibTeX
@inproceedings{RahmanPR19,
  title = {Natural Software Revisited},
  author = {Musfiqur Rahman and Dharani Palani and Peter C. Rigby},
  booktitle = {ICSE},
  year = {2019},
  doi = {10.1109/icse.2019.00022}
}