[論文レビュー] To Type or Not to Type? A Systematic Comparison of the Software Quality of JavaScript and TypeScript Applications on GitHub
本研究は、1600万行以上のコードを含む604のJavaScriptおよびTypeScriptのGitHubリポジトリ(それぞれ299件、305件)を対象に、SonarQubeおよびGitHub APIを用いてソフトウェア品質を比較した。TypeScriptはコード品質と理解しやすさを向上させるが、バグの発生頻度や修正時間の短縮には寄与しないことが判明した。驚くべきことに、JavaScriptプロジェクトはバグ関連のメトリクスが優れており、'any'型の使用を減らすことで品質が向上することが関連していた。
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.
研究の動機と目的
- TypeScript(TS)がJavaScript(JS)よりもソフトウェア品質を向上させるかどうかを、広く信じられているTSの利点を裏付ける実証的評価を行うこと。
- オープンソースリポジトリにおけるJSとTSアプリケーションの間で、大規模かつ直接的な実証的比較が不足しているという問題を解決すること。
- TSにおける静的型付けが、一般的な仮定とは反対に、バグの発生を減らし、修正を速くするかどうかを調査すること。
- 'any'型の使用がソフトウェア品質メトリクスに与える影響を検討すること。
- 実世界のデータを用いた言語選択とソフトウェア品質に関する今後の研究のための透明性があり再現可能な基盤を提供すること。
提案手法
- 1600万行を超えるコードを含む604のGitHubリポジトリ(JSが299件、TSが305件)からデータを収集し、プロジェクトサイズのバランスを保つことで、サイズ要因の影響を制御した。
- コード品質(1000行あたりのコードスモールの数)と認知的複雑性(1000行あたり)を、理解しやすさの代理指標として、SonarQubeを用いて測定した。
- コミットメッセージに「bug」と「fix」を含むキーワードを用いて、バグ修正コミットを自動検出。0.5%のランダムサンプル(500件)で妥当性を検証した。
- バグの解決時間を、Zhengら(2015年)の手法に従い、GitHub APIを用いて、イシュー作成から最終コメントまでの平均日数として測定した。
- ESLintにtypescript-eslintプラグインを組み合わせて、TSプロジェクトにおける'any'型の使用回数を数え、品質メトリクスへの影響を評価した。
- t検定やスピアマンのrhoなどの統計解析を用い、4つの品質フェイズにわたりJSとTSを比較し、'any'型使用と結果との相関を分析した。
実験結果
リサーチクエスチョン
- RQ1実世界のオープンソースプロジェクトにおいて、TypeScriptはJavaScriptよりも顕著に優れたコード品質と理解しやすさを示すか?
- RQ2TypeScriptはJavaScriptよりもバグの発生頻度(バグ修正コミット数)が低いと関連しているか?
- RQ3TypeScriptはJavaScriptよりも短いバグ解決時間を提供するか?
- RQ4TypeScriptにおける'any'型の使用は、ソフトウェア品質メトリクスとどの程度相関しているか?
- RQ5プロジェクトの複雑さや開発者の経験といった、JSとTSのバグ関連メトリクスの差異を説明する可能性のある交絡要因は存在するか?
主な発見
- TypeScriptアプリケーションでは、コードスモールの数がJavaScriptより18.5%少ない(p < 0.01)という顕著なコード品質の向上が確認された。
- TypeScriptプロジェクトは、認知的複雑性が顕著に低く(1000行あたり平均1.23 vs. 1.35)、コードの理解しやすさが向上していることが示された。
- JavaScriptプロジェクトでは、バグ修正コミットの比率が60%低い(0.126 vs. 0.206)という結果となり、コード量あたりのバグ修正コミット数が少ないことが示された。
- バグ解決時間は、TypeScriptプロジェクトが平均33.04日、JavaScriptプロジェクトが31.86日で、差はわずかであったが、TypeScriptの方が長かった。
- 'any'型の使用頻度は、コード品質および理解しやすさと顕著な相関(rho = 0.17–0.26)を示したが、バグの発生頻度とは相関しなかった。
- 相関は認められたが、効果量は小さく、'any'型の使用が品質に悪影響を与えるものの、その影響は限定的であり、バグ関連メトリクスの主な要因ではないことが示唆された。
より良い研究を、今すぐ始めましょう
論文の読解から最終レビューまで、研究時間を劇的に削減しましょう。
クレジットカード登録不要
このレビューはAIが作成し、人間の編集者が確認しました。