arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2203.11115cs.SE
收藏

用还是不用类型?GitHub上JavaScript与TypeScript应用软件质量的系统性比较

To Type or Not to Type? A Systematic Comparison of the Software Quality of JavaScript and TypeScript Applications on GitHub

Justus Bogner, Manuel Merkel

AI总结:

本研究通过挖掘604个GitHub项目对比JS与TS的软件质量,发现TS代码质量和可理解性更优,但缺陷倾向性更高、修复时间更长,减少any类型使用可优化多数质量指标。

摘要:

JavaScript(JS)是最流行的编程语言之一,广泛应用于Web应用甚至后端开发。然而,由于其动态特性,JS应用常被认为软件质量较差。作为JavaScript的类型安全超集,TypeScript(TS)提供了应对这一问题的特性。但目前尚无足够的实证证据能广泛支持“TS应用比JS应用展现出更优软件质量”这一说法。\n 因此我们开展了一项仓库挖掘研究,基于604个GitHub项目(299个JS项目、305个TS项目),总代码量超1600万行,收集了软件质量的四个维度:a)代码质量(每千行代码的代码坏味数量);b)代码可理解性(每千行代码的认知复杂度);c)缺陷倾向性(缺陷修复提交占比);d)缺陷解决时间(缺陷议题的平均开放时长)。针对TS项目,我们还统计了忽略类型安全的`any`类型的使用频率。\n 分析结果显示,TS应用的代码质量和可理解性显著优于JS应用。但与预期相反的是,我们样本中TS项目的缺陷倾向性和缺陷解决时间并未显著低于JS项目:TS的平均缺陷修复提交占比高出60%以上(JS为0.126,TS为0.206),且TS项目修复缺陷平均需要多花一天以上的时间(JS为31.86天,TS为33.04天)。此外,减少TS应用中`any`类型的使用,与除缺陷倾向性之外的所有指标均显著相关(斯皮尔曼相关系数rho在0.17到0.26之间)。\n 我们的研究结果表明,与JavaScript相比,TypeScript在避免缺陷方面的感知正向影响可能比假设的更为复杂。虽然使用TS似乎有一定益处,但它并不会自动带来更少的缺陷,也不会让缺陷更容易修复。不过该领域仍需更多研究,尤其是关于项目复杂度和开发者经验的潜在影响方面。

英文摘要:

JavaScript (JS) is one of the most popular programming languages, and widely used for web apps and even backend development. Due to its dynamic nature, however, JS applications often have a reputation for poor software quality. As a type-safe superset of JavaScript, TypeScript (TS) offers features to address this. However, there is currently insufficient empirical evidence to broadly support the claim that TS apps exhibit better software quality than JS apps. We therefore conducted a repository mining study based on 604 GitHub projects (299 for JS, 305 for TS) with over 16M LoC and collected four facets of software quality: a) code quality (# of code smells per LoC), b) code understandability (cognitive complexity per LoC), c) bug proneness (bug fix commit ratio), and d) bug resolution time (mean time a bug issue is open). For TS, we also collected how frequently the type-safety ignoring `any` type was used. The analysis indicates that TS apps exhibit significantly better code quality and understandability than JS apps. Contrary to expectations, however, bug proneness and bug resolution time of our TS sample were not significantly lower than for JS: mean bug fix commit ratio was more than 60% larger (0.126 vs. 0.206), and TS projects needed on average more than an additional day to fix bugs (31.86 vs. 33.04 days). Furthermore, reducing the usage of the `any` type in TS apps was significantly correlated with all metrics except bug proneness (Spearman's rho between 0.17 and 0.26). Our results indicate that the perceived positive influence of TypeScript for avoiding bugs in comparison to JavaScript may be more complicated than assumed. While using TS seems to have benefits, it does not automatically lead to less and easier to fix bugs. However, more research is needed in this area, especially concerning the potential influence of project complexity and developer experience.

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

↑