arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2607.02744cs.SE
收藏

将软件设计模式应用于后端Rust应用程序的好处

Benefits of Applying Software Design Patterns to Backend Rust Applications

NORDAKADEMIE Hochschule der Wirtschaft(诺达卡德米经济高等学校);Otto GmbH & Co. KGaA(奥托有限公司)

Leon Heuer

AI总结:

通过对生产后端应用三个代表性组件的案例研究,探讨模式对软件质量和不变量编译时强制的影响,开发评估框架,应用模式改进代码,为Rust中设计模式研究奠定基础。

摘要:

软件设计模式对代码质量的影响大多在面向对象语言背景下研究。在具有新颖语言概念、编译时安全保证和独特类型系统的Rust编程语言中,对设计模式的研究很少。本文通过对生产后端应用的三个代表性组件进行案例研究,调查模式如何影响软件质量和不变量的编译时强制。开发了一个基于从SQuaRE质量模型派生的标准的评估框架,包括基准测试、静态代码分析和专家访谈,以评估重构后的代码。应用类型状态和新类型模式来解决所选用例中现有的代码异味。虽然类型状态模式显著提高了无故障性和可测试性,但代价是更多的结构化代码可能会降低可读性。具有广泛分支逻辑和大量不变量的代码可能从该模式中受益最大。新类型模式与“解析,不验证”原则相结合,以低成本在软件质量方面提供高回报,并在运行时防止无效状态。总体而言,这项工作为Rust中的设计模式提供了初步的实证评估,并为涉及更多用例和模式的进一步研究奠定了基础。

英文摘要:

Software design patterns' effects on code quality have mostly been studied in the context of object-oriented languages. In the programming language Rust, which comes with novel language concepts, compile-time safety guarantees and a distinct type system, there has been little research on design patterns. This work investigates how patterns affect software quality and compile-time enforcement of invariants through a case study on three representative components of production backend applications. An evaluation framework based on criteria derived from the SQuaRE quality model, incorporating benchmarking, static code analysis and expert interviews, is developed to assess the refactored code. The patterns typestate and newtype are applied to address existing code smells in the selected use cases. While the typestate pattern improves faultlessness and testability significantly, it comes at the cost of more structural code that can degrade readability. Code with extensive branching logic and a high number of invariants is likely to benefit most from the pattern. The newtype pattern combined with the "Parse, don't validate" principle offers high returns in software quality at a low cost and prevents invalid states during runtime. Overall, this work provides an initial empirical assessment of design patterns in Rust and establishes a foundation for further studies involving additional use cases and patterns.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑