While some promote method chaining as a good practice for improving code readability, others refer to it as a bad practice that worsens code quality. In this paper, we first investigate whether method chaining is a programming style accepted by real-world programmers. To answer this question, we collected 2,814 Java repositories on GitHub and analyzed historical trends in the frequency of method chaining. The results of our analysis revealed the increasing use of method chaining; 23.1% of method invocations were part of method chains in 2018, whereas only 16.0% were such invocations in 2010. We then explore language features that are helpful to the method-chaining style but have not been supported yet in Java. For this aim, we conducted manual inspections of method chains that are randomly sampled from the collected repositories. We also estimated how effective they are to encourage the method-chaining style if they are adopted in Java.
Tomoki Nakamaru Graduate School of Information Science and Technology, The University of Tokyo, Tomomasa Matsunaga, Tetsuro Yamazaki Graduate School of Information Science and Technology, The University of Tokyo, Soramichi Akiyama Department of Creative Informatics, The University of Tokyo, Shigeru Chiba The University of Tokyo