Discipline Matters: Refactoring of Preprocessor Directives in the # ifdef Hell

Discipline Matters: Refactoring of Preprocessor Directives in the # ifdef Hell
复制标题

DOI:
10.1109/tse.2017.2688333
复制
发表时间:
2018-05-01
影响因子:
7.4
通讯作者:
Fonseca, Baldoino
Fonseca, Baldoino
中科院分区:
计算机科学1区
文献类型:
--
作者:
Medeiros, Favio;Ribeiro, Marcio;Fonseca, Baldoino

文献摘要

被引文献

相似文献

C预处理器在许多C项目中使用,以支持可变性和可移植性。然而,研究人员和实践者批评C预处理器,因为它对代码理解和可维护性的负面影响以及它的错误倾向。更重要的是,预处理器的使用阻碍了其他语言中标准的工具支持的开发,比如自动重构。当开发人员以不规范的方式使用预处理器时,这些问题会加剧(例如,不与代码的语法结构对齐的条件块)。在这篇文章中,我们提出了一个目录的重构和我们评估的重构在实践中的应用可能性的数量,开发人员的意见重构的有用性,以及重构是否保留行为。总的来说,我们在63个真实的C项目中发现了5,670个重构应用的可能性。此外,我们在246名开发人员中进行了在线调查,并提交了28个补丁,以将无纪律的指令转换为有纪律的指令。根据我们的结果,63%的开发人员更喜欢使用重构(即,规范的)版本的代码,而不是原始代码与无规范的预处理器的使用。为了验证重构确实是行为保留的,我们将它们应用于使用C语言子集的模型自动生成的36000多个程序,在原始程序和重构程序中运行相同的测试用例。此外,我们将重构应用于三个真实世界的项目:BusyBox,OpenSSL和SQLite。通过这种方式,我们检测并修复了一些行为更改,其中62%是由C编程语言中的未指定行为引起的。
The C preprocessor is used in many C projects to support variability and portability. However, researchers and practitioners criticize the C preprocessor because of its negative effect on code understanding and maintainability and its error proneness. More importantly, the use of the preprocessor hinders the development of tool support that is standard in other languages, such as automated refactoring. Developers aggravate these problems when using the preprocessor in undisciplined ways (e.g., conditional blocks that do not align with the syntactic structure of the code). In this article, we proposed a catalogue of refactorings and we evaluated the number of application possibilities of the refactorings in practice, the opinion of developers about the usefulness of the refactorings, and whether the refactorings preserve behavior. Overall, we found 5,670 application possibilities for the refactorings in 63 real-world C projects. In addition, we performed an online survey among 246 developers, and we submitted 28 patches to convert undisciplined directives into disciplined ones. According to our results, 63 percent of developers prefer to use the refactored (i.e., disciplined) version of the code instead of the original code with undisciplined preprocessor usage. To verify that the refactorings are indeed behavior preserving, we applied them to more than 36 thousand programs generated automatically using a model of a subset of the C language, running the same test cases in the original and refactored programs. Furthermore, we applied the refactorings to three real-world projects: BusyBox, OpenSSL, and SQLite. This way, we detected and fixed a few behavioral changes, 62 percent caused by unspecified behavior in the C programming language.