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

注解如何影响Java代码可读性?

How do annotations affect Java code readability?

Eduardo Guerra, Everaldo Gomes, Jeferson Ferreira, Igor Wiese, Phyllipe Lima, Marco Gerosa, Paulo Meirelles

AI总结:

本文通过332人调查和15对Java代码片段,研究了代码注解对可读性的影响,发现开发者对注解提升可读性的看法存在分歧但无共识,为API设计提供了参考。

摘要:

背景:代码注解在编程语言中获得了广泛普及,使开发者能够将元数据附加到代码元素上以定义自定义行为。许多现代框架和API使用注解来减少集成代码的冗长性,并使其更靠近相应的代码元素。尽管有这些优势,从业者的轶事证据表明,注解可能会对代码可读性产生负面影响。目标:为了更好地理解这种影响,本文系统地研究了代码注解与代码可读性之间的关系。方法:在一项针对软件开发者的调查(n=332)中,我们展示了15对带有和不带有代码注解的Java代码片段。这些代码对是根据真实世界Java框架和API中使用的五类注解设计的。调查参与者在每对代码中选择他们认为更具可读性的代码片段,并回答了一个关于注解如何影响代码可读性的开放性问题。结果:对于所有类别的注解使用,参与者的偏好都很分散,表明参与者之间没有达成共识。即使按参与者的编程或注解相关经验进行划分,答案的分布也很分散。然而,一些参与者在所有类别中都表现出一致支持或反对注解的偏好,这可能表明这是一种个人偏好。我们对开放式问题的定性分析显示,参与者经常赞扬注解对设计、可维护性和生产力的影响,但对可理解性和代码清晰度表达了截然不同的观点。结论:软件开发者和API设计师在决定是否使用注解时可以参考我们的结果,从而了解到开发者对注解影响代码可读性的看法存在分歧。

英文摘要:

Context: Code annotations have gained widespread popularity in programming languages, offering developers the ability to attach metadata to code elements to define custom behaviors. Many modern frameworks and APIs use annotations to keep integration less verbose and located nearer to the corresponding code element. Despite these advantages, practitioners' anecdotal evidence suggests that annotations might negatively affect code readability. Objective: To better understand this effect, this paper systematically investigates the relationship between code annotations and code readability. Method: In a survey with software developers (n=332), we present 15 pairs of Java code snippets with and without code annotations. These pairs were designed considering five categories of annotation used in real-world Java frameworks and APIs. Survey participants selected the code snippet they considered more readable for each pair and answered an open question about how annotations affect the code's readability. Results: Preferences were scattered for all categories of annotation usage, revealing no consensus among participants. The answers were spread even when segregated by participants' programming or annotation-related experience. Nevertheless, some participants showed a consistent preference in favor or against annotations across all categories, which may indicate a personal preference. Our qualitative analysis of the open-ended questions revealed that participants often praise annotation impacts on design, maintainability, and productivity but expressed contrasting views on understandability and code clarity. Conclusions: Software developers and API designers can consider our results when deciding whether to use annotations, equipped with the insight that developers express contrasting views of the annotations' impact on code readability.

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

↑