The incorporation and adaptation of style guides play an essential role in software development, influencing code formatting, naming conventions, and structure to enhance readability and simplify maintenance. However, many of these guides often lack empirical studies to validate their recommendations. Previous studies have examined the impact of code styles on developer performance, concluding that some styles have a negative impact on code readability. However, there is a need for more studies that assess other perspectives and the combination of these perspectives on a common basis through experiments. This study aimed to investigate, through eye-tracking, the impact of guidelines in style guides, with a special focus on the PEP8 guide in Python, recognized for its best practices. We conducted a controlled experiment with 32 Python novices, measuring time, the number of attempts, and visual effort through eye-tracking, using fixation duration, fixation count, and regression count for four PEP8 recommendations. Additionally, we conducted interviews to explore the subjects' difficulties and preferences with the programs. The results highlighted that not following the PEP8 Line Break after an Operator guideline increased the eye regression count by 70% in the code snippet where the standard should have been applied. Most subjects preferred the version that adhered to the PEP8 guideline, and some found the left-aligned organization of operators easier to understand. The other evaluated guidelines revealed other interesting nuances, such as the True Comparison, which negatively impacted eye metrics for the PEP8 standard, although subjects preferred the PEP8 suggestion. We recommend practitioners selecting guidelines supported by experimental evaluations.
翻译:风格指南的采纳与适应在软件开发中扮演着关键角色,其通过影响代码格式、命名规范和结构来提升可读性并简化维护工作。然而,多数此类指南往往缺乏实证研究以验证其建议的合理性。既往研究已探讨了代码风格对开发者绩效的影响,并指出某些风格会对代码可读性产生负面影响。但当前仍需更多研究,通过实验评估其他视角以及这些视角在共同基础上的综合效应。本研究旨在通过眼动追踪技术,探究风格指南中各项规范的影响,尤其聚焦于以最佳实践著称的Python PEP8指南。我们开展了一项受控实验,招募32名Python新手,通过眼动追踪测量其完成任务的时间、尝试次数及视觉努力程度,具体采用注视时长、注视次数和回视次数四项指标,针对PEP8的四项建议进行分析。此外,我们通过访谈深入探究受试者在程序理解中遇到的困难及其风格偏好。结果显示,未遵循PEP8“运算符后换行”规范的代码片段中,眼动回视次数在应应用该标准的场景下增加了70%。多数受试者更倾向于符合PEP8规范的代码版本,部分受试者认为运算符左对齐的组织方式更易于理解。其他被评估的规范亦揭示出值得关注的细节,例如“真值比较”规范虽受试者偏好PEP8建议,但其眼动指标却显示对PEP8标准产生了负面影响。我们建议实践者优先选择经过实验评估支持的编码规范。