Content area
Writing functions is one of the basic mechanisms to implement reusability in software development. It serves as a method for reducing the cost of maintenance in the development of systems. While the writing of functions appears to be a good idea, previous research showed that developers do not use it as their first choice but prefer to use alternative strategies such as code cloning. In this research, we examined this behavior from free different theoretical perspectives: 1) The economical perspective: the effect of cost-benefit considerations 2) The structural perspective: the effect of tasks' hierarchical structure and cognitive fit, and 3) the social perspective: the effect of pair programming. We conducted three studies, which employed experimental tasks performed by university Information System students, each designed to answer one of these questions. The results showed that the decision to write functions is affected by different cognitive, structural, and social factors.
In the first study, we found that when asked to code, less than half of the participants exhibited a cost-benefit decision pattern that was sensitive to the number of repetitions in a task, whereas most of the rest of the participants avoided writing reusable code altogether. However, when asked to plan how they would solve the task and indicate their decision before coding, we found an overwhelming difference in the decisions made in these settings compared to the first scenario. These results suggest a new direction that should be considered in studying cognitive effort of utility-based decision-making.
In the second study, we examined the effect of task-structure complexity on the decision to write reusable code. We manipulated the structure of coding tasks by adding a structure of hierarchical subtask (high complexity) compared to a non-hierarchical structure (low complexity) of tasks. We found that in the high complexity group, 34 participants of 60 (43%) used functions to solve the task, while in the low complexity group only 10 participants of 53 (19%) used functions to solve the task. We further found that that participants who did not write functions used a lower number of paste commands in the high complexity condition (average 7.94, median 7) compared with the low complexity condition (average 16.94, median 14.9) suggesting that the structural pattern had an effect on their decision to write the code in a reusable manner. These results show the importance of setting the task structure in a way that increases the tendency of programmers to write reusable code.
In the third study, we studied the difference of writing reusable code between pair-programmers and individuals, and further studied the effect of allocating explicit roles in pair-programming, by introducing a planning step to the programmer who served as the "navigator" (i.e., the one seating next to the programmer who actively writes the code, called "driver"). In the first experiment, we did not find a significant difference in the tendency to write reusable code between individual programmers (SP) and pairs (PP). In the second experiment, we found that PP with explicit roles (PPE) wrote more functions and rated their confidence and satisfaction more highly than programmers in the previous experiment, both in the PP and SP condition. These results highlight the importance of using explicit roles as a key factor in the "driver-navigator" model in PP and its effect on the decision of writing reusable code.
Taken together, these studies show that the decision-making process of individuals, as well as pairs, executing even simple coding tasks is not optimal. Following Kahneman's dual-systems model of cognitive processes, I suggest that as in any other cognitive task, programmers may be influenced by limited ability to assess the problem which lead them to automatic decision to avoid writing reusable code. The interventions described in my studies serve as a way to stop this automatic process, and engage in deliberate decision which leads them to choose the more efficient reusable code solution. As such, my studies shed light on the importance of factors related to the task presentation, the work environment and how they may be set for leading to the desired output of work.