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

How C++ Templates Are Used for Generic Programming: An Empirical Study on 50 Open Source Systems

Published: 30 January 2020 Publication History
  • Get Citation Alerts
  • Abstract

    Generic programming is a key paradigm for developing reusable software components. The inherent support for generic constructs is therefore important in programming languages. As for C++, the generic construct, templates, has been supported since the language was first released. However, little is currently known about how C++ templates are actually used in developing real software. In this study, we conduct an experiment to investigate the use of templates in practice. We analyze 1,267 historical revisions of 50 open source systems, consisting of 566 million lines of C++ code, to collect the data of the practical use of templates. We perform statistical analyses on the collected data and produce many interesting results. We uncover the following important findings: (1) templates are practically used to prevent code duplication, but this benefit is largely confined to a few highly used templates; (2) function templates do not effectively replace C-style generics, and developers with a C background do not show significant preference between the two language constructs; (3) developers seldom convert dynamic polymorphism to static polymorphism by using CRTP (Curiously Recursive Template Pattern); (4) the use of templates follows a power-law distribution in most cases, and C++ developers who prefer using templates are those without other language background; (5) C developer background seems to override C++ project guidelines. These findings are helpful not only for researchers to understand the tendency of template use but also for tool builders to implement better tools to support generic programming.

    Supplementary Material

    a3-chen-apndx.pdf (chen.zip)
    Supplemental movie, appendix, image and software files for, How C++ Templates Are Used for Generic Programming: An Empirical Study on 50 Open Source Systems

    References

    [1]
    Philip Agnew and Jacob C. Koella. 1999. Constraints on the reproductive value of vertical transmission for a microsporidian parasite and its female-killing behaviour. Journal of Animal Ecology 68 (December 1999), 1010--1019.
    [2]
    Erik Arisholm, Lionel C. Briand, and Eivind B. Johannessen. 2010. A systematic and comprehensive investigation of methods to build and evaluate fault prediction models. Journal of Systems and Software 83, 1 (January 2010), 2--17.
    [3]
    Matthew H. Austern. 1999. Generic Programming and the STL: Using and Extending the C++ Standard Template Library. Addison-Wesley.
    [4]
    Hamid Abdul Basit, Damith C. Rajapakse, and Stan Jarzabek. 2005. An empirical study on limits of clone unification using generics. In Proceedings of the 17th International Conference on Software Engineering and Knowledge Engineering. 109--114.
    [5]
    Eli Bendersky. 2013. The cost of dynamic (virtual calls) vs. static (CRTP) dispatch in C++. Retrieved July 15, 2019, from https://eli.thegreenplace.net/2013/12/05/the-cost-of-dynamic-virtual-calls-vs-static-crtp-dispatch-in-c
    [6]
    Yoav Benjamini and Yosef Hochberg. 1995. Controlling the false discovery rate: A practical and powerful approach to multiple testing. Journal of the Royal Statistical Society. Series B (Methodological) 57, 1 (January 1995), 289--300.
    [7]
    Mike Blome, Saisang Cai, Colin Robertson, Mike Jones, Next Turn, and Gordon Hogenson. 2014. Introduction to Active Template Library (ATL). Retrieved July 15, 2019, from https://docs.microsoft.com/en-us/cpp/atl/introduction-to-atl?view=vs-2019.
    [8]
    Mike Blome, Saisang Cai, Colin Robertson, Mike Jones, Next Turn, and Gordon Hogenson. 2017. Function Templates. Retrieved July 15, 2019, from https://docs.microsoft.com/en-us/cpp/cpp/function-templates?view=vs-2017.
    [9]
    Boost. 2019. Boost C++ Libraries. Retrieved July 15, 2019, from https://www.boost.org/.
    [10]
    Oscar Callú, Romain Robbes, Éric Tanter, and David Röthlisberger. 2011. How developers use the dynamic features of programming languages: The case of smalltalk. In Proceedings of the 8th Working Conference on Mining Software Repositories. 23--32.
    [11]
    Yaofei Chen, Rose Dios, Ali Mili, Lan Wu, and Kefei Wang. 2005. An empirical study of programming language trends. IEEE Software 22, 3 (2005), 72--79.
    [12]
    Aaron Clauset, Cosma Rohilla Shalizi, and M. E. J. Newman. 2009. Power-law distributions in empirical data. SIAM Review 51, 4 (November 2009), 661--703.
    [13]
    William Dickinson, David Leon, and Andy Podgurski. 2001. Finding failures by cluster analysis of execution profiles. In Proceedings of the 23rd International Conference on Software Engineering (ICSE’01). IEEE Computer Society, Toronto, Ontario, Canada, 339--348.
    [14]
    F. Stephen Dobson, Thomas S. Risch, and Jan O. Murie. 1999. Increasing returns in the life history of Columbian ground squirrels. Journal of Animal Ecology 68, 1 (March 1999), 73--86.
    [15]
    Robert Dyer, Hridesh Rajan, Hoan Anh Nguyen, and Tien N. Nguyen. 2014. Mining billions of AST nodes to study actual and potential usage of Java language features. In Proceedings of the 36th International Conference on Software Engineering. 779--790.
    [16]
    James J. Elser and Jotaro Urabe. 1999. The stoichiometry of consumer-driven nutrient recycling: Theory, observations, and consequences. Ecology 80, 3 (April 1999), 735--751.
    [17]
    Michael D. Ernst, Greg J. Badros, and David Notkin and. 2002. An empirical analysis of C preprocessor use. IEEE Transactions on Software Engineering 28, 12 (December 2002), 1146--1170.
    [18]
    S. G. Ganesh. 2008. 60 Tips on Object Oriented Programming. McGraw-Hill Education.
    [19]
    Ronald Garcia, Jaakko Järvi, Andrew Lumsdaine, Jeremy Siek, and Jeremiah Willcock. 2007. An extended comparative study of language support for generic programming. Journal of Functional Programming 17, 2 (March 2007), 145--205.
    [20]
    Andrew Gilpin. 2002. C++ performance tips. Retrieved July 16, 2019, from http://www.cs.cmu.edu/ gilpin/c%2B%2B/performance.html#virtualfunctions.
    [21]
    William H. Greene. 2012. Econometric Analysis. Pearson Education.
    [22]
    Sander Greenland, James M. Robins, and Judea Pearl. 1999. Confounding and collapsibility in causal inference. Statistical Science 14, 1 (February 1999), 29--46.
    [23]
    Douglas Gregor and Jaakko Järvi. 2007. Variadic templates for C++. In Proceedings of the 2007 ACM Symposium on Applied Computing. ACM Press, 1101--1108.
    [24]
    Maurice H. Halstead. 1977. Elements of Software Science. Elsevier.
    [25]
    Stefan Hanenberg. 2010. An experiment about static and dynamic type systems. In Proceedings of 25th Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages, and Applications. 22--35.
    [26]
    Michael Hoppe and Stefan Hanenberg. 2013. Do developers benefit from generic types? An empirical comparison of generic and raw types in Java. In Proceedings of the 2013 ACM SIGPLAN International Conference on Object Oriented Programming Systems, Languages, and Applications. 457--474.
    [27]
    Scientific Toolworks Inc. 2014. Understand: Visualize your code. Retrieved July 15, 2019, from https://scitools.com/.
    [28]
    Wikimedia Foundation Inc. 2016. Category: C++ libraries - Wikipedia. Retrieved July 15, 2019, from https://en.wikipedia.org/wiki/Category:C%2B%2B_libraries.
    [29]
    ISO/IEC. 1998. Information Technology -- Programming Languages -- C++. Retrieved July 15, 2019, from https://www.iso.org/standard/25845.html.
    [30]
    ISO/IEC. 2003. Information Technology -- Programming Languages -- C++, Second Edition. Retrieved July 15, 2019, from https://www.iso.org/standard/38110.html.
    [31]
    ISO/IEC. 2011. Information Technology -- Programming Languages -- C++, Third Edition. Retrieved July 15, 2019, from https://www.iso.org/standard/50372.html.
    [32]
    ISO/IEC. 2014. Information Technology -- Programming Languages -- C++, Fourth Edition. Retrieved July 15, 2019, from https://www.iso.org/standard/64029.html.
    [33]
    ISO/IEC. 2017. Information Technology -- Programming Languages -- C++, Fifth Edition. Retrieved July 15, 2019, from https://www.iso.org/standard/68564.html.
    [34]
    Elizabeth M. Jakob, Samuel D. Marshall, and George W. Uetz. 1996. Estimating fitness: A comparison of body condition indices. Canadian Journal of Zoology 77, 01 (October 1996), 61--67.
    [35]
    Vojtech Jarošík and A. F. G. Dixon. 1999. Population dynamics of a tree-dwelling aphid: Regulation and density-independent processes. Journal of Animal Ecology 68 (December 1999), 726--732.
    [36]
    Nicolai M. Josuttis. 2012. The C++ Standard Library: A Tutorial and Reference (2nd ed.). Addison-Wesley.
    [37]
    Siim Karus and Siim Karus. 2011. A study of language usage evolution in open source software. In Proceedings of the 8th International Working Conference on Mining Software Repositories. 13--22.
    [38]
    Madhusudan Katti and Trevor Price. 1999. Annual variation in fat storage by a migrant warbler overwintering in the Indian tropics. Journal of Animal Ecology 68 (December 1999), 815--823.
    [39]
    Donghoon Kim, Emerson Murphy-Hill, Chris Parnin, Christian Bird, and Ronald Garcia. 2013. The reaction of open-source projects to new language features: An empirical study of C# generics. Journal of Object Technology 12, 4 (November 2013), 1:1--31.
    [40]
    Sebastian Kleinschmager, Romain Robbes, Andreas Stefik, Stefan Hanenberg, and Éric Tanter. 2012. Do static type systems improve the maintainability of software systems? An empirical study. In Proceedings of IEEE 20th International Conference on Program Comprehension. 153--162.
    [41]
    A. Günes Koru and Jeff (Jianhui) Tian. 2005. Comparing high-change modules and modules with the highest measurement values in two large-scale open-source products. IEEE Transactions on Software Engineering 31, 8 (August 2005), 625--642.
    [42]
    Aditya Kumar, Andrew Sutton, and Bjarne Stroustrup. 2012. Rejuvenating C++ programs through demacrofication. In Proceedings of the 2012 IEEE International Conference on Software Maintenance (ICSM’12). 23--28.
    [43]
    Jeff Leips and Joseph Travis. 1999. The comparative expression of life-history traits and its relationship to the numerical dynamics of four populations of the least killifish. Journal of Animal Ecology 68 (December 1999), 595--616.
    [44]
    Antonio Lima, Luca Rossi, and Mirco Musolesi. 2014. Coding together at scale: GitHub as a collaborative social network. In Proceedings of the 8th International AAAI Conference on Weblogs and Social Media. 295--304.
    [45]
    W. M. Lonsdale. 1999. Global patterns of plant invasions and the concept of invasibility. Ecology 80, 5 (July 1999), 1522--1536.
    [46]
    Maarten J. J. E. Loonen, Leo W. Bruinzeel, Jeff M. Black, and Rudi H. Drent. 1999. The benefit of large broods in barnacle geese: A study using natural and experimental manipulations. Journal of Animal Ecology 68 (December 1999), 753--768.
    [47]
    Thomas Madsen and Richard Shine. 1999. The adjustment of reproductive threshold to prey abundance in a capital breeder. Journal of Animal Ecology 68, 1 (December 1999), 571--580.
    [48]
    Thomas Madsen and Richard Shine. 1999. Life history consequences of nest-site variation in tropical pythons (liasis fuscus). Ecology 80, 3 (April 1999), 989--997.
    [49]
    Clemens Mayer, Stefan Hanenberg, Romain Robbes, Éric Tanter, and Andreas Stefik. 2012. An empirical study of the influence of static type systems on the usability of undocumented software. In Proceedings of 27th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications. 683--702.
    [50]
    Leo A. Meyerovich and Ariel S. Rabkin. 2013. Empirical analysis of programming language adoption. In Proceedings of the 2013 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications. 1--18.
    [51]
    Scott Meyers. 2001. Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library (2nd ed.). Addison-Wesley.
    [52]
    Scott Meyers. 2008. Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd ed.). Addison-Wesley.
    [53]
    Microsoft. [n.d.]. Templates vs. Macros. Retrieved July 15, 2019, from https://www.microsoft.com/en-us/download/details.aspx?id=55979.
    [54]
    Emerson Murphy-Hill and Dan Grossman. 2014. How programming languages will co-evolve with software engineering: A bright decade ahead. In Proceedings of the on Future of Software Engineering. 145--154.
    [55]
    Zain Naboulsi. 2010. Code Metrics Depth of Inheritance (DIT). Retrieved July 15, 2019, from https://blogs.msdn.microsoft.com/zainnab/2011/05/19/code-metrics-depth-of-inheritance-dit/.
    [56]
    Meiyappan Nagappan, Romain Robbes, Yasutaka Kamei, Éric Tanter, Shane McIntosh, Audris Mockus, and Audris Mockus. 2015. An empirical study of goto in C code from GitHub repositories. In Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering. 404--414.
    [57]
    Sebastian Nanz and Carlo A. Furia. 2015. A comparative study of programming languages in Rosetta Code. In Proceeding of the 37th International Conference on Software Engineering. 778--788.
    [58]
    Semih Okur and Danny Dig. 2012. How do developers use parallel libraries?. In Proceedings of the ACM SIGSOFT 20th International Symposium on the Foundations of Software Engineering. 54:1--54:11.
    [59]
    Pamela O’Neil. 1999. Selection on flowering time: An adaptive fitness surface for nonexistent character combinations. Ecology 80, 3 (April 1999), 806--820.
    [60]
    Kai Pan, Sunghun Kim, and E. James Whitehead Jr. 2006. Bug classification using program slicing metrics. In Proceedings of the 6th IEEE International Workshop on Source Code Analysis and Manipulation. 31--42.
    [61]
    Chris Parnin, Christian Bird, and Emerson Murphy-Hill. 2011. Java generics adoption: How new features are introduced, championed, or ignored. In Proceedings of the 8th Working Conference on Mining Software Repositories (MSR’11). 3--12.
    [62]
    Chris Parnin, Christian Bird, and Emerson Murphy-Hill. 2013. Adoption and use of Java generics. Empirical Software Engineering 18, 6 (December 2013), 1047--1089.
    [63]
    Gustavo Pinto, Weslley Torres, Benito Fernandes, Fernando Castor, and Roberto S. M. Barros. 2015. A large-scale study on the usage of Java’s concurrent programming constructs. Journal of Systems and Software 106 (2015), 59--81.
    [64]
    Baishakhi Ray, Daryl Posnett, Vladimir Filkov, and Premkumar Devanbu. 2014. A large scale study of programming languages and code quality in Github. In Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering. 155--165.
    [65]
    James D. Reist. 1985. An empirical evaluation of several univariate methods that adjust for size variation in morphometric data. Canadian Journal of Zoology 63, 6 (February 1985), 1429--1439.
    [66]
    Romain Robbes, David Röthlisberger, and Éric Tanter. 2015. Object-oriented software extensions in practice. Empirical Software Engineering 20, 3 (2015), 745--782.
    [67]
    Jeanine Romano, Jeffrey D. Kromrey, Jesse Coraggio, and Jeff Skowronek. 2006. Appropriate statistics for ordinal level data: Should we really be using t-test and Cohen’s d for evaluating group differences on the NSSE and other surveys? In Proceedings of Annual Meeting of the Florida Association of Institutional Research. 1--33.
    [68]
    Sandro Schulze, Jörg Liebig, Jörg Liebig, and Sven Apel. 2013. Does the discipline of preprocessor annotations matter?: A controlled experiment. In Proceedings of 12th International Conference on Generative Programming: Concepts and Experiences. 65--74.
    [69]
    Alexander Stepanov and Paul McJones. 2009. Elements of Programming (2nd ed.). Addison-Wesley.
    [70]
    Bjarne Stroustrup. 1994. The Design and Evolution of C++. Addison-Wesley.
    [71]
    Bjarne Stroustrup. 2000. The C++ Programming Language (3rd ed.). Addison Wesley.
    [72]
    Bjarne Stroustrup. 2004. Templates aliases for C++. Retrieved July 15, 2019, from http://www.stroustrup.com/template-aliases.pdf.
    [73]
    Bjarne Stroustrup. 2013. The C++ Programming Language (4th ed.). Addison-Wesley, New York, NY.
    [74]
    Bjarne Stroustrup and Herb Sutter. 2019. C++ Core Guidelines. Retrieved July 15, 2019, from http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.
    [75]
    Herb Sutter and Andrei Alexandrescu. 2005. C++ Coding Standards: 101 Rules, Guidelines, and Best Practices. Pearson Education, Inc.
    [76]
    Frédéric Tripet and Heinz Richner. 1999. Density-dependent processes in the population dynamics of a bird ectoparasite ceratophyllus gallinae. Ecology 80, 4 (June 1999), 1267--1277.
    [77]
    David Vandevoorde and Nicolai M. Josuttis. 2002. C++ Templates: The Complete Guide. Addison-Wesley.
    [78]
    Genevieve Warren, Jill Reinauer, and Eddy Nakamura. 2016. CA1501: Avoid excessive inheritance. Retrieved July 15, 2019 from https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1501?view=vs-2019.
    [79]
    Helmut Wendeln and Peter H. Becker. 1999. Effects of parental quality and effort on the reproduction of common terns. Journal of Animal Ecology 68 (December 1999), 205--214.
    [80]
    Di Wu, Lin Chen, and Baowen Xu. 2014. An empirical study on the adoption of C++ templates: Library templates versus user defined templates. In Proceedings of the 26th International Conference on Software Engineering and Knowledge Engineering (SEKE’14). 144--149.
    [81]
    Di Wu, Lin Chen, Yuming Zhou, and Baowen Xu. 2015. An empirical study on C++ concurrency constructs. In Proceedings of 9th International Symposium on Empirical Software Engineering and Measurement. IEEE, 257--266.
    [82]
    Di Wu, Lin Chen, Yuming Zhou, and Baowen Xu. 2015. How do developers use C++ libraries? An empirical study. In Proceedings of 27th International Conference on Software Engineering and Knowledge Engineering. 260--265.
    [83]
    Di Wu, Lin Chen, Yuming Zhou, and Baowen Xu. 2015. A metrics-based comparative study on object-oriented programming languages. In Proceedings of 27th International Conference on Software Engineering and Knowledge Engineering. 272--277.
    [84]
    Yuming Zhou, Hareton Leung, and Baowen Xu. 2009. Examining the potentially confounding effect of class size on the associations between object-oriented metrics and change-proneness. IEEE Transactions on Software Engineering 35, 5 (September 2009), 607--623.
    [85]
    Yuming Zhou, Baowen Xu, and Hareton Leung. 2010. On the ability of complexity metrics to predict fault-prone classes in object-oriented systems. Journal of Systems and Software 83, 4 (April 2010), 660--674.
    [86]
    Yuming Zhou, Baowen Xu, Hareton Leung, and Lin Chen. 2014. An in-depth study of the potentially confounding effect of class size in fault prediction. ACM Transactions on Software Engineering and Methodology 23, 1 (February 2014), 10:1--10:51.

    Cited By

    View all

    Index Terms

    1. How C++ Templates Are Used for Generic Programming: An Empirical Study on 50 Open Source Systems

        Recommendations

        Comments

        Information & Contributors

        Information

        Published In

        cover image ACM Transactions on Software Engineering and Methodology
        ACM Transactions on Software Engineering and Methodology  Volume 29, Issue 1
        January 2020
        317 pages
        ISSN:1049-331X
        EISSN:1557-7392
        DOI:10.1145/3375995
        • Editor:
        • Mauro Pezzè
        Issue’s Table of Contents
        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        Published: 30 January 2020
        Accepted: 01 August 2019
        Revised: 01 July 2019
        Received: 01 August 2016
        Published in TOSEM Volume 29, Issue 1

        Permissions

        Request permissions for this article.

        Check for updates

        Author Tags

        1. C++
        2. Programming language
        3. empirical study
        4. generic programming
        5. template

        Qualifiers

        • Research-article
        • Research
        • Refereed

        Funding Sources

        • National Key R&D Program of China
        • National Natural Science Foundation of China

        Contributors

        Other Metrics

        Bibliometrics & Citations

        Bibliometrics

        Article Metrics

        • Downloads (Last 12 months)52
        • Downloads (Last 6 weeks)1

        Other Metrics

        Citations

        Cited By

        View all
        • (2024)Collection skeletonsJournal of Systems and Software10.1016/j.jss.2024.112042213:COnline publication date: 1-Jul-2024
        • (2024)Why and how bug blocking relations are breakableInformation and Software Technology10.1016/j.infsof.2023.107354166:COnline publication date: 1-Feb-2024
        • (2024)Embracing modern C++ featuresJournal of Software: Evolution and Process10.1002/smr.260536:5Online publication date: 25-Apr-2024
        • (2022)Collection Skeletons: Declarative Abstractions for Data CollectionsProceedings of the 15th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3567512.3567528(189-201)Online publication date: 29-Nov-2022

        View Options

        Get Access

        Login options

        Full Access

        View options

        PDF

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader

        HTML Format

        View this article in HTML Format.

        HTML Format

        Media

        Figures

        Other

        Tables

        Share

        Share

        Share this Publication link

        Share on social media