Affiliation:
1. USI Lugano, Switzerland
Abstract
The main goal of a static type system is to prevent certain kinds of errors from happening at run time. A type system is formulated as a set of constraints that gives any expression or term in a program a well-defined type. Yet mainstream programming languages are endowed with type systems that provide the means to circumvent their constraints through casting.
We want to understand how and when developers escape the static type system to use dynamic typing. We empirically study how casting is used by developers in more than seven thousand Java projects. We find that casts are widely used (8.7% of methods contain at least one cast) and that 50% of casts we inspected are not guarded locally to ensure against potential run-time errors.
To help us better categorize use cases and thus understand how casts are used in practice, we identify 25 cast-usage patterns---recurrent programming idioms using casts to solve a specific issue. This knowledge can be: (a) a recommendation for current and future language designers to make informed decisions (b) a reference for tool builders, e.g., by providing more precise or new refactoring analyses, (c) a guide for researchers to test new language features, or to carry out controlled programming experiments, and (d) a guide for developers for better practices.
Funder
Schweizerischer Nationalfonds zur Förderung der Wissenschaftlichen Forschung
Publisher
Association for Computing Machinery (ACM)
Subject
Safety, Risk, Reliability and Quality,Software
Reference79 articles.
1. Mining source code repositories at massive scale using language modeling
2. Taming the wildcards
3. Sourcerer: An internet-scale software repository
4. Gavin Bierman. 2019. JEP 354: Switch Expressions. (2019). https://openjdk.java.net/jeps/354 Gavin Bierman. 2019. JEP 354: Switch Expressions. (2019). https://openjdk.java.net/jeps/354
Cited by
9 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献
1. Bloat beneath Python’s Scales: A Fine-Grained Inter-Project Dependency Analysis;Proceedings of the ACM on Software Engineering;2024-07-12
2. Do names echo semantics? A large-scale study of identifiers used in C++’s named casts;Journal of Systems and Software;2023-08
3. Towards the Detection of Hidden Familial Type Correlations in Java Code;2022 IEEE 22nd International Working Conference on Source Code Analysis and Manipulation (SCAM);2022-10
4. An Empirical Study of Solidity Language Features;2021 IEEE 21st International Conference on Software Quality, Reliability and Security Companion (QRS-C);2021-12
5. Well-typed programs can go wrong: a study of typing-related bugs in JVM compilers;Proceedings of the ACM on Programming Languages;2021-10-20