Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article

Refactoring to Standard C++20 Modules

Published: 28 November 2024 Publication History

Abstract

Good component‐based design for software projects is a desired property both for development and maintenance. The C++ programming language inherited the “translation unit” model from C, where every source file is individually compiled with no knowledge about other parts of the project. This model has several drawbacks, and C++20 Modules is the Standard's answer for them. Moreover, Modules allows a cleaner encapsulation of concern. This paper investigates a semi‐automatic modularization method to refactor existing C++ projects. Our approach uses dependency analysis and clustering to organize elements of an existing project into modules, without domain‐specific information. Based on our study of two medium‐size open‐source projects from disjoint domains and vastly distinct architecture, upgrading existing software systems to the new Modules feature is limited by the existing design of the project's architecture. To fully facilitate the use of Modules in a project, it is likely that both project‐internal and user‐facing interfaces must be changed.

Graphical Abstract

This paper investigates a semi‐automatic modularization method to refactor existing C++ projects. Our approach uses dependency analysis and clustering to organize elements of projects into modules, without domain‐specific information. To fully facilitate the use of Modules, it is likely that both project‐internal and user‐facing interfaces must be changed.

References

[1]
V. Bauer, J. Eckhardt, B. Hauptmann, and M. Klimek, “An Exploratory Study on Reuse at Google,” in Proceedings of the 1st international workshop on software engineering research and industrial practices (New York, NY, USA: Association for Computing Machinery, 2014), 14–23, https://doi.org/10.1145/2593850.2593854.
[2]
N. Mäkitalo, A. Taivalsaari, A. Kiviluoto, T. Mikkonen, and R. Capilla, “On Opportunistic Software Reuse,” Computing 102, no. 11 (2020): 2385–2408.
[3]
T. Brunner and Z. Porkoláb, “Programming Language History: Experiences Based on the Evolution of C++,” in Proceedings of the 10th International Conference on Applied Informatics (Eger, Hungary: Eszterházy Károly University, 2018), 63–71, http://icai.uni‐eszterhazy.hu/icai2017/uploads/papers/2017/final/ICAI.10.2017.63.pdf.
[4]
B. A. Malloy and J. F. Power, “Quantifying the Transition From Python 2 to 3: An Empirical Study of Python Applications (IEEE, 2017), 314–323, https://doi.org/10.1109/ESEM.2017.45.
[5]
R. Szalay and Z. Porkoláb, “Semi‐Automatic Refactoring to C++20 Modules: A Semi‐Success Story,” in 2022 IEEE 22nd International Working Conference on Source Code Analysis and Manipulation (SCAM) (2022), 45–55, http://ieeexplore.ieee.org/document/10006851.
[6]
K. Martin and B. Hoffman, Mastering CMake: A Cross‐Platform Build System, 3.1 (Kitware Inc., 2015), http://cmake.org/cmake/help/book/mastering‐cmake/index.html.
[7]
ISO/IEC JTC 1/SC 22, Phases of Translation (Geneva, Switzerland: International Organization for Standardization, 2017), [lex.phases], http://iso.org/standard/68564.html.
[8]
The LLVM Project, “The ClangD Language Server,” (2020), accessed February 18, 2019, http://clangd.llvm.org.
[9]
Z. Porkoláb, T. Brunner, D. Krupp, and M. Csordás, “CodeCompass: An Open Software Comprehension Framework for Industrial Usage,” in Proceedings of the 26th Conference on Program Comprehension, ICPC 2018, eds. F. Khomh, C. K. Roy, and J. Siegmund (Gothenburg, Sweden: ACM, 2018), 361–369, https://doi.org/10.1145/3196321.3197546.
[10]
I. JetBrains, “CLion Refactoring,” (2020), accessed February 18, 2023, http://jetbrains.com/help/clion/refactoring‐source‐code.html.
[11]
G. Horváth, P. Szécsi, Z. Gera, D. Krupp, and N. Pataki, “Challenges of Implementing Cross Translation Unit Analysis in Clang Static Analyzer,” in 2018 IEEE 18th International Working Conference on Source Code Analysis and Manipulation (SCAM) (2018), 171–176, http://ieeexplore.ieee.org/document/8530731.
[12]
ISO/IEC JTC 1/SC 22, “IEC14882:2017 Information Technology ‐ Programming languages ‐ C++, version 17 (C++17), ch. 6.2: [basic.def.odr] One‐Definition Rule” (Geneva, Switzerland: International Organization for Standardization, 2017), http://iso.org/standard/68564.html.
[13]
B. Stroustrup, “N1614 – #scope: A Simple Scoping Mechanism for the C/C++ Preprocessor,” tech. rep. ISO/IEC JTC 1/SC 22/WG 21 ‐ Programming language “C++” – Open Papers, (2004), http://open‐std.org/jtc1/sc22/wg21/docs/papers/2004/n1614.pdf.
[14]
C. O'Donell and M. Sebor, “N1967 – Field Experience With Annex k – Bounds Checking Interfaces,” tech. rep. ISO/IEC JTC 1/SC 22/WG 14 ‐ Programming Languages “C”, (2015), http://open‐std.org/jtc1/sc22/wg14/www/docs/n1967.htm.
[15]
G. Márton and Z. Porkoláb, “Selective Friends in C++,” Software: Practice and Experience 48, no. 8 (2018): 1493–1519, http://onlinelibrary.wiley.com/doi/abs/10.1002/spe.2587.
[16]
G. Márton and Z. Porkoláb, “Unit Testing in C++ With Compiler Instrumentation and friends,” Acta Cybernetica 23, no. 2 (2017): 659–686, http://cyber.bibl.u‐szeged.hu/index.php/actcybern/article/view/3947.
[17]
D. van de Voorde, N. M. Josuttis, and D. Gregor, C++ Templates: The Complete Guide, 2nd ed. (Addison‐Wesley Professional, 2017), http://tmplbook.com.
[18]
T. H. Cormen, C. E. Leiserson, R. L. Rivest, and C. Stein, Introduction to Algorithms, 3rd Edition (MIT Press, 2009), http://mitpress.mit.edu/books/introduction‐algorithms.
[19]
D. van de Voorde, “N3347 – Modules in C++,” tech. rep. ISO/IEC JTC 1/SC 22/WG 21 ‐ Programming language “C++” – Open Papers, (2012), http://open‐std.org/jtc1/sc22/wg21/docs/papers/2012/n3347.pdf.
[20]
R. Smith, “P1103R3 – Merging Modules,” Tech. Rep. 3. ISO/IEC JTC 1/SC 22/WG 21 ‐ Programming language “C++” – Papers Mailing List, (2019), http://open‐std.org/jtc1/sc22/wg21/docs/papers/2019/p1103r3.pdf.
[21]
I. JetBrains, “C++ Programming – The State of the Developer Ecosystem in 2022,” (2022), accessed February 19, 2023, http://jetbrains.com/lp/devecosystem‐2022/cpp/.
[22]
B. Hoffman, B. Boeckel, and B. King, “import CMake; C++20 Modules,” (2023), accessed February 19, 2023, http://kitware.com/import‐cmake‐c20‐modules/.
[23]
G. Horváth, R. N. Kovács, and P. Szécsi, “Report on the Differential Testing of Static Analyzers,” Acta Cybernetica 25, no. 4 (2020): 781–795, http://cyber.bibl.u‐szeged.hu/index.php/actcybern/article/view/4099.
[24]
B. A. Lelbach, “What Belongs in the C++ Standard Library?,” (2021), accessed July 29, 2022, http://youtube.com/watch?v=OgM0MYb4DqE.
[25]
M. Klimek, “Deploying C++ Modules to 100s of Millions of Lines of Code,” in CppCon ‐ The C++ Conference, (Bellevue, Washington, United States of America, 2016), accessed March 1, 2019, http://youtube.com/watch?v=dHFNpBfemDI (the quoted sentence is said at 38:50 minutes).
[26]
R. Szalay, Z. Porkoláb, and D. Krupp, “Measuring Mangled Name Ambiguity in Large C/C++ Projects,” in 6th Workshop on Software Quality Analysis, Monitoring, Improvement, and Applications, eds. Z. Budimac, CEUR Workshop Proceedings, Vol. 1938 (Belgrade, Serbia: CEUR‐WS.org, 2017), http://ceur‐ws.org/Vol‐1938/paper‐sza.pdf.
[27]
R. Szalay, Z. Porkoláb, and D. Krupp, “Towards Better Symbol Resolution for C/C++ Programs: A Cluster‐Based Solution,” in 17th IEEE International Working Conference on Source Code Analysis and Manipulation (Shanghai, China: IEEE Computer Society, 2017), 101–110, https://doi.org/10.1109/SCAM.2017.15.
[28]
R. Szalay, Á. Sinkovics, and Z. Porkoláb, “Practical Heuristics to Improve Precision For Erroneous Function Argument Swapping Detection in c and C++,” Journal of Systems and Software 181 (2021): 111048, http://sciencedirect.com/science/article/pii/S016412122100145X.
[29]
J. Mihalicza, “Analysis and Methods for Supporting Generative Metaprogramming in Large Scale C++ Projects” (PhD Dissertation, Eötvös Loránd University, Doctorol School of the Faculty of Informatics, 2014), http://edit.elte.hu/xmlui/handle/10831/39565.
[30]
S. Lapierre, B. Laguë, and C. Leduc, “Datrix™ Source Code Model and its Interchange Format: Lessons Learned and Considerations for Future Work,” ACM SIGSOFT Software Engineering Notes 26, no. 1 (2001): 53–56.
[31]
R. Ferenc, A. Beszédes, M. Tarkiainen, and T. Gyimóthy, “Columbus ‐ Reverse Engineering Tool and Schema for C++,” in 18th International Conference on Software Maintenance (ICSM 2002) (Montreal, Quebec, Canada: IEEE Computer Society, 2002), 172–181, https://doi.org/10.1109/ICSM.2002.1167764.
[32]
The LLVM Project, “Clang: C Language Family Frontend for LLVM,” (2003), accessed August 13, 2018, http://clang.llvm.org.
[33]
E. B. Duffy, B. A. Malloy, and S. Schaub, “Exploiting the Clang AST for Analysis of C++ Applications,” in Proceedings of the 52nd Annual ACM Southeast Conference (South Carolina, USA: Clemson University, 2014), http://people.cs.clemson.edu/∼malloy/publications/papers/2014/acmse2014.pdf.
[34]
H. K. Wright, D. Jasper, M. Klimek, C. Carruth, and Z. Wan, “Large‐Scale Automated Refactoring Using Clangmr,” in 2013 IEEE International Conference on Software Maintenance (ICSM) (2013), 548–551, http://ieeexplore.ieee.org/document/6676954.
[35]
H. Sutter, Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions (Boston, MA, USA: Addison‐Wesley Longman Publishing Co., Inc., 2000), http://gotw.ca/publications/xc++.htm.
[36]
G. B. Dantzig and D. R. Fulkerson, “On the Max‐Flow Min‐Cut Theorem of Networks,” in Linear Inequalities and Related Systems. (am‐38), volume 38 (Princeton University Press, 1957), 215–222, https://doi.org/10.1515/9781400881987-013.
[37]
Various open‐source authors, “NetworkX,” (2014), accessed March 8, 2019, http://networkx.github.io.
[38]
D. B. Johnson, “Finding all the Elementary Circuits of a Directed Graph,” SIAM Journal on Computing 4, no. 1 (1975): 77–84, http://epubs.siam.org/doi/abs/10.1137/0204007.
[39]
The Apache Foundation, “Xerces‐C – Validating xml Parser: A Processor for Parsing, Validating, Serializing and Manipulating xml,” (1999), accessed March 8, 2019, http://xerces.apache.org and http://github.com/apache/xerces‐c.
[40]
A. B. Ericsson, “CodeCompass is a Software Comprehension Tool for Large‐Scale Software Written in C/C++ and Java,” http://codecompass.net and accessed March 16, 2022, http://github.com/Ericsson/CodeCompass.
[41]
Z. Porkoláb and T. Brunner, “The CodeCompass Comprehension Framework,” in Proceedings of the 26th Conference on Program Comprehension (ICPC), ICPC '18 (New York, NY, USA: Association for Computing Machinery, 2018), 393–396, http://dl.acm.org/doi/10.1145/3196321.3196352.
[42]
B. Kolpackov and CodeSynthesis, “ODB: C++ Object‐Relational Mapping (ORM),” accessed March 17, 2019, http://codesynthesis.com/products/odb.
[43]
R. Abernethy, Programmer's Guide to Apache Thrift, 1st ed. (Manning, 2019), http://manning.com/books/programmers‐guide‐to‐apache‐thrift.
[44]
N. Hawes, S. Marshall, and C. Anslow, “CodeSurveyor: Mapping Large‐Scale Software to Aid in Code Comprehension,” in 2015 IEEE 3rd Working Conference on Software Visualization (VISSOFT) (2015), 96–105, http://ieeexplore.ieee.org/document/7332419.
[45]
A. Fekete, M. Cserép, and Z. Porkoláb, “Measuring Developers' Expertise Based on Version Control Data,” in 2021 44th International Convention on Information, Communication and Electronic Technology (MIPRO) (2021), 1607–1612, http://ieeexplore.ieee.org/document/9597103.
[46]
Z. Gutterman, B. Pinkas, and T. Reinman, “Analysis of the Linux Random Number Generator,” in 2006 IEEE Symposium on Security and Privacy (S&P'06) (2006), 15, http://ieeexplore.ieee.org/document/1624027.
[47]
J. Mihalicza, “How #includes Affect Build Time in Large Systems,” in Proceedings of the 8th International Conference on Applied Informatics (ICAI), eds. A. Egri‐Nagy, E. Kovács, G. Kovásznai, G. Kusper, and T. Tómács, 8, Vol. 2 (Eger, Hungary: BVB Nyomda és Kiadó Kft., 2010), 343–350, http://icai.ektf.hu/pdf/ICAI2010‐vol2‐pp343‐350.pdf.
[48]
A. Kovács and K. Szabados, “Internal Quality Evolution of a Large Test System – An Industrial Study,” Acta Universitatis Sapientiae, Informatica 8, no. 2 (2016): 216–240, https://doi.org/10.1515/ausi-2016-0010.
[49]
The LLVM Project, “Include‐What‐You‐Use,” (2011), accessed February 28, 2019, http://github.com/include‐what‐you‐use/include‐what‐you‐use.
[50]
A. Lorencz, “RFC: Prototype of clang‐scan‐deps, Faster Dependency Scanning Tool for Explicit Modules and clangd,” (2018), accessed March 6, 2019, http://lists.llvm.org/pipermail/cfe‐dev/2018‐October/059831.html.
[51]
B. Kolpackov, “Complete C++20 Modules Support With GCC,” (2021), accessed April 17, 2022, http://build2.org/blog/build2‐cxx20‐modules‐gcc.xhtml.
[52]
Y. Takahashi, O. Shadura, and V. Vassilev, “Migrating Large Codebases to C++ Modules,” Journal of Physics: Conference Series 1525, no. 1 (2020): 12051.
[53]
International Organization for Standardization and International Electrotechnical Commission, ISO/IEC 1539:1991 International Standard: Information Technology, Programming Languages, Fortran, 2nd ed. (Geneva, Switzerland: International Organization for Standardization, 1991), http://iso.org/standard/6128.html.
[54]
H. Ledgard, Reference Manual for the Ada Programming Language (Berlin, Heidelberg: Springer‐Verlag, 1983), http://springer.com/gp/book/9781461250166.
[55]
H. Schildt, Java: The Complete Reference, 8th ed. (McGraw‐Hill Education, 2011), http://mhprofessional.com/9780071606301‐usa‐java‐the‐complete‐reference‐8th‐edition‐group.
[56]
G. Van Rossum and F. L. J. Drake, The Python Language Reference Manual (Network Theory Ltd, 2011), http://dl.acm.org/doi/book/10.5555/2011965.
[57]
Y. Yu, H. Dayani‐Fard, and J. Mylopoulos, “Removing False Code Dependencies to Speedup Software Build Processes,” in Proceedings of the 2003 Conference of the Centre for Advanced Studies on Collaborative Research, October 6‐9, 2003, Toronto, Ontario, Canada, eds. D. A. Stewart (IBM, 2003), 343–352, http://dl.acm.org/citation.cfm?id=961375.
[58]
H. Dayani‐Fard, Y. Yu, J. Mylopoulos, and P. Andritsos, “Improving the Build Architecture of Legacy C/C++ Software Systems,” in Fundamental Approaches to Software Engineering, 8th International Conference, FASE 2005, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2005, Edinburgh, UK, April 4‐8, 2005, Proceedings, ed. M. Cerioli, Lecture Notes in Computer Science, Vol. 3442 (Springer, 2005), 96–110, https://doi.org/10.1007/978-3-540-31984-9_8.
[59]
The Vim Community, “Vim: The Ubiquitous Text Editor,” accessed March 18, 2019, http://vim.org.
[60]
Kitware Inc ., “CMake Documentation – UNITY_BUILD,” (2019), accessed September 9, 2022, http://cmake.org/cmake/help/v3.16/prop_tgt/UNITY_BUILD.html.
[61]
M. J. Keith and M. C. Martin, “Genetic Programming in C++: Implementation Issues,” Advances in genetic programming 1 (1994): 285–310, http://cognet.mit.edu/book/advances‐genetic‐programming‐volume‐1.
[62]
E. Elizondo, Optimizing Compilation Times With Templates (Bellevue, Washington, United States of America, 2017), accessed June 12, 2020, http://youtube.com/watch?v=NPWQ7xKfIHQ.
[63]
Oracle, The Template Repository (Sun Microsystems, Inc., 2008), accessed February 27, 2019, http://docs.oracle.com/cd/E19205‐01/819‐5267/index.html.
[64]
Ceemple Software Ltd ., “ZapCC – a (Much) Faster C++ Compiler,” (2018), accessed February 27, 2019, http://zapcc.com.
[65]
M. Godbolt, The bits Between the Bits: How We Get to main() (Bellevue, Washington, United States of America, 2018), accessed June 22, 2020, http://youtube.com/watch?v=dOfucXtyEsU.
[66]
F. Fakhar, B. Javed, R. ur Rasool, O. Malik, and K. Zulfiqar, “Software Level Green Computing for Large Scale Systems,” Journal of Cloud Computing: Advances, Systems and Applications 1, no. 1 (2012): 4, http://journalofcloudcomputing.springeropen.com/articles/10.1186/2192‐113X‐1‐4.
[67]
A. Litman, “An Implementation of Precompiled Headers,” Software: Practice and Experience 23, no. 3 (1993): 341–350, http://onlinelibrary.wiley.com/doi/abs/10.1002/spe.4380230308.
[68]
T. Krishnaswamy, “Automatic Precompiled Headers: Speeding up C++ Application Build Times,” in Proceedings of the First Workshop on Industrial Experiences With Systems Software, WIESS 2000, October 22, 2000, San Diego, CA, USA, ed. D. S. Milojicic (USENIX, 2000), 57–66, http://usenix.org/events/wiess2000/krishnaswamy.html.
[69]
LLVM Foundation, “Clang 15.0 Documentation – Modules,” (2022), accessed February 24, 2023, http://releases.llvm.org/15.0.0/tools/clang/docs/Modules.html.
[70]
D. Gregor, “Modules,” in 2012 LLVM Developers' Meeting, (2012), accessed February 24, 2023, http://youtube.com/watch?v=586c_QMXir4.
[71]
LLVM Foundation, “Clang 15.0 Documentation – Standard C++ Modules,” (2022), online, accessed February 24, 2023, http://releases.llvm.org/15.0.0/tools/clang/docs/StandardCPlusPlusModules.html.
[72]
V. Vassilev, P. Canal, A. Naumann, L. Moneta, and P. Russo, “Cling – the New Interactive Interpreter for ROOT 6,” Journal of Physics: Conference Series 396, no. 5 (2012): 52071, http://iopscience.iop.org/article/10.1088/1742‐6596/396/5/052071/pdf.

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Journal of Software: Evolution and Process
Journal of Software: Evolution and Process  Volume 37, Issue 1
January 2025
696 pages
EISSN:2047-7481
DOI:10.1002/smr.v37.1
Issue’s Table of Contents
This is an open access article under the terms of the Creative Commons Attribution License, which permits use, distribution and reproduction in any medium, provided the original work is properly cited.

Publisher

John Wiley & Sons, Inc.

United States

Publication History

Published: 28 November 2024

Author Tags

  1. C++ programming language
  2. Modules
  3. software architecture
  4. software evolution
  5. software packages
  6. tool‐assisted refactoring

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 0
    Total Downloads
  • Downloads (Last 12 months)0
  • Downloads (Last 6 weeks)0
Reflects downloads up to 10 Feb 2025

Other Metrics

Citations

View Options

View options

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media