Keywords

1 Introduction

Emotion is one of the most popular areas of focus for the neuroIS community where neurophysiological tools may be used for more objective measures than self-reports [1, 2]. Emotion is characterized in psychology as a multidimensional state where an individual experiences feelings that can be described as good or bad, energizing or draining. A growing body of literature is recognizing a two-dimensional framework, the circumplex model, for representing this phenomenon. This model describes an emotional state in a two-dimensional circular space with the arousal and valence dimensions, where the dimension of valence describes the extent to which an emotion is positive or negative, and the dimension of arousal describes its intensity [3,4,5]. These emotional experiences have been shown to be associated with activation of certain regions in the brain suggesting that physiological correlates of emotions can be measured using neurophysiological and neuroimaging tools [6, 7].

Electroencephalography (EEG), which measures electrical activity in the brain, is one of such neurophysiological measures that correlate with emotions [2, 8]. Changes in emotions can cause differences in EEG signals, which may reflect different emotional states. For instance, research shows that high frequencies sensed from electrodes positioned on the frontal, parietal, and occipital lobes have high correlation with emotional valence [9], and it is possible to discriminate between happiness and sadness by analyzing EEG signals in various situations [10]. In fact, EEG has been used to study how the brain functions in relation to job performance in software development and how programmers experience positive and negative emotions when coding.

Code quality is an important metric for evaluation of software as poorly written code can negatively impact the utility and the security of an application. The quality of code refers to how well-written and structured the code is, as well as how effectively it performs its intended function [11, 12]. High-quality code is easy to read and understand, well-documented, and efficient. There are many technical factors that affect the quality of code, such as clarity, maintainability, reliability, and security [13]. Other behavioral factors can impact the quality of code, such as motivation, communication, time management, and emotions [14].

Emotions can have a significant impact on people’s performance. Notably, positive and negative emotions can significantly impact the quality of code that developers produce [15,16,17,18]. Relaxation can have a positive impact on code quality, as well. When developers are relaxed, they are more likely to be focused, creative, and attentive to detail [19,20,21]. These characteristics can lead to better code quality and more efficient development.

In this paper, we present a work-in-progress study to understand the impact of emotions on the quality of programming code. To better understand this impact, we explore the possible effect of relaxation on emotions while novice programmers solve a case problem. We provide a discussion about these findings with appreciation that further investigation with a larger sample size will be most helpful for the continuation of this research to reinforce or alter current leanings.

2 Background

Despite growing evidence that most defects in code quality are a result of human cognitive issues [22,23,24,25], software development processes in practice do not consider the emotional state of programmers during coding. The ability to examine and understand how emotions affect code quality using neurophysiological measurements can provide guidance to managers and developers to take appropriate measures to minimize and prevent poor-quality code and promote a healthy environment for the programmer. Furthermore, scholars have suggested that the use of neurophysiological measures in software engineering could lead to the design and development of integrated, neuro-adaptive development environments and learning platforms [26,27,28,29]. Several studies in software engineering have employed a variety of neurophysiological tools to study the electrical activity of the brain [2, 8], the skin [28], and heart rate variability (HRV) [29]. Results from these studies indicate that measures captured with neurophysiological tools can be used to investigate the emotional states of programmers when performing various programming tasks [3]. However, most of this prior work has centered on the prediction of abilities. Only a limited number of studies focus on emotional processes using neurophysiological tools in the context of software engineering [30,31,32]. Our study builds on prior work by using neurophysiological tools to examine the impact of relaxation and emotions on the quality of code produced by novice programmers during a coding task.

3 Proposed Study

Electroencephalography has been used to extract and detect positive and negative emotions from brain signals and incorporated as feedback into neuro-adaptive interfaces [33, 34]. The proposed study aims to use non-invasively recorded EEG to measure developers’ emotions while programming a task to identify if positive and negative emotions have a correlation with high- or low-quality of the code. The EEG recording system we are using is the BioSemi ActiveTwo bioamplifier system [35].

The ActiveTwo system consists of a headbox, which connects to a set of electrodes placed on the scalp to measure EEG signals, and a bioamplifier unit, which magnifies and digitizes these signals. The ActiveTwo system is used to measure EEG activity in specific regions of the brain that are associated with emotional processing, such as the prefrontal cortex [36]. The prefrontal cortex is a brain region involved in many cognitive and emotional processes, including the regulation of positive and negative emotions [37]. It has been shown that the left prefrontal cortex (PFC) is associated with positive emotions, while the right PFC is associated with negative emotions [38,39,40].

The quality of code can be determined using Code-DKT [41]. Code-DKT stands for “Code-based Deep Knowledge Tracing.” It is a neural network-based approach to modeling student knowledge over time in the context of programming tasks. In this study, we use the categories of Code-DKT to manually analyze the code’s quality, specifically on the reason why participants make incorrect submissions. In the future, we plan to use Code-DKT in a more data-driven way to evaluate novices’ code quality. For example, Code-DKT uses the Code2vec model to predict students’ programming performance in an educational context based on their submissions when they practice programming in a course [42]. The approach incorporates the Code2vec model into the traditional DKT model for the performance prediction task [43]. This approach directly incorporates features from programming code into the model and achieves state-of-the-art performance in the prediction task for the computing education domain. While we currently leverage a limited set of test cases to evaluate the quality of programming code, as more data is available, we will switch to the data-driven method for a more accurate evaluation of the quality of student code quality.

4 Methodology

Seven (7) participants were recruited with ages between 18 and 40 years old and located in the southeast region of the United States. Participants belonged to different university departments with some fundamental coding experience with Python. Participants were randomly divided into two groups. The control group received a relaxation treatment via a biofeedback device called the Muse 2 [44] for ten minutes. The experimental group attempted the coding task without engaging in the relaxation activity.

The BioSemi ActiveTwo system was used to collect participants’ EEG signals as they completed a thirty-minute coding activity of writing Python code for a classical programming problem, the rainfall problem [45]. The placement of the BioSemi ActiveTwo sensors was performed by trained personnel to ensure that it was comfortably and accurately positioned on the participant’s head. The study ensured that the procedures for both, the experimental and control groups, were consistent and standardized to reduce any potential confounding factors that may affect the study results. Figure 1 shows one of the participants wearing an electrode cap fitted with active electrodes wired to the BioSemi bioamplifier during the experiment.

Fig. 1
A photograph of a participant seated on a chair. There is a table next to the participant with a laptop on it. The participant wears an electrode cap.

Participant wearing an electrode cap with BioSemi active electrodes

Independent variables consisted of individual characteristics, including age, sex, relaxation treatment, and EEG data from the brain that was collected during the time the participants attempted the coding task. We collected information from 16 channels of EEG using a Common Average Reference (CAR) across: frontal-polar (Fp1, Fp2), frontal-central (FC3, FCz, FC4), central (C3, Cz, C4), temporal-parietal (TP7, TP8), parietal (P3, Pz, P4), and occipital (O1, Oz, O2). After collection, we performed offline feature extractions of the EEG signals for emotion classification. We used the software EDFBrowser [46] to down sample the signals from 1024 Hz to a sampling rate of 256 Hz. Then, we used standardized low resolution brain electromagnetic tomography (sLORETA) software to determine the cross-spectra and visualize the brain activations in a topographic plot [47]. The topographies revealed the left and right prefrontal cortex asymmetry as often related to emotions.

Dependent variables consisted of the manual analysis of the code’s quality that consisted of parameters such as syntaxis errors, I/O incorrect prompt, and non-identifiable logic. Quality points were assigned from 0 to 4, where 0 is the lowest quality and 4 is the highest. Figure 2 shows a representation of the possible relationships between the variables of the study. Independent variables such as age, sex, and relaxation treatment may act as moderators or mediators on the quality of code, however a bigger sample size is needed to establish such effects.

Fig. 2
A block flow diagram of independent variables. Individual characteristics, relaxation treatment, and emotions lead to the quality of code. Relaxation treatment is also linked to emotions.

Independent variables of age, sex, relaxation treatment, and emotion as determined from EEG, and their possible effects on the independent variable of code quality

5 Preliminary Results

Emotions and code quality were analyzed for the seven participants in the study of six males and one female with an average age of 21.6 (±3.7). The participants were racially-diverse, with two White, three Asian, one Hispanic, and one Black/African-American. After visual inspection of the EEG, we analyzed the brain activations from the sixteen channels of scalp electrodes using a previously-validated technique for brain localization with the same name of the accompanying software, sLORETA [48]. These activations were presented on a normalized scale such that brighter areas with yellow indicated the highest levels of activation. For each six-view grouping of topological plots, the image presented on the top row in the center is a back-end view of the brain whereas the image on the bottom row in the center is a front-on view of the brain. In a similar manner as used by Riley and Randolph [49], theory indicates that higher activation in the left hemisphere may indicate a stronger positive approach to the stimulus whereas higher activation in the right hemisphere may indicate a negative approach to the stimulus [49, 50].

As “work-in-progress,” we start seeing a tendency in the results that need to be confirmed with more data. Table 1 shows the results of each participant after completing the study. The Muse 2 provided an assessment of percent calm which we report for all four participants who received the relaxation treatment except for participant C0110 whose percentage was not captured.

Table1 Preliminary results of the study

Surprisingly, the majority of the participants that experienced positive emotions (evidenced from highest activation levels in left prefrontal cortex), developed low quality code. There are inconclusive results from participants that exhibited negative emotions (evidenced from highest activation levels in right prefrontal cortex) and their quality of code where there is an even split between high and low quality of code generated.

Figure 3 shows exemplar topography of brain activation for participant C0300. As can be seen in Fig. 3, the yellow color represents highest levels of brain activation that were observed in the right prefrontal cortex and has been related to negative emotions. Additionally, the high activity was in the Brodmann Area 45 [51], which has been associated with semantic tasks, such as semantic decision tasks (determining whether a word represents an abstract or a concrete entity) and generation tasks. This participant ranked three out of four in the analysis of code quality, which means that overall, the code produced the expected result with minimal error of a division by zero. In contrast as seen in Fig. 4, participant A200 exhibited positive emotions while the quality of the code was low. Relaxation seemed to have a contrary effect where participants who received the relaxation treatment seemed to exhibit negative motions.

Fig. 3
A chart of 6 images of brain activation for participant C0300. The views are of the top, back, left, bottom, front, and right sides of the brain. The maximum activity is visible on the right view of the brain. The least activity is visible at the back.

Topography of brain activation for Participant C0300

Fig. 4
A chart of 6 images of brain activation for participant A200. The views are of the top, back, left, bottom, front, and right sides of the brain. The maximum activity is visible on the left view of the brain. The least activity is visible on the right.

Topography of brain activation for Participant A200

6 Discussion

Emotions are not the only factor that influences the quality of code. Other important factors also have impact, such as developer’s skill, confidence, and motivation. In this preliminary study, we showed that positive emotions seem to favor the lower quality of code. This statement seems to be alienated with general literature indicating that stronger positive emotions are correlated with higher confidence in successful task completion and complicated with how high-performance goal orientation is related to stronger negative and weaker positive emotions [52]. While surprising, these preliminary results encourage more discussion and further investigation.

A deep discussion about the preliminary results led to potential research questions that can be explored in future work. For example, looking at the initial results, we can see that everyone who obtained the relaxation treatment had negative emotions, but some of them had good-quality code. This requires more investigation, keeping in mind the ones developing the code are humans that get affected by their emotional load. Some practitioners have found that happiness, a positive emotion, could lead to more code (quantity) while sadness, a negative emotion, leads to better and cleaner code (fewer mistakes) [53]. Some others have found that stress, anger, arrogance, and negative emotions lead to more code errors and in contrast motivation and confidence, positive emotions, lead to better code or code that is easy to read and maintain [54]. Therefore, the results we are getting so far might not be entirely contradictory with literature.

Our results do, however, indicate the need to perform a more in-depth analysis about the specific positive and negative emotions experienced by the participants to understand the relationship between emotions and quality of code. Likewise, due to the highly diverse nature of the participants, it is also possible that the effects were due to differences in expertise rather than the affective state. For this reason, we propose in future work to have a self-reporting evaluation of the level of expertise of the participants. Other potential confounds need to also be considered.

7 Future Work

As next steps, we propose a research roadmap to explore more emotional factors on the quality of code. First, we will design a separate study with around forty participants and one more complex programming code task with a prior self-report of expertise in the programming language to help avoid confounding factors affecting the results. We will analyze participants in different relaxation scenarios to measure the impact of relaxation. We will compute results to verify the correlation between emotions and code quality and reduce inconclusive results. Finally, we will introduce and evaluate the impact of HRV on emotions and code quality, as other literature has shown that this is a significant measure [55, 56]. In this roadmap, it is also essential to highlight that for the preliminary results, the relaxation device (Muse2) is not considered a research-grade tool. Due to the weighted discussion of the use of research-grade devices [57, 58], we may find a substitute for measuring the relaxed state for individuals.

8 Conclusion

In this paper, we show an experimental work-in-progress for determining the impact of emotions on the quality of code of novice programmers. We designed a study that non-invasively obtained EEG signals from seven participants while they worked on developing a programming task. According to the preliminary results, positive emotions may lead to lower-quality code. Further investigation with a larger sample size is needed to validate this direction.