Dependency cycles pose a significant challenge to software quality and maintainability. However, there is limited understanding of how practitioners resolve dependency cycles in real-world scenarios. This paper presents an empirical study investigating the recurring patterns employed by software developers to resolve dependency cycles between two classes in practice. We analyzed the data from 38 open-source projects across different domains and manually inspected hundreds of cycle untangling cases. Our findings reveal that developers tend to employ five recurring patterns to address dependency cycles. The chosen patterns are not only determined by dependency relations between cyclic classes, but also highly related to their design context, i.e., how cyclic classes depend on or are depended by their neighbor classes. Through this empirical study, we also discovered three common counterintuitive solutions developers usually adopted during cycles' handling. These recurring patterns and common counterintuitive solutions observed in dependency cycles' practice can serve as a taxonomy to improve developers' awareness and also be used as learning materials for students in software engineering and inexperienced developers. Our results also suggest that, in addition to considering the internal structure of dependency cycles, automatic tools need to consider the design context of cycles to provide better support for refactoring dependency cycles.
翻译:依赖环对软件质量和可维护性构成重大挑战。然而,目前对实践者在真实场景中如何解决依赖环的理解仍然有限。本文通过实证研究,探究软件开发者在实践中用于解决两个类之间依赖环的重复模式。我们分析了来自不同领域的38个开源项目的数据,并手动检查了数百个依赖环解缠案例。研究结果表明,开发者倾向于采用五种重复模式来解决依赖环。所选模式不仅由循环类之间的依赖关系决定,还与其设计上下文高度相关,即循环类如何依赖于其邻居类或被其邻居类依赖。通过这一实证研究,我们还发现了开发者在处理依赖环过程中通常采用的三种常见反直觉解决方案。这些在依赖环实践中观察到的重复模式和常见反直觉解决方案可以作为分类法,提升开发者的认识水平,并可作为软件工程学生和经验不足的开发者的学习材料。我们的结果还表明,除了考虑依赖环的内部结构外,自动工具还需要考虑依赖环的设计上下文,以更好地支持依赖环的重构。