Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Tuesday, 19 April 2016

Sniff from Scratch

Now we've got a release running on microbit it seems like a good idea to run through some basic tutorials on using the Microbit with Sniff, and also some ideas for introducing kids to text based coding using it.

We've now got quite a lot of experience of introducing kids to Sniff, and generally spend about an hour moving them from blocks to text before setting them loose on a real project. I've been to presentations on "moving from blocks to text", which talk about how difficult it is, and how they spend sessions before hand "laying groundwork", and how emphasising parallels between the two systems, but with Sniff its something you can get out of the way within a single session and move on to something more exciting.

We start with a quick revision of Scratch, and I usually ask them to write two programs:
  • ask for my name and then say hello using my name
  • count from one to ten
The idea isn't that either of these should be hard - the exact opposite in fact. Kids should be able to make both of these in Scratch in a few minutes. In fact many struggle with the second example - they're not comfortable using variables or even loops...

Once they've completed those tasks in Scratch, we introduce Sniff - emphasising that its basically just Scratch written down. Typicaly we've made a desktop shortcut to the "clickMe" file which fires up a copy of SniffPad, so they click on that. The first program I write would be something like

when start
.say "hello"

Here we example that start is green flag, and that the dot attaches shows that the "say" is linked to the "when". Everyone types this in, and we explain compiling and running on the computer by clicking the compile and run buttons.

Then we write

when start
.repeat 10
..say "hello"

Now most of the handwork is done! So get the to rewrite the "ask your name" example in Sniff. They should be able to do this with only a little support:

when start
.ask "what's your name?" and wait
.say join "hello " answer

Refer them back to the Scratch version which you should keep visible throughout this part of the session. Some of them might have used the say mmm for n secs block in Scratch, but simply explain it doesn't make sense in Sniff, as the messages get printed out one ofter the other, so once its printed its always visible.

Before they can tackle the second example you'll need to introduce a couple of concepts using an example like:

make x number

when start
.set x to 22
.say [x]

The important things to discuss are that we're making a variable 'x', but that its specifically going to be number. In this case its the number 22, but when we print it out we print out two two. Two and two makes 22, because we're printing out the words not the number. X is a number, but say prints out strings so we put it in square brackets to convert the numbers to a string. There's a bit more going on here, but this is sufficient to get  things rolling. For now all they really need to remember is to put square brackets around numbers when they print them out.

With this in place we're ready to ask them to write

make x number

when start
.set x to 1
.repeat 10
..say [x]
..wait 1 secs
..change x by 1

I've taken children as young as 8 through this, though normally they'd be a bit older. They make mistakes, but simply reassuring them that typing errors are just part of programming, and getting them to read the error messages to fix problems gets them up to speed quickly.

It takes about an hour to get this far depending on the group, and they're now programming in text.  We've covered enough Sniff that kids can now just carry over their Scratch experience, start having fun. From here they can start editing their code. Everyone wants to count to a million! It takes a while but actually sitting watching it count that high (WITHOUT the wait!) is actually an interesting idea - sure it takes a few minutes counting at full speed, but its a few minutes to realise how big a million really is. Try counting down, count in 2's....

We're programming in text, without any painful moments!

No comments:

Post a comment