How C++ Templates Are Used for Generic Programming

Author:

Chen Lin1,Wu Di2,Ma Wanwangying1,Zhou Yuming1,Xu Baowen1,Leung Hareton3

Affiliation:

1. Nanjing University, China

2. Momenta, China

3. Hong Kong Polytechnic University, China

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.

Funder

National Key R&D Program of China

National Natural Science Foundation of China

Publisher

Association for Computing Machinery (ACM)

Subject

Software

Reference86 articles.

1. Constraints on the reproductive value of vertical transmission for a microsporidian parasite and its female-killing behaviour

2. A systematic and comprehensive investigation of methods to build and evaluate fault prediction models

3. Matthew H. Austern. 1999. Generic Programming and the STL: Using and Extending the C++ Standard Template Library. Addison-Wesley. Matthew H. Austern. 1999. Generic Programming and the STL: Using and Extending the C++ Standard Template Library. Addison-Wesley.

Cited by 4 articles. 订阅此论文施引文献 订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献

1. Collection skeletons: Declarative abstractions for data collections;Journal of Systems and Software;2024-07

2. Why and how bug blocking relations are breakable: An empirical study on breakable blocking bugs;Information and Software Technology;2024-02

3. Embracing modern C++ features: An empirical assessment on the KDE community;Journal of Software: Evolution and Process;2023-08-02

4. Collection Skeletons: Declarative Abstractions for Data Collections;Proceedings of the 15th ACM SIGPLAN International Conference on Software Language Engineering;2022-11-29

同舟云学术

1.学者识别学者识别

2.学术分析学术分析

3.人才评估人才评估

"同舟云学术"是以全球学者为主线,采集、加工和组织学术论文而形成的新型学术文献查询和分析系统,可以对全球学者进行文献检索和人才价值评估。用户可以通过关注某些学科领域的顶尖人物而持续追踪该领域的学科进展和研究前沿。经过近期的数据扩容,当前同舟云学术共收录了国内外主流学术期刊6万余种,收集的期刊论文及会议论文总量共计约1.5亿篇,并以每天添加12000余篇中外论文的速度递增。我们也可以为用户提供个性化、定制化的学者数据。欢迎来电咨询!咨询电话:010-8811{复制后删除}0370

www.globalauthorid.com

TOP

Copyright © 2019-2024 北京同舟云网络信息技术有限公司
京公网安备11010802033243号  京ICP备18003416号-3