The quality of scientific code is a critical concern for the research community. Poorly written code can result in irreproducible results, incorrect findings, and slower scientific progress. In this study, we evaluate scientific code quality across three dimensions: reproducibility, readability, and reusability. We curated a corpus of 518 code repositories by analyzing Code Availability statements from all 1239 Nature publications in 2024. To assess code quality, we employed multiple methods, including manual attempts to reproduce Jupyter notebooks, documentation reviews, and analyses of code clones and mutation patterns. Our results reveal major challenges in scientific code quality. Of the 19 notebooks we attempted to execute, only two were reproducible, primarily due to missing data files and dependency issues. Code duplication was also common, with 326 clone classes of at least 10 lines and three instances found among 637 of the 1510 notebooks in our corpus. These duplications frequently involved tasks such as visualization, data processing, and statistical analysis. Moreover, our mutation analysis showed that scientific notebooks often exhibit tangled state changes, complicating comprehension and reasoning. The prevalence of these issues -- unreproducible code, widespread duplication, and tangled state management -- underscores the need for improved tools and abstractions to help science build reproducible, readable and reusable software.
翻译:科学代码质量是研究界关注的核心问题。编写低劣的代码可能导致结果不可复现、结论错误以及科学进展缓慢。本研究从可复现性、可读性和可重用性三个维度评估科学代码质量。通过分析2024年《自然》期刊所有1239篇出版物中的代码可用性声明,我们构建了包含518个代码仓库的语料库。为评估代码质量,我们采用多种方法:手动尝试复现Jupyter笔记本、文档审查,以及代码克隆与变异模式分析。研究结果揭示了科学代码质量面临的重大挑战:在尝试执行的19个笔记本中,仅有两个具备可复现性,主要原因在于数据文件缺失和依赖性问题。代码重复现象同样普遍,在1510个笔记本构成的研究语料库中,637个笔记本存在至少包含10行代码及3个实例的326个克隆类群。这些重复代码频繁涉及可视化、数据处理和统计分析等任务。此外,变异分析表明,科学笔记本常呈现状态变更混乱的特征,增加了理解与推理的难度。此类问题的普遍存在——不可复现代码、广泛重复与状态管理混乱——凸显出亟需改进工具与抽象方法,以助力科学界构建可复现、可读且可重用的软件。