playing with scratch

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.

Components used

  1. Multiple sprites and event handling (broadcast/wait)
  2. Key and mouse listeners
  3. Functions (custom blocks)
  4. Logic (loops/conditionals)
  5. Lists
  6. Comments

What I missed

As a programmer used to full fledged (non-simplified) programming languages and environments, there are a few things I missed.

  1. Real 2D arrays. I used a string in a 1D array and getting the character at each position.
  2. 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.
  3. 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.
  4. elsif/elseif. Yes, you can nest if/else statements. But harder to read.
  5. 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.
  6. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.

Refactoring?

  1. 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.
  2. I also have duplication in “when I receive move” if statements. I got lazy when drawing the line.

 

Leave a Reply

Your email address will not be published.