Mining the Use of Higher-Order Functions: An Exploratory Study on Scala Programs

Published in Proceedings of the National Software Application Conference (NASAC 2019), Hangzhou, China. 2019., 2019


A higher-order function takes one or more functions as inputs or outputs to support the generality of function definitions. In modern programming languages, higher-order functions are designed as a feature to enhance the usability and scalability. Abstracting higher-order functions from existing functions decreases the number of similar functions and improves the code reuse. However, due to the complexity, defining and calling higher-order functions are not widely used in practice. In this paper, we investigate the use of higher-order functions in Scala programs. We collected 7,804 higher-order functions from 35 Scala projects in GitHub with the most stars and conducted an exploratory study via answering five research questions of using higher-order functions, including the data scale, the definitions and calls, the overlap with lambda expressions, the developer contribution, and the factor that affects the function calls. Our study mainly shows five empirical results about the common use of higher-order functions in Scala programs: higher-order functions are not widely used in Scala programs; most of higher-order functions are defined and called by the same developers; there exists a small overlap between calling higher-order functions and calling lambda expressions; top 20% of developers have contributed 81% of definitions and 86% of calls of higher-order functions; and the number of calls of higher-order functions correlates most with the number of executable lines of code and the code complexity. This study can be viewed as a preliminary result to understand the use of higher-order functions and to trigger further investigation in Scala programs.