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

Roee Cates, Nadav Yunik, D. Feitelson
{"title":"Does Code Structure Affect Comprehension? On Using and Naming Intermediate Variables","authors":"Roee Cates, Nadav Yunik, D. Feitelson","doi":"10.1109/ICPC52881.2021.00020","DOIUrl":null,"url":null,"abstract":"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.","PeriodicalId":288873,"journal":{"name":"2021 IEEE/ACM 29th International Conference on Program Comprehension (ICPC)","volume":"30 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2021-03-19","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"5","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"2021 IEEE/ACM 29th International Conference on Program Comprehension (ICPC)","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1109/ICPC52881.2021.00020","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 5

Abstract

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.
代码结构影响理解吗?关于中间变量的使用和命名
中间变量可用于将复杂的表达式分解为更易于管理的小表达式,这可能更容易理解。但目前尚不清楚这是否真的有帮助。我们做了一个实验,让实验对象阅读6个数学函数,并给它们起个有意义的名字。113名受试者参与,其中58%有3年或3年以上的编程工作经验。每个函数有3个版本:使用复合表达式,使用名称无意义的中间变量,或使用名称有意义的中间变量。结果是,只有在一种情况下,两个极端版本之间存在显著差异,支持具有有意义名称的中间变量。这个case是最难理解的函数。在另外两种情况下,使用具有无意义名称的中间变量似乎会导致理解能力略有下降。在所有其他情况下,代码结构并没有太大的区别。由于很难预测其他人会发现难以理解的内容,因此结论是使用中间变量通常是可取的。然而,这一建议取决于给他们起个好名字。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术官方微信
小红书