An Investigation of confusing code patterns in JavaScript

Evolving software is particularly challenging when the code has been poorly written or uses confusing idioms and language constructs, which might increase maintenance efforts and impose a significant cognitive load on developers. Previous research has investigated possible sources of confusion in pr...

Full description

Saved in:
Bibliographic Details
Published inThe Journal of systems and software Vol. 203; p. 111731
Main Authors Torres, Adriano, Oliveira, Caio, Okimoto, Márcio, Marcílio, Diego, Queiroga, Pedro, Castor, Fernando, Bonifácio, Rodrigo, Canedo, Edna Dias, Ribeiro, Márcio, Monteiro, Eduardo
Format Journal Article
LanguageEnglish
Published Elsevier Inc 01.09.2023
Subjects
Online AccessGet full text
ISSN0164-1212
1873-1228
DOI10.1016/j.jss.2023.111731

Cover

More Information
Summary:Evolving software is particularly challenging when the code has been poorly written or uses confusing idioms and language constructs, which might increase maintenance efforts and impose a significant cognitive load on developers. Previous research has investigated possible sources of confusion in programs, including the impact of small code patterns (hereafter atoms of confusion) that contribute to misunderstanding the source code. Although researchers have explored atoms of confusion in code written in C, C++, and Java, different languages have different features, developer communities, and development cultures. This justifies the exploration of other languages to verify whether they also exhibit confusion-inducing patterns. In this paper we investigate the impact of atoms of confusion on understanding JavaScript code—a dynamically typed language whose popularity is growing in the most diverse application domains. We present the results of a mixed-methods research comprising a mining software repositories (MSR) study, two experiments, and a set of interviews with practitioners. Our MSR effort shows that atom candidates are frequent and used intensively in 72 popular open-source JavaScript projects: four atom candidates appear in 90% of them and two of them occur more than once for every 100 lines of code. This helps motivate the other three studies. The results of both experiments suggest that two code patterns that have been previously observed to confuse C programmers also confuse JavaScript programmers: the comma operator and assignments being used as values. In addition, some code patterns, such as omitted curly braces and change of literal encoding, have caused confusion in participants in one of the experiments. We discover that some JavaScript-specific elements, such as automatic semicolon insertion and object destructuring, also have the potential to cause confusion. For all these cases effect sizes were either medium or high. The interviews we conducted indicate other constructs and idioms that merit investigation in the future. •Our study investigates the impact and prevalence of atoms of confusion in JavaScript.•Some atoms proved to confuse C programmers also confuse JavaScript programmers.•JavaScript-specific atom candidates also have the potential to confuse developers.•Examined code patterns are frequent and used intensively in JavaScript projects.
ISSN:0164-1212
1873-1228
DOI:10.1016/j.jss.2023.111731