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

用基于搜索的重构提高Scratch程序的可读性

Improving Readability of Scratch Programs with Search-based Refactoring

Felix Adler, Gordon Fraser, Eva Gründinger, Nina Körber, Simon Labrenz, Jonas Lerchenberger, Stephan Lukasczyk, Sebastian Schweikl

摘要:

像Scratch这样的基于块的程序设计语言作为初学者的入门语言越来越受欢迎。这些语言旨在以“修修补补”的方式使用,允许学习者和教师快速组装工作程序和游戏,但这通常会导致代码质量低下。这样的代码可能很难理解,更改它很容易出错,学习者可能会挣扎并失去兴趣。提高代码质量的一般解决方案是重构代码。然而,Scratch缺乏许多在重构用高级程序设计语言编写的程序时使用的通用抽象机制。为了改善Scratch代码,我们提出了一组原子代码转换,以优化可读性(1)重写控制结构和(2)简化脚本使用Scratch程序固有的并发性质。通过自动化这些转换,可以探索Scratch程序的可能变化空间。在本文中,我们描述了一个多目标的搜索为基础的方法,确定序列的代码转换,提高了可读性的一个给定的Scratch程序,因此形成重构。对1000个Scratch程序的随机样本的评估表明,生成的重构在70.4%的情况下降低了复杂性和熵,并且354个项目在至少一个度量方面得到了改进,而没有使任何其他度量变差。重构后的程序可以帮助新手和他们的老师改进他们的代码。

英文摘要:

Block-based programming languages like Scratch have become increasingly popular as introductory languages for novices. These languages are intended to be used with a "tinkering" approach which allows learners and teachers to quickly assemble working programs and games, but this often leads to low code quality. Such code can be hard to comprehend, changing it is error-prone, and learners may struggle and lose interest. The general solution to improve code quality is to refactor the code. However, Scratch lacks many of the common abstraction mechanisms used when refactoring programs written in higher programming languages. In order to improve Scratch code, we therefore propose a set of atomic code transformations to optimise readability by (1) rewriting control structures and (2) simplifying scripts using the inherently concurrent nature of Scratch programs. By automating these transformations it is possible to explore the space of possible variations of Scratch programs. In this paper, we describe a multi-objective search-based approach that determines sequences of code transformations which improve the readability of a given Scratch program and therefore form refactorings. Evaluation on a random sample of 1000 Scratch programs demonstrates that the generated refactorings reduce complexity and entropy in 70.4% of the cases, and 354 projects are improved in at least one metric without making any other metric worse. The refactored programs can help both novices and their teachers to improve their code.

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

↑