Comparing the understandability of iteration mechanisms over Collections in Java
Author:
Hnatkowska Bogumiła1, Krych Bartosz1
Affiliation:
1. 1 Wroclaw University of Science and Technology , Wybrzeże Wyspiańskiego 27, 50-370 Wrocław , Poland
Abstract
Abstract
Source code understandability is a desirable quality factor affecting long-term code maintenance. Understandability of source code can be assessed in a variety of ways, including subjective evaluation of code fragments (perceived understandability), correctness, and response time to tasks performed. It can also be assessed using various source code metrics, such as cyclomatic complexity or cognitive complexity. Programming languages are evolving, giving programmers new ways to do the same things, e.g., iterating over collections. Functional solutions (lambda expressions and streams) are added to typical imperative constructs like iterators or for-each statements. This research aims to check if there is a correlation between perceived understandability, understandability measured by task correctness, and predicted by source code metrics for typical tasks that require iteration over collections implemented in Java. The answer is based on the results of an experiment. The experiment involved 99 participants of varying ages, declared Java knowledge and seniority measured in years. Functional code was perceived as the most understandable, but only in one case, the subjective assessment was confirmed by the correctness of answers. In two examples with the highest perceived understandability, streams received the worst correctness scores. Cognitive complexity and McCabe’s complexity had the lowest values in all tasks for the functional approach, but – unfortunately – they did not correlate with answer correctness. The main finding is that the functional approach to collection manipulation is the best choice for the filter-map-reduce idiom and its alternatives (e.g., filter-only). It should not be used in more complex tasks, especially those with higher complexity metrics.
Publisher
Walter de Gruyter GmbH
Reference16 articles.
1. Baron, M. M., Wirich, M., Wagner, S.: An Empirical Validation of Cognitive Complexity as a Measure of Source Code Understandability, in Proceedings of the 14th ACM/IEEE International Symposium of Empirical Software Engineering and Measurement, p. 1-12, (2020). 2. Bexell, A.: Comparing functional to imperative Java with regards to readability, complexity, and verbosity, Växjö, (2017). 3. Cheon, Y., Escobar De La Torre, A.: Impacts of Java Language Features on the Memory Performances of Android Apps, ScholarWorks@UTEP, Impacts of Java Language Features on the Memory Performances of Android Apps - CORE (2017). 4. Costa, D. E., Andrzejak, A., Seboek, J, Lo, D.: Empirical Study of Usage and Performance of Java Collections, Proceedings of the 8th ACM/SPEC on International Conference on Performance Engineering, (2017). 5. Flauzino, M., Veríssimo, J., Terra, R., Cirilo, E., Durelli, V., Durelli, R.: Are you still smelling it?: A comparative study between Java and Kotlin Language, Proceedings of the VII Brazilian Symposium on Software Components, Architectures, and Reuse, pp. 23-32, (2018).
|
|