Snap!: A More Powerful Scratch

Image by Stephen Chin on Flickr
This language of the month is going to be a real Snap!
Scratch is the biggest blocks-based programming language out there. But it’s not the only one! Today we’ll take a look at a really cool and extremely powerful blocks based language called Snap!. (The exclamation mark is actually a part of the name, but I am also excited about this.)
Snap! looks a lot like Scratch:

Scratch is the biggest blocks-based programming language out there. But it’s not the only one! Today we’ll take a look at a really cool and extremely powerful blocks based language called Snap!. (The exclamation mark is actually a part of the name, but I am also excited about this.)
Snap! looks a lot like Scratch: but under the hood it’s actually pretty different. To show that, we’re going to do a version of the factorial function we showed in our article on recursion also in this issue.
If you remember, a factorial is a mathematical formula shown with an exclamation mark. The factorial 3! is calculated by multiplying all whole numbers between 3 and the number 1: 1 * 2 * 3 = 6. Therefore, 6 is the value of the factorial 3!.

And we can easily compare that to our Python code from the recursion article
def fact(n): if n > 1: return n*(fact(n-1)) else: return 1
Neat! You can see that these are almost exactly alike, except that in Snap! the way you get a value out of the function is with the report block instead of return like in Python.
If you’re an experienced Scratcher and you’re thinking “hey, there’s no ‘report’ block in Scratch?” you’d be right! In Scratch, only the built-in blocks can return values, like the blocks under operators. How would you write the factorial in Scratch? Well, here’s an example from the official Scratch wiki!

It’s doable but involves creating a list and having extra steps.
Okay, well what else is different in Snap!?
First, you can group sprites together yet have them move independently. Here’s a little example involving a cartoon tank with turret.
As we show in the screenshots below, we’ve made the turret a “child” of the tank body so that when the tank moves forward with the w key both the tank and turret sprites move forward, when the tank turns with the a and d keys then the turret turns as well, but when the turret turns with the left and right keys the tank doesn’t move.



Can you do this in Scratch? Well, like the factorial example the answer is “yes, but it’s harder”. That’s essentially my pitch about Snap! in general: it takes things you can do in Scratch but are really inconvenient and makes them a lot easier to do.
Here’s one last really little example of something convenient in Snap! but awkward in Scratch: for-loops! For-loops are how you do something repeatedly, but count how many times you’ve done the thing so far. Most programming languages have them but in Scratch you have to do something like

Meanwhile in Snap! you can instead just do this:

and you don’t even need to make a seperate variable as the loop counter! That’s only a little bit of savings if you have one for-loop, but if you’re writing physics-heavy code that needs multiple for-loops having to create variables for each is a real pain.
Lastly, here’s a simple example of the fractal Koch’s curve which is made just a little simpler by using variables that only exist inside a single script. In most programming languages these are called local variables.

This is also my promised example from our recursion article that I said you’d find here. Try making this yourself and running it! It’s pretty neat.
Now is Snap! nothing but an improvement over Scratch? Well, not really. It’s a little rougher around the edges. For example, if you’re wondering how to share your project you might be surprised to learn that you need to go under File then Open under the main menu and then select share. Oh yes, you need to “open” your project even if it’s open! There are other small things like this: quirks and inconveniences. But, in the end I think Snap! has a lot of cool features, the bulk of which could fill a college computer science class, and is a great next step beyond Scratch.
Learn More
The Snap! Manual
https://snap.berkeley.edu/snapsource/help/SnapManual.pdf
Racket/Scheme text-based programming language that inspired Snap!
Algorithmically creating embroidery
Factorials
https://factorialhr.com/number-function-factorial
Koch’s curve: snowflake
https://en.wikipedia.org/wiki/Koch_snowflake
Koch Snowflake
http://mathworld.wolfram.com/KochSnowflake.html
Factorials
https://www.mathsisfun.com/numbers/factorial.html
Build your own blocks
SNAP!
https://en.scratch-wiki.info/wiki/Snap!_(programming_language)
Factorial examples
https://www.shmoop.com/basic-statistics-probability/factorials-examples.html
Factorial video
Blocks-based coding
https://en.scratch-wiki.info/wiki/Block-Based_Coding
Fun Facts about factorials
Also In The April 2020 Issue

As students reach the age of 13 the importance of them understanding their rights and privacy online becomes crucial.

Pretend to be a spy with some of these fun python encryption methods!

This language of the month is going to be a real Snap!

The iDTech summer camp recently posted 102 questions. Here are a few with links to the full list.

Being well-read is essential in everything in life, and coding is no exception! Here are some book recommendations to make you a coding master.

The circus is in town, but they're missing one of their colourful balls. Let's make one for them!

Sundials were one of the first ways people kept track of time. But how did they work?

New to physical computing? MircoPython may be perfect or you!

It's project time! In this article we go over how the same processes used in big factories can be used to control a simple LED.

What do bubbles, pancakes, and spaghetti all have in common? They're all great for sorting!

Yee-ha! In the wild wild west of the internet, antivirus software is a must-have partner.

Exploring the concept of RAM and how it helps your MInecraft game run better.

Breaking down big problems into smaller ones is a great way to solve them. Let's see how recursion helps us do this!

How did this pale blue dot that we call Earth first begin? The answer is even more fascinating than imagined.

Have you ever wondered why your computer's mouse is called that? Well it all started with a fellow named Douglas and a block of wood...

How do you power devices at the top of mountains and the bottom of oceans? Let's find out!

Links from the bottom of all the April 2020 articles, collected in one place for you to print, share, or bookmark.

Interesting stories about computer science, software programming, and technology for April 2020.