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 18 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 mistakes developers usually made during cycles' handling. These recurring patterns and common mistakes 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.
翻译:依赖循环对软件质量和可维护性构成重大挑战。然而,关于从业者如何在真实场景中解决依赖循环的理解仍十分有限。本文通过实证研究,探讨软件开发者在实际中用于解决两类间依赖循环的重复模式。我们分析了来自18个跨领域开源项目的数据,并手动检查了数百个循环解开案例。研究发现,开发者倾向于采用五种重复模式来处理依赖循环。所选模式不仅由循环类之间的依赖关系决定,更与其设计上下文高度相关——即循环类如何依赖或被其相邻类依赖。通过这项实证研究,我们还发现了开发者在处理循环时常犯的三类常见错误。这些在依赖循环实践中观察到的重复模式与常见错误可形成分类体系,用于提升开发者的认知,同时也可作为软件工程专业学生及经验不足开发者的学习材料。研究结果同时表明,自动工具在考虑依赖循环内部结构之外,还需结合循环的设计上下文,从而为重构依赖循环提供更优支持。