The names of variables and functions serve as implicit documentation and are instrumental for program comprehension. But choosing good meaningful names is hard. We perform a sequence of experiments in which a total of 334 subjects are required to choose names in given programming scenarios. The first experiment shows that the probability that two developers would select the same name is low: in the 47 instances in our experiments the median probability was only 6.9%. At the same time, given that a specific name is chosen, it is usually understood by the majority of developers. Analysis of the names given in the experiment suggests a model where naming is a (not necessarily cognizant or serial) three-step process: (1) selecting the concepts to include in the name, (2) choosing the words to represent each concept, and (3) constructing a name using these words. A followup experiment, using the same experimental setup, then checked whether using this model explicitly can improve the quality of names. The results were that names selected by subjects using the model were judged by two independent judges to be superior to names chosen in the original experiment by a ratio of two-to-one. Using the model appears to encourage the use of more concepts and longer names.
翻译:变量和函数的名称是隐含的文档,有助于程序理解。 但是选择有意义的好名称很难。 我们进行一系列实验, 总共需要334个对象在特定编程情景中选择名称。 第一个实验显示, 两位开发者选择相同名称的概率很低: 在我们的实验中的47个例子中, 中位概率仅为6.9%。 同时, 由于选择了特定名称, 它通常为大多数开发者所理解。 对实验中给出的名称的分析表明, 命名是一个( 不一定知道或序列) 三步过程的模型:(1) 选择要包含在名称中的概念, (2) 选择代表每个概念的词, (3) 使用这些词构建名称。 后续实验, 使用同样的实验设置, 然后检查使用这个模型是否明确可以提高名称的质量。 结果是, 两位独立法官对使用模型选择的名称的评分优于最初实验中选择的名称, 比例为二比一。 使用模型似乎鼓励使用更多概念和更长的名称。