Title
How C++ Templates Are Used for Generic Programming: An Empirical Study on 50 Open Source Systems
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.
Year
DOI
Venue
2020
10.1145/3356579
ACM Transactions on Software Engineering and Methodology (TOSEM)
Keywords
Field
DocType
C++,Programming language,empirical study,generic programming,template
Programming language,Computer science,Theoretical computer science,Template,Generic programming,Empirical research
Journal
Volume
Issue
ISSN
29
1
1049-331X
Citations 
PageRank 
References 
0
0.34
0
Authors
6
Name
Order
Citations
PageRank
Lin Chen163.43
Di Wu221.03
Wanwangying Ma3264.28
Yuming Zhou455924.72
Xu, Baowen52476165.27
Hareton Leung698265.63