Hello Ruby — teaching children to write code

Ruby, with a wise penguins, a green robot, and lonely snow leopard. Drawing by Linda Liukas.
Ruby, with a wise penguin, a green robot, and lonely snow leopard. Drawing by Linda Liukas.

A few years ago I remember reading a book advocating that all school children should be taught to program computers. It’s a great discipline for anyone, the author argued, especially children. It teaches patience, persistence, problem-solving, the importance of planning; it can help children improve their maths and logical thinking, and it’s hugely rewarding to see something that you’ve been working on suddenly come to life and work as expected. I wish I still had that book.

A couple of stories about teaching children to write code have caught my eye over the last few weeks.

Year of code

On Newsnight, broadcast on BBC 2 on Wednesday 5 February 2014, Jeremy Paxman presented an article about the Year of Code campaign, an independent, non-profit campaign to encourage people across the country to get coding for the first time.

One of my first experiences of using a computer was in primary 7 when the headteacher brought in a Commodore VIC-20. I took computer studies in high school through to higher level, and half of my university application form was to study computer science (the other half to study divinity, which is what I ended up doing).

I loved coding as a kid. My friends and I would gather around each others home computers, whether a Commodore 64, ZX Spectrum, or BBC B, and we’d design or amend games and programs together.

People are often amazed when I say that I taught myself the web skills that I use now in my day-to-day job in the web team at the University of St Andrews. Except, that’s not entirely true: I do have the experience of those seven or eight years of coding on 8-bit computers as a child and as a teenager. That was a brilliant headstart.

It seems that today ‘computer studies’ in school is more about learning how to be a consumer and user of existing software (how to use Microsoft Word, Microsoft Excel, Microsoft PowerPoint) rather than creating your own software.

I was appalled to learn how some youngsters are being ‘taught’ to code in schools today. A couple of months ago a friend of mine phoned me asking for my help. Her daughter is studying computer studies and she is being ‘taught’ to code using… Adobe Flash!? And I say ‘taught’ because it sounds like she and her classmates were essentially shown the application, given a book and told to get on with it. It sounded like the teacher didn’t know to code either.

Compare that with my own experience in the mid-80s. I had three years of hands-on coding BASIC and machine code by someone who understood how computers worked and what the programs were being asked to do, who could tell a CPU from an ALU from a RAM. And then in my sixth year a group of six of us took ourselves off and taught ourselves Pascal in what would otherwise have been free periods for us in our timetable.

We need to be teaching our children to code so that they can contribute to the next generation of computer applications. Technology has never been more exciting than it is now. I remember my dad (who worked in the electronics and communications industry, who delivered the Faraday lecture on fibre optic communications) telling me in the early 80s that one day televisions would be so thin we could hang them on our walls. It seemed like a space-age dream, it is now reality.

My main concern about that Newsnight piece, however, is the interview with Lottie Dexter, the executive director of Year of Code (at 5′ 32″ on the video).

It’s not her admission that she herself cannot code—good on her for admitting that straight away, and even better that she is committing herself to learning this year, alongside those she is encouraging to take it up. No, it’s comments like,

“You can do very little in a short space of time. For example, you can actually build a website in an hour […] completely from scratch.”

Well, you know. That’s true. But it’s not going to be a particularly good one, if this is your first. Erm… practice?

Paxman then asks her, “How long does it take to teach to code?”

“Well, I think, you can pick it up in a day.”

My heart sank. I was speechless. In trying to make coding sound more accessible she immediately undervalued programmers everywhere. It really isn’t quite that simple. I’m going to be bold here and state: you simply cannot learn enough about programming in one day to be competent enough to teach it. Is it not comments like that that result in school pupils being ‘taught’ how to program using Adobe Flash?

Hello Ruby

Hello Ruby, a Kickstarter project by Linda Liukas
Hello Ruby, a Kickstarter project by Linda Liukas

Which is why projects such as Linda Liukas’s Hello Ruby are so exciting.

Linda, a founder of Rails Girls, wants to create a children’s book that teaches programming fundamentals through stories and child-friendly activities.

She asked for US $10,000, as I write her total is at US $336,203. (There are currently three days left to get involved.)

I think it’s a hugely exciting project. This is what Linda has to say about it:

Ruby is a small girl with a huge imagination. She stomps and stumbles around her own little world while her dad is traveling. On her adventures, Ruby makes friends with the lonely Snow Leopard, visits castles made of windows, and solves problems with the wise penguins. She bakes gingerbreads with the green robots and throws a garden party with… well, if you like to hear the rest of the story, I need your help.

Ruby’s world is an extension of the way I’ve learned to see technology. It goes far beyond the bits and bytes inside the computer. This is the story of what happens between the ones and zeros, before the arrays and the if/else statements. The book and workbook are aimed for four to seven year olds.

I believe stories are the most formative force of our childhood. Everyone has a book that made the world seem beautiful and full of possibility. My book is about little Ruby.

It’s due out in August. I’ll report back when I receive my copy, and we’ll see how Reuben, Joshua and Isaac engage with it.

Installing Node.js on Windows 8

Command line showing node installation
Command line showing node installation

Over the last month I’ve slowly begun exploring Node.js and so far I’m really liking what I’m seeing.

In a nutshell, Node.js (or simply Node) allows you to write server-side JavaScript. In other words, until now JavaScript is normally written to be run within a web browser, on a web page. Node instead allows you to write JavaScript applications that run outside the browser or via the command line.

Node uses Google Chrome’s JavaScript engine, called V8. Perfect if you are used to writing JavaScript for your browser.

This means that you can now write applications, or ‘modules’ that can do stuff outside the scope of a web browser. For example, you could write a simple web server in Node or — and this is what I want to use it for — you could write modules to manipulate web code and automate certain processes related to web development.

Installing Node.js

Installation on Windows 8 could not have been any more straight forward:

  1. Visit nodejs.org
  2. Click the “install” button to download the installer.
  3. Run the installer (make sure you tell the installer to add references to your PATH system variables).
  4. Reboot your PC.
  5. Er…
  6. That’s it!

Command line

Almost everything you do with Node is via a command line. You can use either the standard Windows cmd.exe or Windows PowerShell (or, indeed, any other command line interpreter (CLI) you may have installed).

To use the standard Windows command line:

  1. Press Win + R (for Run)
  2. Type: CMD
  3. Click OK

Checking that Node is installed is as simple as opening a command line and typing:

node --version

Hit enter and you’ll get a result, something like:

v0.10.5

Node Package Manager

One of the great things about the Node installer is that it automatically installs the Node Package Manager. This makes it much easier to install additional applications to extend Node’s capabilities.

Again, you can check the version of NPM by typing the following into your CLI:

npm version

You’ll get an answer, returned as a JSON object:

{ http_parser: '1.0',
  node: '0.10.5',
  v8: '3.14.5.8',
  ares: '1.9.0-DEV',
  uv: '0.10.5',
  zlib: '1.2.3',
  modules: '11',
  openssl: '1.0.1e',
  npm: '1.2.18' }

To find out what packages are installed enter the following into your CLI:

npm ls

The result will be formatted as a directory structure, like this:

C:\Users\Gareth
├── [email protected]
└── [email protected]

Obviously, to find out which globally-installed packages are available use the global flag:

npm ls -g

The first application/module that I want to investigate in depth is the CSS pre-processor Less which is used by the Bootstrap project. I will no doubt report back.

Learn JavaScript this year with Codecademy

Screenshot of Codecademy website

When I was young my Mum and Dad bought my brother, sister and me a computer, a Commodore 64. I remember that I had to write a short essay about why I wanted a computer before Mum and Dad would consider buying one. I really wish I still had that essay, I’d love to read now what I wrote back in 1983.

I loved it. With its friendly blue screen and flashing cursor.

Commodore 64

And its ability to load The Hobbit text adventure in under half-an-hour. But what I loved most was that I could program it.

I would spend hours typing in programs from magazines like Commodore User, Your Commodore and Your 64, and then working out how to customise them. And if I felt brave I’d write my own programs from scratch, in nothing but Commodore BASIC but it was a start.

These days you buy a computer and it boots into Windows, or Linux, or MacOS, or Google Chrome, or Android, or a host of other operating systems with friendly, colourful graphical user interfaces and there is nowhere obvious to begin trying your hand at programming.

If you do want to get into Windows programming, for example, many of the programming languages and environments look quite intimidating to a beginner (and often have a price-tag to match). And that’s before you even attempt to decipher what .NET is, or WPF (that’s Windows Presentation Foundation), or DirectX, or… you get the idea.

I once dabbled with an early version of Delphi (having done a year of Pascal at high school), and Dolphin Smalltalk. I even looked into C and Borland C++ Builder. I didn’t create anything particularly mind-blowing. But you know, they were my programs. I had created them and I knew how they worked, and the process was just really good fun.

That’s one reason I loved my Psion PDAs: they had an OPL programming editor built in. You could start writing programs straight away, using Psion’s own BASIC-like procedural language. I have a half-written Mahjong scoring program somewhere on file that I would like, one day, to finish. Maybe next year!

I definitely think that young people, especially, should be taught programming (again) in school. Something that an article in The Guardian last month agrees with: Programming should take pride of place in our schools.

Codecademy

This year Codecademy seem to be making a push for 2012 to be a year of programming. They are encouraging people to sign up for their getting started with programming course. They are using JavaScript as their chosen language.

JavaScript is a great language to start with (as Mike Loukides will tell you “everyone needs to learn JavaScript” in 2012). The course is online. You do it all within a Web browser. Web browsers know what to do with JavaScript. Perfect.

I’ve completed the first lesson already. It was called FizzBuzz and it gets you recreating that favourite game of primary school, where you start counting from 1 to 20, but instead of saying numbers divisible by 3, you say “Fizz”. And instead of saying numbers divisible by 5, you say “Buzz”. For numbers divisible by both 3 and 5, you say “FizzBuzz”.

If you’re interested in trying your hand at learning JavaScript (and programming in general) then do check out Codecademy.