一句话:复现命名选择研究,发现学生命名随年级变长且存在歧义,已有方法可提升超 67% 案例的命名质量。
类、方法和变量命名对代码可读性有重要影响。Feitelson 等人曾通过实证调查研究开发者如何选择命名,并提出一种改进命名质量的方法。本文对该研究进行重复,但将调查对象限定为大学生。具体而言,作者开展了两个实验,共涉及 341 名大一至大四学生。第一个实验考察学生所给名称的特征,结果显示名称长度和包含的词数随年级升高而增加,且学生对变量名存在理解歧义。第二个实验验证 Feitelson 等人的命名方法能否帮助学生提升命名质量,结果显示超过 67% 的案例中命名质量得到改善,从而确认该方法对大学生群体有效。
Names of classes/methods/variables play an important role in code readability. To investigate how developers choose names, Feitelson et al. conducted an empirical survey and suggested a method to improve naming quality. We replicated their study, but limited the survey subjects to university students. Specifically, we conducted two experiments including 341 students from freshmen to seniors. The aim of the first experiment was to investigate the characteristics of the names given by students. The experimental results showed that the name length as well as the number of words contained in names increased with the grade and students have ambiguity in understanding variable names. The second experiment was to verify whether Feitelson et al.’s naming method can help improve the quality of the names given by students. The experimental results showed an improvement in naming quality for more than 67% of cases, which confirms the validity of the method for university students.