可变性对Java中圈复杂度的影响
The Impact of Mutability on Cyclomatic Complexity in Java
AI总结:
研究分析了1,000个GitHub仓库的862,446个Java文件,发现不可变对象的McCabe圈复杂度比可变对象低近三倍,表明增加不可变类可降低代码库整体复杂度与可维护性。
摘要:
在Java中,一些对象属性是可变的,而另一些是不可变的(带有“final”修饰符)。具有至少一个可变属性的对象可称为“可变”对象。我们怀疑可变对象的McCabe圈复杂度(CC)高于不可变对象。为验证这一直觉,我们分析了来自1,000个开放GitHub仓库的862,446个Java文件。结果表明,不可变对象的复杂度比可变对象低近三倍。因此可以假设,使用更多不可变类能降低代码库的整体复杂度与可维护性。
英文摘要:
In Java, some object attributes are mutable, while others are immutable (with the "final" modifier attached to them). Objects that have at least one mutable attribute may be referred to as "mutable" objects. We suspect that mutable objects have higher McCabe's Cyclomatic Complexity (CC) than immutable ones. To validate this intuition, we analysed 862,446 Java files from 1,000 open-GitHub repositories. Our results demonstrated that immutable objects are almost three times less complex than mutable ones. It can be therefore assumed that using more immutable classes could reduce the overall complexity and maintainability of the code base.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。