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

被引:28
|
作者
Medeiros, Favio [1 ,2 ]
Ribeiro, Marcio [3 ]
Gheyi, Rohit [2 ]
Apel, Sven [4 ]
Kstner, Christian [5 ]
Ferreira, Bruno [3 ]
Carvalho, Luiz [3 ]
Fonseca, Baldoino [3 ]
机构
[1] Fed Inst Alagoas, BR-57020600 Maceio, AL, Brazil
[2] Univ Fed Campina Grande, Dept Comp & Syst, BR-58429900 Campina Grande, PB, Brazil
[3] Univ Fed Alagoas, Comp Inst, BR-57072900 Maceio, AL, Brazil
[4] Univ Passau, Dept Informat & Math, D-94032 Passau, Germany
[5] Carnegie Mellon Univ, Sch Comp Sci, Inst Software Res, Pittsburgh, PA 15213 USA
关键词
Configurable systems; preprocessors; refactoring; C PREPROCESSOR; CODE;
D O I
10.1109/TSE.2017.2688333
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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.
引用
收藏
页码:453 / 469
页数:17
相关论文
共 37 条
  • [1] The Discipline of Preprocessor-Based Annotations Does #ifdef TAG n't #endif Matter
    Malaquias, Romero
    Ribeiro, Marcio
    Bonifacio, Rodrigo
    Monteiro, Eduardo
    Medeiros, Flavio
    Garcia, Alessandro
    Gheyi, Rohit
    [J]. 2017 IEEE/ACM 25TH INTERNATIONAL CONFERENCE ON PROGRAM COMPREHENSION (ICPC), 2017, : 297 - 307
  • [2] Patterns to Escape the #ifdef Hell
    Preschern, Christopher
    [J]. PROCEEDINGS OF THE 24TH EUROPEAN CONFERENCE ON PATTERN LANGUAGES OF PROGRAMS (EUROPLOP 2019), 2019,
  • [3] Refactoring browser with preprocessor
    Vittek, M
    [J]. SEVENTH EUROPEAN CONFERENCE ON SOFTWARE MAINTENANCE AND REENGINEERING, PROCEEDINGS, 2003, : 101 - 110
  • [4] Embracing the C preprocessor during refactoring
    Garrido, Alejandra
    Johnson, Ralph
    [J]. JOURNAL OF SOFTWARE-EVOLUTION AND PROCESS, 2013, 25 (12) : 1285 - 1304
  • [5] Do background colors improve program comprehension in the #ifdef hell?
    Feigenspan, Janet
    Kaestner, Christian
    Apel, Sven
    Liebig, Joerg
    Schulze, Michael
    Dachselt, Raimund
    Papendieck, Maria
    Leich, Thomas
    Saake, Gunter
    [J]. EMPIRICAL SOFTWARE ENGINEERING, 2013, 18 (04) : 699 - 745
  • [6] #ifdef Directives and Program Comprehension: The Dilemma between Correctness and Preference
    Fenske, Wolfram
    Krueger, Jacob
    Kanyshkova, Maria
    Schulze, Sandro
    [J]. 2020 IEEE INTERNATIONAL CONFERENCE ON SOFTWARE MAINTENANCE AND EVOLUTION (ICSME 2020), 2020, : 255 - 266
  • [7] Do background colors improve program comprehension in the #ifdef hell?
    Janet Feigenspan
    Christian Kästner
    Sven Apel
    Jörg Liebig
    Michael Schulze
    Raimund Dachselt
    Maria Papendieck
    Thomas Leich
    Gunter Saake
    [J]. Empirical Software Engineering, 2013, 18 : 699 - 745
  • [8] Discipline matters
    McCourt, J
    [J]. PSYCHOLOGIST, 2003, 16 (08) : 426 - 427
  • [9] REFACTORING OF C/C plus plus PREPROCESSOR CONSTRUCTS AT THE MODEL LEVEL
    Vidacs, Laszlo
    [J]. ICSOFT 2009: PROCEEDINGS OF THE 4TH INTERNATIONAL CONFERENCE ON SOFTWARE AND DATA TECHNOLOGIES, VOL 1, 2009, : 232 - 237
  • [10] Green Information Systems: Directives for the IS Discipline
    vom Brocke, Jan
    Watson, Richard T.
    Dwyer, Cathy
    Elliot, Steve
    Melville, Nigel
    [J]. COMMUNICATIONS OF THE ASSOCIATION FOR INFORMATION SYSTEMS, 2013, 33 : 509 - 520