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

Roee Cates, Nadav Yunik, Dror G. Feitelson

Research output: Chapter in Book/Report/Conference proceedingConference contributionpeer-review

4 Scopus citations

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.

Original languageAmerican English
Title of host publicationProceedings - 2021 IEEE/ACM 29th International Conference on Program Comprehension, ICPC 2021
PublisherIEEE Computer Society
Pages118-126
Number of pages9
ISBN (Electronic)9781665414036
DOIs
StatePublished - May 2021
Event29th IEEE/ACM International Conference on Program Comprehension, ICPC 2021 - Virtual, Online
Duration: 20 May 202121 May 2021

Publication series

NameIEEE International Conference on Program Comprehension
Volume2021-May

Conference

Conference29th IEEE/ACM International Conference on Program Comprehension, ICPC 2021
CityVirtual, Online
Period20/05/2121/05/21

Bibliographical note

Publisher Copyright:
© 2021 IEEE.

Keywords

  • Code comprehension
  • extract variable
  • inline variable

Fingerprint

Dive into the research topics of 'Does Code Structure Affect Comprehension? On Using and Naming Intermediate Variables'. Together they form a unique fingerprint.

Cite this