SEMar 19, 2021

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

arXiv:2103.11008v111 citations
Originality Synthesis-oriented
AI Analysis

This addresses a practical problem for programmers and educators by clarifying when code structuring aids comprehension, though the findings are incremental.

The study investigated whether using intermediate variables with meaningful names improves code comprehension, finding a significant benefit only for the hardest function, while meaningless names sometimes decreased understanding.

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.

Foundations

The foundational work for this paper's niche, ranked by how specifically the neighbourhood builds on it — not by global fame.

Your Notes