Coding with Kids: From Robbie the Robot to Lego Boost
Posted | Reading time: 4 minutes and 6 seconds.
My Kids are pretty much required to do something related to sensors/electronics/code/exploding diamonds (blog post follows) whenever they want to play with their dad. Luckily, they share my interest and their eyes start to gloom whenever a new Arduino is brought by the postman.
Connecting wires and creating circuits, or running some experiments, is easy for kids; coding however not so much. The lingua franca in software development is English, my kids’ first language is German. Also, even though they can read/write, they are still pretty busy with adding letters to words. Combining that with logic is a little too much for them (still).
Also, when we started to look into that direction, reading was far away, as they were only 3 years old.
Thus, to give them a first idea on developing software I did what a software developer does - I wrote a program.
My kids, 3 to 5 - Meet Robbie The Robot
Robbie the robot is a game I developed when my kids were much younger, 2 and 3 years old. They were far from getting anything from scratch, and I wanted something they can use in the real world and do the same online. Robbie the Robot was my take on that.
To make sure that overall idea would work, I started out with an offline version which was more of a board game. The kids had to place actions like “move up” on an action deck, the goal was to reach the kitten with as few actions as possible.
My kids were pretty happy with it, so I create an online version as well.
The basic idea is simple. A robot (Robbie) has to get to an unnamed kitten. To do that, the robot can take in a number of commands. Once the commands are set, they can be executed. There are no limits on how many commands can be used, and at the end of the commands, the robot will always stay in the last position. There are rewards for fewer commands/executions though, in the form of stars. You can play it right here: https://robbie-the-robot.herokuapp.com/.
It’s mobile friendly, and with touch and drag & drop it was pretty intuitive for my kids.
Inside robbie the robot
The program itself internally translates the commands to a programming language. If you click on “move up”, the program will translate it internally into the statement
then move in the direction up
.then
publishes the commandmove
in the current context with a named argumentdirection
ofup
.
The subscriber looks kinda like this:
the robot is a Robot (
the position is a Coordinate (
the row is 2
the column is 2
)
)
when move in the direction (
in case our direction (
up (
our robot.position.row - 1
)
down (
our robot.position.row + 1
)
// other directions...
)
notify movement of our direction
)
then move in the direction up
export robot
The language is pretty verbose and trying to avoid shorthand syntax that would be confusing for beginners. Scoping is done via
()
, and not with angel brackets which seem to be more frightening to first-coders too.Types can be declared inline, i.e. there is no requirement for a
Robot
to exist before the instancerobot
was created. Inline declared types are open, if another caller would create a robot with additional fields those fields would be added to allRobot
instances. Types cannot have functions but are only data.
when
creates a subscriber for themove
command inside the scope of the process, we called it with the statementthen move
above. An unlimited amount of subscribers can be created for a single command.
notify
publishes commands as well, but not only to the running process but also to the outside world. The same happens to anexport
on the top level (otherwise it would be in the current scope). If you were to run this in javascript, you can subscribe to this notification with this code:
const result = new Machine()
.subscribe("movement", (direction) => console.log(`Moved in the direction ${direction}!`))
.run(new ParsingService(WordService.create(yourCode)).parse());
console.log(JSON.stringify(result));
The output of this would be:
Moved in the direction up!
{ position: { row: 1, column: 2 }}
The idea behind this language was to give my kids an easy language to start with when they come to age. The syntax parsing/AST generation is also to make cheating in the browser a little harder - otherwise, someone with knowledge of the developer tools can easily change variables like the number of executed commands. Now, every command by the user is executed separated from the react application that renders it.
As of now, to be honest, the language is not of much use other than the learnings I had from creating it. We’ll see if eventually, it might become more useful in the future - Robbie the Robot has a feature backlog that would allow it to consume “sensory data” too, which would enable programming the robot to find it’s route independently.
As my kids got older, they eventually outgrew robbie though. One thing they are into now is Lego. This is when we took the next challenge
My kids at 5 to 6: Lego Boost
Lego Boost is the starter set of the digital lego world. It comes with a brick that can be connected via bluetooth to a tablet and mobile phone, and controlled via App.
We