arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2209.01098cs.SE
收藏

开发人员如何提取函数:一个实验

How Developers Extract Functions: An Experiment

Alexey Braver, Dror G. Feitelson

摘要:

创建函数是编写计算机程序的核心。但是,关于如何做到这一点以及开发人员使用的考虑因素是什么,几乎没有实证研究。我们设计了一个实验,在这个实验中,我们可以比较多个开发人员在完全相同的条件下做出的决定。该实验基于现有的生产代码,将其“扁平化”为单个单片函数,然后让开发人员承担重构它的任务,以通过提取函数来实现更好的设计。结果表明,开发人员倾向于基于结构线索提取功能,例如“if”或“try”块。虽然不同开发人员执行的重构之间存在显著的相关性,但在重构的程度上也存在显著差异。例如,提取的函数数量在3到10之间,提取到函数中的代码量在37%到95%之间。

英文摘要:

Creating functions is at the center of writing computer programs. But there has been little empirical research on how this is done and what are the considerations that developers use. We design an experiment in which we can compare the decisions made by multiple developers under exactly the same conditions. The experiment is based on taking existing production code, "flattening" it into a single monolithic function, and then charging developers with the task of refactoring it to achieve a better design by extracting functions. The results indicate that developers tend to extract functions based on structural cues, such as 'if' or 'try' blocks. And while there are significant correlations between the refactorings performed by different developers, there are also significant differences in the magnitude of refactoring done. For example, the number of functions that were extracted was between 3 and 10, and the amount of code extracted into functions ranged from 37% to 95%.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑