Scratching a Visual Programming Itch11 Aug 2008
Scratch is a visual programming environment for creating interactive stories, animations, games, music and art. Scratch is object-oriented and organizes projects into objects called sprites. Sprites have a visual presentation called a costume, sound effects, and behavior implemented by user-defined scripts. Sprites interact with each other on the stage, another object that has sound effects, behavior, and a visual presentation called a background. At first glance, Scratch resembles Logo’s turtle graphics. But look deeper and one finds that Scratch’s design is deceptively clever and has the potential to change the way we write software.
One builds scripts visually by dragging and dropping Scratch’s three kinds of block:
- stacks control every aspect of a sprite, including its position, motion and presentation;
- reporters return values such as the position of the mouse or the value of a variable; and
- hats listen for events.
Scratch’s visual, modeless feedback shows where one can drop blocks and connect them to other blocks. For example, one builds sequences by connecting each subsequent block to the bottom of the previous block. Scratch encourages experimentation because, like all template and snap-together systems, Scratch produces no syntax errors. Scratch scripts may have semantic errors—one might not get the behavior one expects after joining blocks together—but one always produces a syntactically correct script. Scratch implements changes to scripts immediately—even while a script is still running.
Scratch seamlessly combines so many aspects of programming—sequence, selection, iteration, object-orientation and events—in a natural, obvious way, which is what a good user interface should do. Scratch isn’t perfect, of course. The method for starting a script isn’t easily discoverable, which is an important usability problem. I expected the green flag button to be the go button that would start a script. I then looked for a start or a play feature without success. After resorting to the documentation—the only time I needed to consult it—I learned that to start a script, one must double-click the script’s top block. I later learned that one can add a block to the top of a stack that will start the script when the green flag button is pushed. However, enabling new users to see the results of their efforts as soon as possible should be easy and discoverable.
Scratch has some nice documentation, especially the comprehensive but concisely written reference guide. Scratch’s video tutorials are also good for getting up to speed as quickly as possible, even though only the stimulation-deprived would appreciate a repeat viewing of the introduction video’s hyperactive presenter.
Where Scratch stands out is its potential for improving the way we write code, just like Visual Basic’s visual interface building approach stood out on its release. Imagine writing C, Python or Java by dragging and dropping blocks: with no syntax errors, compilation would become a background object-code-generating task. Combining visual coding with visual interface building would produce an even more powerful development environment.