Alice 3: Visualize Concurrent Code in Action
Carnegie Mellon University announced the beta release of Alice 3 in 2009. Almost two years later, this educational development environment is still in beta. However, the latest version 3.0.0.2.10 is pretty stable and provides visual tools to teach students to think parallel.
It is easy to conceptualize that you need code running in parallel in order to show many actors performing actions concurrently. Think about two hares running a race. Which is the most natural way of coding the desired behavior for each hare? Figure 1 shows two instances of the Hare class on a grassy background as shown by the Alice 3 scene editor and its starting camera view.
Each hare might have different energy and speed values. Each hare has to run using its own speed value while considering its remaining energy. In addition, each hare wants to win the race, and therefore, it will consider its rival's position to determine its necessary effort in each stage of the race. If you think in object-oriented code, each hare will use its own properties to animate its body and to advance positions in the 3D space.
The main code has to run some sort of loop in order to update the position for each hare. If each hare has a method that encapsulates the algorithm that updates its position, you might want to call the method for each hare in parallel. Think about real life: Each real hare would execute actions in parallel because the real world doesn't have a sequential execution. Thus, if you want to create animations that represent situations of the real world in virtual environments, the easiest way to code them is by creating blocks of code that run in parallel.
Alice 3 provides three blocks that allow you to organize statements to run in parallel (see Figure 2):
- Do together: Run many statements or blocks of statements in parallel.
- Each in _ together : For each object in the specified array of objects, run many statements or blocks of statements in parallel.
- Do in thread: Run many statements in an independent thread that will execute concurrently with the main thread and other threads.
Alice 3 allows you to combine the aforementioned three blocks with other blocks that organize the sequential execution of statements. Thus, you can use a do together block to run two do in order blocks in parallel. Figure 3 shows a simple example of two do in order blocks that create sequential code that will run in parallel because they are included in a do together block. With just a few clicks, you can make two hares move toward the camera and orient to the sunlight in parallel.
You can run code in different threads and you can teach students to think parallel with Alice 3. Alice 3 doesn't include synchronization mechanisms and The Sims module still has a few significant bugs. However, once students learn the difference between sequential and parallel executions with actors moving on the rendered scenes, it is easier to understand more complex threads.
My wife has been using Alice 3 during the last year in the classroom, and she has been working with colleagues on the design of simple programs that run code in parallel by using different threads. (and yes, of course, she helped me in writing this post). I've been amazed with the results. Students learn to create and organize concurrent code because Alice 3 makes it easy to mix parallel code with sequential code. Students understand the complexities of parallelized code, visualize the problems, and can switch to more complex programming languages. If you want to create virtual worlds with actors performing actions in parallel, you will love Alice 3.
There are dozens of excellent books about Alice, and a couple bear mentioning here. Learning to Program with Alice, by Wanda P. Dann, Stephen Cooper, and the late Randy Pausch (Prentice Hall, 3rd Edition, 2011), is a must read if you want to understand the Alice programming language; and the book includes a sneak peek at Alice 3. The Alice 3 Cookbook, by Vanesa S. Olsen (Packt Publishing, 2011) includes dozens of exercises that combine sequential execution with parallel execution for Alice 3. As a disclaimer, I must note that Vanesa is my wife.

