Before implementing a function, programmers are encouraged to write a purpose statement i.e., a short, natural-language explanation of what the function computes. A purpose statement may be ambiguous i.e., it may fail to specify the intended behaviour when two or more inequivalent computations are plausible on certain inputs. Our paper makes four contributions. First, we propose a novel heuristic that suggests such inputs using Large Language Models (LLMs). Using these suggestions, the programmer may choose to clarify the purpose statement (e.g., by providing a functional example that specifies the intended behaviour on such an input). Second, to assess the quality of inputs suggested by our heuristic, and to facilitate future research, we create an open dataset of purpose statements with known ambiguities. Third, we compare our heuristic against GitHub Copilot's Chat feature, which can suggest similar inputs when prompted to generate unit tests. Fourth, we provide an open-source implementation of our heuristic as an extension to Visual Studio Code for the Python programming language, where purpose statements and functional examples are specified as docstrings and doctests respectively. We believe that this tool will be particularly helpful to novice programmers and instructors.
翻译:在实现函数之前,程序员被鼓励编写目的陈述,即对函数计算内容的简短自然语言解释。当某些输入存在两种或更多不等价计算均属合理时,目的陈述可能存在歧义,即未能明确指定预期行为。本文做出四项贡献:首先,我们提出一种利用大型语言模型(LLM)生成此类输入的新启发式方法。通过使用这些建议,程序员可以选择澄清目的陈述(例如,提供指定该输入下预期行为的函数示例)。其次,为评估启发式方法生成的输入质量并促进未来研究,我们创建了一个包含已知歧义目的陈述的开放数据集。第三,我们将该启发式方法与GitHub Copilot的对话功能进行对比——该功能在提示生成单元测试时可提供类似输入。第四,我们为Python编程语言提供了基于Visual Studio Code扩展的开源实现,其中目的陈述和函数示例分别以文档字符串和文档测试的形式指定。我们相信该工具将对新手程序员和教育工作者特别有帮助。