Scratch is an intro programming language for kids. (Like Logo was, but way better). When I saw edx was offering an Intro to Scratch course, I decided to take that opportunity to learn it. It’s cute and a great starting point for programming. It offers the ability to write a really simple program. But it also lets you learn about lists and event handling.
For my final project for the course, I wrote a two player game of tic tac toe. Here’s what jumped out me when doing the project.
- Multiple sprites and event handling (broadcast/wait)
- Key and mouse listeners
- Functions (custom blocks)
- Logic (loops/conditionals)
What I missed
As a programmer used to full fledged (non-simplified) programming languages and environments, there are a few things I missed.
- Real 2D arrays. I used a string in a 1D array and getting the character at each position.
- Grouping parens. I wanted to write something equivalent to (a==b and b==c) or (d==e and e=f)). While this possible to do in Scratch, it uses the layering of blocks rather than parens so is hard to read. I wound up splitting into two if statements.
- Local variables. There are “sprite only” variables, but they still clutter up the namespace and make it hard to find the variable you need at a given point.
- elsif/elseif. Yes, you can nest if/else statements. But harder to read.
- I didn’t work on the program for two weeks and went back to it. I really wanted “search” functionality to find uses of a variable or where a custom block was defined.
- I miss having rollback/history for changes. When the program “used to work” and then doesn’t, it’s hard to figure out what you accidentally drag and dropped.
Other interesting points
- Scratch uses 1 based indexes. Makes sense for a first language to break with the odd tradition practically ever other language uses. But feels weird.
- There is no distinction between character and numeric types. This meant I could get a character out of a string and use it as a loop index.
- Regular mode and turbo mode allows you to control the speed the sprites draw. This is useful when drawing things like circles. When coding, turbo mode is enabled with Edit > Turbo Mode. When in the play view, it is enabled by holding shift when pressing the green flag to start. I wish there were a way to either “save” with turbo mode or turn turbo mode on in the code.
- There are blocks for length of on list and and operator/string. Calling the wrong length block on a list doesn’t fail, but does return unexpected data.
- I have some duplication in drawO vs draw X and if statements when drawing the grid. I could put in variable but didn’t feel like it was clearer that way. Similarly in calculating if the a player won.
- I also have duplication in “when I receive move” if statements. I got lazy when drawing the line.