Back to Search
Start Over
What do developers consider magic literals? A smalltalk perspective
- Source :
- Information and Software Technology, Information and Software Technology, 2022, 149, ⟨10.1016/j.infsof.2022.106942⟩
- Publication Year :
- 2022
- Publisher :
- Elsevier BV, 2022.
-
Abstract
- International audience; Context: Literals are constant values (numbers, strings, etc.) used in the source code. Magic literals are such values used without an explicit explanation of their meaning. Such undocumented values may hinder sourcecode comprehension, negatively impacting maintenance. Relatively little literature can be found on the subject beyond the usual (and very old) recommendation of avoiding literals and preferring named constants. Yet, magic literals are still routinely found in source code. Objective: We studied literal values in source code to understand when they should be considered magic or not (i.e., acceptable). Methods: First, we perform a qualitative study of magic literals, to establish why and under which conditions they are considered harmful. We formalize hypotheses about the reasoning behind how literals are considered magic. Second, we perform a quantitative study on seven real systems ranging from small (a few classes) to large (thousands of classes). We report the literals' types (number, string, Boolean,. . .), their grammatical function (e.g., argument in a call, operand in an expression, value assigned,. . .), or the purpose of the code in which they appear (test methods, regular code). Third, we report on another study involving 26 programmers who analyzed about 24,000 literals, to understand which ones they consider magic. Finally, we evaluate the hypotheses defining specific conditions under which literals are acceptable. Results: We show that (1) literals still exist and are relatively frequent (found in close to 50% of the methods considered); (2) they are more frequent in test methods (in 80% of test methods); (3) to a large extent, they were considered acceptable (only 25% considered magic); and (4) the hypotheses concerning acceptable literals are valid to various degrees. Conclusion: We thus pave the way to future research on magic literals, for example, with tools that could help developers deciding if a literal is acceptable.
Details
- ISSN :
- 09505849 and 18736025
- Volume :
- 149
- Database :
- OpenAIRE
- Journal :
- Information and Software Technology
- Accession number :
- edsair.doi.dedup.....68316c0b52d699efea5fd1321de9e67e
- Full Text :
- https://doi.org/10.1016/j.infsof.2022.106942