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个开源项目数据,并手动审查了数百个循环解缠案例。研究发现,开发者倾向于采用五种重复模式来处理依赖循环。所选模式不仅受循环类之间依赖关系的影响,还与它们的设计上下文高度相关,即循环类如何依赖或被其相邻类依赖。通过这项实证研究,我们还发现了开发者在处理循环时通常采用的三种常见反直觉解决方案。这些在依赖循环实践中观察到的重复模式和常见反直觉解决方案,可作为分类法提升开发者的认知意识,同时也可作为软件工程学生和经验不足开发者的学习材料。我们的结果还表明,除了考虑依赖循环的内部结构外,自动工具还需考虑循环的设计上下文,以便为重构依赖循环提供更好的支持。