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.
Refactoring for Novices in Java: An Eye Tracking Study on the Extract vs. Inline Methods
State University of Paraíba (UEPB)(帕拉伊巴州立大学);Federal University of Campina Grande (UFCG)(坎皮纳格兰德联邦大学);Federal University of Alagoas (UFAL)(阿拉戈阿斯联邦大学);University of Brasília (UnB)(巴西利亚大学);Pontifical Catholic University of Rio de Janeiro(里约热内卢天主教大学)
Type4Py: Practical Deep Similarity Learning-Based Type Inference for Python
Delft University of Technology(代尔夫特理工大学);Facebook(脸书)
动态语言,如Python和JavaScript,用静态类型换取开发人员的灵活性和生产力。缺少静态类型会导致运行时异常,并且是IDE支持薄弱的主要因素。为了缓解这些问题,PEP 484为Python引入了可选的类型注释。由于将类型改装到现有代码库是容易出错且费力的,因此已经提出了基于机器学习(ML)的方法来实现基于现有的部分注释的代码库的自动类型推断。然而,以前的基于ML的方法是在人类提供的类型注释上训练和评估的,这可能并不总是合理的,因此这可能限制了现实世界使用的实用性。在本文中,我们提出了Type4Py,一个基于深度相似性学习的分层神经网络模型。它学会在高维空间中区分相似和不相似的类型,从而产生类型集群。参数、变量和返回值的可能类型可以通过最近邻搜索来推断。与以前的工作不同,我们在经过类型检查的数据集上训练和评估了我们的模型,并使用平均倒数排名(MRR)来反映用户感知的性能。所获得的结果表明,Type4Py实现了77.1%的MRR,这比最先进的方法Typilus和TypeWriter分别大幅提高了8.1%和16.7%。最后,为了帮助开发人员改进类型,我们发布了一个Visual Studio Code扩展,它使用Type4Py为Python提供基于ML的类型自动完成。