Ask HN: How should I teach code to kids?

236 points by holaboyperu ↗ HN
My little cousins are 7 and 9 years old. I have been thinking a lot how can I get them started with building and designing for the web.

I just finish my first attempt https://www.youtube.com/watch?v=BiwWT2CERA8

I wanted to ask the HN, what other ideas or what type curriculum I can do to make it more fun and interesting for them. All ideas are welcomed.

137 comments

[ 5.6 ms ] story [ 228 ms ] thread
Ask them.
If they don't have much context, you could show them software projects tailored to their interests and capabilities/time constraints and ask them if they want to make something like that with you.
I've taught kids using https://www.codeclub.org.uk/ - they have a great Scratch based set of exercises. You sell it as "Design your own video games!!!!"

Also moves into HTML, Python, etc.

I had great fun teaching using their curriculum. They're rolling out worldwide and all their materials are CC licensed.

Plus one for this option, I've been teaching the same curriculum for nearly 4 years now, it keeps getting better and better in terms of the resources available as a teacher.
I teach.

I have the kids learn Python between age 9 and 11 depending on when they are interested. We write games and learn the fundamentals of CS by following the curriculum of Rice's "Introduction to Interactive Programming in Python" class designed by Rixner and Warren. It has a Python interpreter and game library that compiles in-browser into javascript, which is a very helpful design for a first class, and for sharing their results with myself, their families, and each other.

Afterwards I encourage those who really enjoy it to learn Java, also using web sources primarily. I intercede when they are stuck but generally they help each other out.

Some of them used to use the Java to write Minecraft mods but that has become a bit more tricky.

There was one student who started to learn Java at age 7, but in general that's too young. If you push things too earlier they don't get a head start. They get burned out and don't want to have anything to do with it any more. You really need to be sensitive to what they are interested in and let them lead.

Most kids when they see others making their own games want to try their own hand at it themselves, so I have managed to create a self-perpetuating cycle.

Learning languages to make games makes sense. Pushing languages to force concepts will be resisted and is counterproductive.

The games approach is nice too because they rapidly learn trigonometry, basic physics, and linear algebra by age 10 or so, and are teaching themselves Calculus on Khan Academy by age 12, as well as researching optics, writing their own shaders and generally doing what most would consider college or graduate level mathematics. Their Java skills also often lead to writing for Android. Some selling their games and other software at a certain point, which helps their families.

It helps that on the reservation I have a great deal of autonomy in what I can do. I've worked in public outside schools before. None of this would be allowed there.

I don't really care for the idea of dumbed down toy languages that can't really be used for production software. Python and Java are well designed enough that they are understandable and usable from the age where they are able to do programming thought. Python is a simpler one to read and use and so we start with that. But Java is very similar and the lessons of Python directly transfer. Java ends up being much more useful for distributable and saleable software, though it is harder as a first language.

Why Python rather than JavaScript?
The real question is "why JavaScript rather than Python?" The only reason JavaScript is so popular is that it runs in the browser. JavaScript is otherwise a pretty poor language, and certainly much harder to learn than Python.
Running in the browser and having pretty good debugging tools seems pretty useful to me.
Compared to other languages and environments, debugging JavaScript can be difficult if you don't have a good idea of what's going on behind the scenes in specific browser versions, the DOM and JavaScript VM. Throw callbacks, Promises, etc into the mix and things get confusing pretty fast.

Comparatively, other languages, like Python, will throw sane exceptions and a meaningful stack trace when something goes wrong.

JS is a pretty bad first language to learn—too many quirks and random syntax in the last few years.

Python is dead simple—I recently had to take on a project written in it having never programmed in Python before and I essentially did not have to learn it to get the feature done.

I had a similar experience with JavaScript, assuming you make _extensive_ use of ES2017 syntax and features. It's actually very nice, provided you have a compatible browser, but there's a long way to go still.
Having used both to teach beginners, I can assure you that your categorical statements are false.

I might give Python an edge for a number of reasons (a shell is a simpler environment than a browser in a number of ways, some of the language features are cleaner), but to say that it's much harder doesn't bear out with my experience. Capable first-timers become productive at about the same rate.

I've found it's mostly experienced developers who trip over JavaScript, because they're carrying a set of expectations and are weirded out when it does something different. Turns out principle of least surprise means different things depending on people's backgrounds.

Feel free to choose to start someone with Python if you prefer it, or if they're likely to want to work in a domain where it makes sense (say, data science), but it's probably not going to change your learn-to-code outcomes much.

That ES6 was created, to substantially redesign the language says otherwise.
The syntax of Python is sane, which can't really be said of JavaScript.
I helped an 8 year old get started in Python. It was an almost effortless process once we started with Python's Turtle Graphics. He started "innovating" himself when he saw what he could do with loops etc and draw with the Turtle. I initially tried Javascript but I couldn't think of an easy way to get him to the level of Python's Turtle animations as quickly. Python seemed more packaged and modular this way.
Interesting. I teach people programming too, both adults and kids - okay not too young kids, say 10th grade or above.

>distributable and saleable software

Do you or they make the Python code into an EXE for sale, using one of the available tools, or sell as source?

In respect to Minecraft, you can use Python to control aspects of the game in the Pi Edition. With Java, the Bukkit/Spigot API isn't too hard to understand, but I'm not too sure about how hard it would be for kids that age. Depends on their skill level and interest.
We used Learn to Mod for a junior hackathon, it is like modding Minecraft but with a scratchlike interface. Super cool
I did the same in New Zealand and it was a massive hit with the kids! Great site with a series of tutorials, in browser barebones Minecraft game to see the results of your code and a great full version Minecraft setup with dedicated worlds where the code is loaded as book objects inside the game. HIGHLY recommend checking them out: https://www.learntomod.com/

They also offer free teacher and student accounts with the ability to limit time. Can't say enough positive things about the service.

(comment deleted)
javascript html5 videogame seems like an obvious choice
Maybe try to use their own interests and relate the code to a kid's story. How are you going to make the little lamb move 5 steps?

Sample to move 1 step:

function move(steps) {

  $("#lamb").css({

    'right': steps + 'px',

    'transition': 'all 1s'

  });
}

move(100);

becomes

move(500);

I don't know haha, do they even want to code in the first place.

Doesn't even consider requestAnimationFrame or proportional scale. Also I'm starting to realize jQuery is pretty big even the min version especially on slow networks.

Have a look at CoderDojo [1]. I did an IT project with the first class (patient zero) of kids from this organization. It was a very rewarding experience to see how great their "hands on" pedagogic approach worked out. The project - a website with front end and backend, full stack - was a great success. Amazing bunch of kids.

CoderDojo in an NGO that has spread globally. I wholeheartedly recommend it.Just don't leave your notebook lying around, or some curious kid might take it apart.. (no joke)

[1] https://coderdojo.com/

(comment deleted)
Don't. Kids that age should be playing outdoors.
So it's either learn how to program or play outside? I do not see why the kids couldn't dedicate some time to each, if they are interested of course.
computers are addictive. Every noticed how top coders look like they've never seen daylight?
I'm 38, started coding when I was 6. My life has been amazing because of it.
Nice video! How did you film the Lego stop-motion stuff? Some advice: make sure your voice is clear next time. The music was too loud in this video.

I agree with the other comments in that they need to be interested first. Well, how do you get them interested? That depends on their interests and hobbies. So what I would do is create a short video that ties one of their hobbies to programming, and try to discuss what they thought of the video. Once you get them hooked, they'll be ready to learn.

For more in depth JavaScript exercises, I built this for some hour of code sessions at some pretty big high schools.

It's basically a UI for writing/sharing/leading code exercises.

It should obviously be using a database and have better security, but that wasn't a major priority for my original purpose.

https://github.com/katzgrau/hour-of-code-developer

I know of a game that incorporates programming lessons in a really cute way. I discovered it when I was around 15 and loved it so much, I wished I ran into it at an earlier age.

It's a 3rd person view where you control an astronaut on different missions. It has some RTS elements as there are various robots to control.

However, in addition to being able to directly control the robots (which is fun and accessible), you can write code that it'll execute and automate some simple tasks, like fetching resources, defending a base, etc. It's very high quality and well made, and incorporates step by step lessons, starting with basics of programming. Your creativity is the limit.

What I've found out recently is the game was eventually released as open source (it was originally commercial) and picked up by a community of people working on making it better, and it's suppported on modern systems.

It's called Colobot [0] and I highly suggest you try it out, see if you think the kids would find it interesting.

[0] https://colobot.info/

I found Scratch Jr. [1] and Alice 3D [2] great tools for teaching programming. I found Alice 3D more appealing for kids that the full Scratch online. Scratch Jr. for a 7 year old kid is a good way to start. A typical 9 year old is more capable of general programming (thinking in a straigthforward syntax like in Python).

For younger kids I only recommend Scratch Jr. since it is natural, has less friction, and doesn't require reading.

[1] https://www.scratchjr.org/

[2] https://www.alice.org/

+1 for Scratch Jr.

I am also a fan of hour of code ( https://code.org/learn), it uses popular games and Disney characters and typically no project takes more than an hour.

How about teaching them about health?

We've recently started to teach kids with the use of Aidlab (https://www.aidlab.com/developer) to show them some basics about heart, lungs or motion data. They are able to measure themselves, develop simple apps thanks to Unity engine, and make use of those data (ex. building games that use respiration level to control game character).

In my (very limited) experience, building text adventures is a great way to teach kids programming:

* You don't need any complicated stuff for it, just printing to stdout and reading from stdin.

* Kids love making up stories and games

* When they understand the basics you can gradually increase the complexity: Add if/then/else conditions (do you wanna go left or right?), functions (e.g. to parse answers to questions), variables and simple arithmetic (treasures found, monsters fought, ...) and libraries (e.g. for adding randomness to the game).

And if they're hungry for even more afterwards, you can add some graphics programming into the mix. By then they should be motivated enough by their story that they actually want to learn something more complex and challenging.

I'd recommend a scripting language to get started, as it removes the need to compile code, which (IMHO) just adds unnecessary complexity.

Not sure if this is the best approach, I tried it once and it worked great though!

>I'd recommend a scripting language to get started, as it removes the need to compile code //

Or use a REPL (eg repl.it)?

Depends whether you want to teach code or computer science (and code).

I wrote a book to teach 7-11 year olds to code in Python and Scratch and teach them some computer science along the way - I read a few other books out there first, and there's a lot of "just copy out this code and things will happen", which is exactly what I tried to avoid in this book.

The reviews: http://www.goodreads.com/book/show/28232614-coding-unlocked#...

The book: https://www.amazon.com/gp/product/B013R4OFVA/ref=x_gr_w_bb?i...

My son is 8 and started using Scratch at school. He had me install it on my macbook and he created a simple side-scroll game and a program to play the Jingle Bells chorus.

I was impressed with how quickly he went from "just tried this at school" to "leave me alone, Dad, I know what I'm doing here".

Seems like a good intro for kids.

You don't have to install Scratch! The old version required you to install it, but these days you just need to use the browser version. https://scratch.mit.edu/
Hywel, I notice the blurb says "in line with the new National Curriculum" is that a USA-wide curriculum or is it in another country. I've got kids in that age range in the UK and they don't do any such computing/coding [at school!].
Yeah, the UK National Curriculum says children need to learn a visual language (like Scratch) and then a text based one (like Python). Your kids should be doing visual coding in school from Key Stage 2.
In case anyone else was wondering, "Key Stage 2 is the legal term for the four years of schooling in maintained schools in England and Wales normally known as Year 3, Year 4, Year 5 and Year 6, when the pupils are aged between 7 and 11."
This is more a recommendation for kids slightly younger (4yo) - http://thefoos.com/

The game is pretty amazing in that it teaches pre-reading kids how to "code" by presenting it as a puzzle that you add pieces to. Really well done.

Bitsbox was on Shark Tank yesterday. It's apparently founded by ex-Googlers.

It looks quite good, but does anyone here have any first hand experience with it? I'd love to hear an honest review.

https://bitsbox.com/

Game modding

The first contact I had to actual programming was messing with Pawno scripts to make gameservers in San Andreas multiplayer when I was 12... Spent hours and hours programming with it. It started simple placing coordinates where the cars should spawn until I started to mess with more 'complicated' stuff like gates that open when player get near.

I would get some game that is popular among kids that age (minecraft?) and teach them to make simple modifications, if they like they will try to push themselfs to make harder and more complex stuff, the reward/work ratio is bigger than make a game from scratch on HTML, where there is a lot that needs to be done before getting to the "fun part".

Codakid (based in Scottsdale, Arizona) teaches kids how to code with Minecraft mods amongst other things.
Wasn't aware of them, signing up my daughter now. Thanks!
(comment deleted)
Games are a great way to get kids into computers and code.

Many of us who grew up around MS-DOS had to figure out ways to get around the 640kb base memory limitation and deal with conflicting IRQ ports. Did we want to do that? No, we just wanted to play Dune II. But through that, it got us tinkering with installing new programs, tinkering with configuration files, and eventually learning BASIC, putting together your own computer, etc.

Unless the kids are extremely mature and patient, the best way is to focus on an appealing end product. Don't present it as "oh, let's learn about boolean operators" today, as much as "hey, want to build a [something cool] together?"

And you know what? It may not stick; maybe they'd rather be outside, bake some cookies, or beat on some drums, and that's fine, too.

Doom modding was a challenge too, though more because the tools were immature. Now Duke3D changed that when it shipped with Build. Now I know teens who still use Build to experiment despite it being nearly as old as them.
I first learned programming from game modding as well. I loved it.
Also game hacking. I remember teaching myself VB to make flash game trainers. Would be interesting to find maybe some open-source HTML5/JS games and teach the kids to hack the JS to do what they want. With kids, it tends to help if you give them an existing foundation to build on or work around.
Can relate. Although I enjoyed doing things with websites my programming took on a noticeable uptick after I managed to find a way to automate (fancy for bot >_>) my crafting in FFXIV so I could game and go to the gym at the same time...
I've done it. The best way I found was to setup a Minecraft Server and let them manage it. Keeping it up and running touches on every skill you need.
To teach them basic concept of coding you can always let them play Human Resource Machine, Android/iOS/Windows game created by World of Goo studio http://2dboy.com/
I learned the basics of programming with Processing[0] and it was great! Seriously. It's basically procedural (but not turtle) graphics with a very simple IDE. You can also do animations and interactive stuff (mouse/keyboard), that's fun too. The official one is in Java, but it's just procedural, little to no OO required. there's also Python/JavaScript versions, haven't tried them. Another bonus is, it's easily embedabble online. There's a built-in Java -> JavaScript converter, which lets you automagically run a Java sketch in a browser.

the rest of this is just me criticizing things I used and didn't like, so feel free to ignore

I tried reaching a friends' kid programming with Scratch and making any kind of more complex stuff was actually too hard because of the "simplifications" built into the language. Can't remember the details, but you had to use globals instead of passing parameters for something basic, like constructing objects.

[0] processing.org