To refactor already working code while keeping reliability, compatibility and perhaps security, we can borrow ideas from micropass/nanopass compilers. By treating the procedure of software refactoring as composing code transformations, and compressing repetitive transformations with automation tools, we can often obtain representations of refactoring processes short enough that their correctness can be analysed manually. Unlike in compilers, in refactoring we usually only need to consider the codebase in question, so regular text processing can be extensively used, fully exploiting patterns only present in the codebase. Aside from the direct application of code transformations from compilers, many other kinds of equivalence properties may also be exploited. In this paper, two refactoring projects are given as the main examples, where 10-100 times simplification has been achieved with the application of a few kinds of useful transformations.
翻译:为了在保持可靠性、兼容性乃至安全性的前提下重构已有正常运行的代码,可借鉴微通道/纳通道编译器的设计理念。通过将软件重构过程视为代码变换的组合,并借助自动化工具压缩重复性变换,我们通常能获得足够简洁的重构过程表示,从而可对其进行人工正确性分析。与编译器不同,重构场景通常只需考虑特定代码库,因此可广泛运用常规文本处理技术,充分挖掘代码库中特有的模式。除直接应用编译器中的代码变换外,还可利用多种其他类型的等价性质。本文以两个重构项目作为主要案例,通过应用若干类实用的变换方法,实现了10-100倍的简化效果。