arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2206.08849cs.SEcs.PL
收藏

JavaScript项目中函数式编程启发的结构缺陷倾向性研究

On the Bug-proneness of Structures Inspired by Functional Programming in JavaScript Projects

Fernando Alves, Delano Oliveira, Fernanda Madeiral, Fernando Castor

摘要:

受函数式编程启发的语言构造已经进入了大多数主流程序设计语言。许多研究人员和开发人员认为,这些结构导致程序更简洁,可重用,更容易理解。然而,很少有研究调查在主流程序设计语言中使用它们的影响。本文量化了JavaScript中与函数式编程相关的四个概念:递归、不变性、惰性求值和函数作为值。我们专注于JavaScript程序,因为这些概念中的一些在语言中的可用性,因为它的灵感来自函数式程序设计语言,以及它的流行。我们挖掘了91个GitHub存储库(2200多万个),其中大部分是用JavaScript编写的(超过50%的代码),从静态和时间角度衡量这些概念的使用情况。我们还测量了错误修复提交删除这些概念的可能性(这将暗示错误倾向)以及它们与代码注释的存在(这将暗示代码难以理解)的关联。我们发现,这些概念被广泛使用(每46.65个,43.59%的人)。此外,高阶函数、不变性和惰性求值相关结构的使用在这些年来一直在增长,而递归、回调和承诺的使用却在减少。我们还发现统计证据表明,除了与不变性相关的结构之外,删除这些结构在bug修复提交中比在其他提交中更不常见。此外,它们的存在与评论大小无关。我们的研究结果表明,函数式编程的概念是很重要的开发人员使用多范式语言,他们的使用不会使程序更难理解。

英文摘要:

Language constructs inspired by functional programming have made their way into most mainstream programming languages. Many researchers and developers consider that these constructs lead to programs that are more concise, reusable, and easier to understand. However, few studies investigate the implications of using them in mainstream programming languages. This paper quantifies the prevalence of four concepts typically associated with functional programming in JavaScript: recursion, immutability, lazy evaluation, and functions as values. We focus on JavaScript programs due to the availability of some of these concepts in the language since its inception, its inspiration from functional programming languages, and its popularity. We mine 91 GitHub repositories (22+ million LOC) written mostly in JavaScript (over 50% of the code), measuring the usage of these concepts from both static and temporal perspectives. We also measure the likelihood of bug-fixing commits removing uses of these concepts (which would hint at bug-proneness) and their association with the presence of code comments (which would hint at code that is hard to understand). We find that these concepts are in widespread use (1 for every 46.65 LOC, 43.59% of LOC). In addition, the usage of higher-order functions, immutability, and lazy evaluation-related structures has been growing throughout the years for the analyzed projects, while the usage of recursion and callbacks & promises has decreased. We also find statistical evidence that removing these structures, with the exception of the ones associated to immutability, is less common in bug-fixing commits than in other commits. In addition, their presence is not correlated with comment size. Our findings suggest that functional programming concepts are important for developers using a multi-paradigm language, and their usage does not make programs harder to understand.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑