arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2103.11008cs.SE
收藏

代码结构影响理解吗?关于中间变量的使用和排除

Does Code Structure Affect Comprehension? On Using and Naming Intermediate Variables

Roee Cates, Nadav Yunik, Dror G. Feitelson

摘要:

中间变量可用于将复杂的表达式分解为更易于管理的较小表达式,这可能更容易理解。但尚不清楚何时以及是否真的有帮助。我们进行了一项实验,让受试者阅读6个数学函数,并给它们起一个有意义的名字。113名受试者参与,其中58%有3年或3年以上的编程工作经验。每个函数都有3个版本:使用复合表达式,使用无意义名称的中间变量,或使用有意义名称的中间变量。结果是,只有在一种情况下,两个极端版本之间存在显着差异,有利于中间变量具有有意义的名称的版本。这个案子,本来就是最难理解的一个功能。在另外两种情况下,使用中间变量和无意义的名称似乎导致了理解的轻微下降。在所有其他情况下,代码结构没有太大的区别。由于很难预测其他人会发现什么难以理解,因此结论是使用中间变量通常是可取的。然而,这一建议取决于给它们起好名字。

英文摘要:

Intermediate variables can be used to break complex expressions into more manageable smaller expressions, which may be easier to understand. But it is unclear when and whether this actually helps. We conducted an experiment in which subjects read 6 mathematical functions and were supposed to give them meaningful names. 113 subjects participated, of which 58% had 3 or more years of programming work experience. Each function had 3 versions: using a compound expression, using intermediate variables with meaningless names, or using intermediate variables with meaningful names. The results were that in only one case there was a significant difference between the two extreme versions, in favor of the one with intermediate variables with meaningful names. This case was the function that was the hardest to understand to begin with. In two additional cases using intermediate variables with meaningless names appears to have caused a slight decrease in understanding. In all other cases the code structure did not make much of a difference. As it is hard to anticipate what others will find difficult to understand, the conclusion is that using intermediate variables is generally desirable. However, this recommendation hinges on giving them good names.

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

↑