The common use case of code smells assumes causality: Identify a smell, remove it, and by doing so improve the code. We empirically investigate their fitness to this use. We present a list of properties that code smells should have if they indeed cause lower quality. We evaluated the smells in 31,687 Java files from 677 GitHub repositories, all the repositories with 200+ commits in 2019. We measured the influence of smells on four metrics for quality, productivity, and bug detection efficiency. Out of 151 code smells computed by the CheckStyle smell detector, less than 20% were found to be potentially causal, and only a handful are rather robust. The strongest smells deal with simplicity, defensive programming, and abstraction. Files without the potentially causal smells are 50% more likely to be of high quality. Unfortunately, most smells are not removed, and developers tend to remove the easy ones and not the effective ones.
翻译:摘要:代码坏味的常见用例假设因果关系:识别出坏味,移除它,从而改善代码。我们通过实证研究检验其对该用例的适用性。我们提出了代码坏味若要成为质量低下的诱因所应具备的特性列表。我们评估了来自677个GitHub仓库中31,687个Java文件的坏味,这些仓库均为2019年提交数超过200次的仓库。我们测量了坏味对质量、生产率和缺陷检测效率四项指标的影响。在CheckStyle坏味检测器计算的151种代码坏味中,不到20%被认定为潜在因果关系,且仅少数坏味表现稳健。最强的坏味涉及简洁性、防御性编程与抽象化。不含潜在因果坏味的文件高质量可能性高出50%。遗憾的是,大多数坏味未被移除,且开发者倾向于移除容易处理的坏味,而非真正有效的坏味。