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.
翻译:Scratch 等基于街区的编程语言越来越受欢迎,成为新手的入门语言。这些语言的用意是使用一种“牵引”方法,使学习者和教师能够快速组合工作程序和游戏,但这往往导致代码质量低。这种代码很难理解,改变容易出错,学习者可能会挣扎和失去兴趣。提高代码质量的一般解决办法是重新构筑代码。然而,Scratch 缺乏许多用于重构以更高编程语言编写的程序所用的共同抽象机制。为了改进拼写代码,我们因此提出一套原子代码转换以优化可读性,方法是:(1) 重写控制结构,(2) 简化脚本,使用Scratch 程序固有的并行性质。通过这些转换的自动化,可以探索Scratch 程序可能的变换空间。在本文中,我们描述了一种多目标的基于搜索的方法,确定代码转换的顺序,从而改进了某个特定编程的编程的可读性,因此,我们因此提出了一套最不易读化的代码。 在一个随机样本中,对一个更糟糕的编程的编程中,对一个重的编程进行评方案进行了评估。