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.
Understanding before Naming! Enhancing LLM-based Method Name Prediction with Code Summarization
Faculty of Data Science, City University of Macau(澳门城市大学数据科学学院);School of Cyberspace Security (School of Cryptography), Hainan University(海南大学网络空间安全学院(密码学院));College of Computing and Data Science, Nanyang Technological University(南洋理工大学计算机与数据科学学院);State Key Laboratory for Novel Software Technology, Nanjing University(南京大学软件新技术国家重点实验室)
University of Buenos Aires(布宜诺斯艾利斯大学);CONICET(阿根廷国家科学研究委员会);Kristiania University of Applied Sciences(克里斯蒂亚纳应用科学大学);Oslo Metropolitan University(奥斯陆都会大学);Volkswagen AG(大众汽车集团)