How To Teach Lua/Codea

Hi all,

In another thread I got into a discussion with @Andrew_Stacey and @Ignatz about teaching programming to young children using Codea (and hence Lua). (In my case, I started one daughter at age 7 and another at age 10. Some of their similarly-aged friends are now interested too.) @Andrew_Stacey suggested I start a new thread for discussing approaches to that.

At age 7, part of the challenge is that even basic math skills (say, the notion of “multiplication”) aren’t quite solid yet. So I try to find a path that adds skills very incrementally while trying to keep a sense of wonder all along the way. So far, most of what I’ve done is one on one; i.e., I teach only one child at a time.

I started programming quite young myself around 1980: Back then, my aspiration was to write something like Space Invaders or Pac-Man, which was actually a nearly realistic goal for a 10-year old with a home computer of the time. Nowadays, the aspiration is in terms of something like Minecraft, which is far less realistic: So I think it’s harder for a child today to stay motivated than it was 30 years ago.

Anyway, on to some practical notes… suggestions for improvement welcome.

I start by explaining the notion of coordinates on paper. I.e., we spent a few minutes discussing what would be needed to tell a computer where on the screen something should appear. At age seven that question is too abstract, so I provide quite a bit of lead: “How about we tell it how far from the left edge and how far from the bottom edge we want to draw a circle?” Once she agrees that that would be a good way to describe a place on the screen, I explain that “distance from the left edge” is called the “X coordinate” and “distance from the bottom edge” is called the “Y coordinate” and usually we write the two in order with a comma between them, like this: 100, 200. Once she gets that, I suggest a little game: I give her a paper with a grid pattern and a list with pairs coordinate pairs and ask her to draw straight lines between the pairs of coordinate pairs. The list is carefully chosen to produce a smiley face.

Then I bring up a new Codea project on the iPad and explain that the stuff written in the draw()end are instructions to draw on the screen. I let her play with the background argument (i.e., the color picker) that’s in there and let her run the program to see the effect. It’s remarkable how entertaining that can be at that age :wink:

Next, I explain the line call: I find it makes perfect sense after the discussion and paper game about coordinates. I type some arbitrary line(...) in the program and show her the effect. Then I ask her if she’d like to write some herself (which she does; if she wouldn’t, I would probably suggest taking a break for an extended while). Translating the paper tracing game into line calls is natural at point.

I also show ellipse and rect calls around this time.

This much can take me quite a few days, BTW. I don’t spend hours at a time on this. Just a half hour here and a half hour there. Also, we frequently ask about her programming goals, explain that I cannot realistically walk her through a Minecraft implementation, suggest something else (tic-tac-toe, at first), and remind her that even achieving that will require her to practice much.

Next, I show print and explain that for now she should only use it in setup() ... end. For fun, I show her what happens when you put it in draw()...end and explain that draw() happen 60 times a second but the iPad is so fast that it can do a lot of things between to such drawings (“wow!”). I introduce the idea of variables from print, just showing variations like the following. First:





    x = 7

And now:

    x = 4
    x = x+3

Or even:

    x = 4

Once she gets that, I combine it with the coordinates idea:

function draw()
    circle(x, 100, 50, 50)
    x = x+1

Tadaa! (After a while it sinks in what is happening.)

Next I explain numeric for-loops and spend quite a bit of time trying to get her to come up with loops on her own to do various things. E.g., find the sum of the first one thousand integers, draw 10 circles on a line, draw 100 circles in a square arrangement, draw a pyramid of circles, etc. This turns out to be remarkably hard (which is why I spend so much time on it).

Then if-then-else, comparisons, and, or, and not. Again, not easy, and I try to think of a lot of little examples (one I remember: I explain fill and color — which they readily get — and ask to change the square arrangement of circles to fill one circle with a different color). break also gets explained around this time.

Next are tables, which I also first start on paper (a table with two columns, having in the left column the names of your friends, and on the right their ages). When I move to code, I only show three table primitives:

    ages = {}               -- start a table
    ages["Natasha"] = 9     -- update a row in the table
    print(ages["Natasha"])  -- look for something in the table

And finally, the touched function (with my first daughter I started with currentTouch instead, but that turned out not to be helpful). Note that for function touch(t) she doesn’t learn about t.x at first; only t["x"]. Since then I have shown her the shorthand notation, but I waited until I felt she was solid on table use. This is also where I tell her how to organize her overall program: setup is only to set the initial values of variables and tables, draw is only to draw (not updating variables and tables that are used outside of draw), and touched is where variables and tables are updated.

This is more or less where we’re at with my youngest (who has had a birthday since the start of this). She does know about sprite, and likes to make drawings in Art Studio (another iPad app) which she then exports via the pasteboard to her Documents. She also understands functions (caveat: we haven’t discussed return yet), but she hasn’t acquired the skill to decompose code into reusable functions.

My oldest (age 11 now) understands functions a bit better, understands some of the tween functions (and hence callbacks), and has started simple physics. We’ve got a ball bouncing.

thanks! interesting read. Codea seems like a good first code environment.

@tnlogy: Agreed. I think Lua/Codea/iPad is the new Basic/Home Computer. It’s personal and nonthreatening, yet produces fairly quick results. My kids know my professional life revolves around C++, but if they had to start with that, I suspect they’d run away from programming and computer science as fast as they could :stuck_out_tongue:

Really nice approach. Again, will engage further when feeling better but have you considered developing this into an ebook or app? Also, have you seen some of the children’s programming games on the App Store and what’s your opinion of them? Kind of agree with the Lua-BASIC comparison but throw Codea into the mix and the results can end up being fairly polished. Let’s hope Codea ends up inspiring as many future programmers as BASIC did back in the day (my brother first taught me to program on a ZX81 when I was just 10/11 although I never really kept up with it after that…)

@daveedvdv - thank you, very interesting. It seems that 1:1 coaching makes all the difference, especially when the initial learning process is not very exciting and initial expectations have to be dampened.

I agree that Codea is the new Basic, having been around both for the original Basic and Visual Basic (which aroused the same kind of enthusiasm I’m seeing in this forum).

@Ignatz: I agree 1:1 mentoring makes a huge difference; I have no experience teaching a large group of small children, and wouldn’t know how to start. (College students are okay.)

@ScottDafydd: I have started an iBook on the topic because I sensed with my older daughter that she’d like to study on her own. The in-app instructions are just a bit too terse for her, and we don’t allow her to surf the web on her own. I’m not sure I’ll ever finish the iBook though, because since then she’s been keener on doing things 1:1 or even 1:2 again. Then again, their friends want to learn too, and so that could be a vehicle to pass the knowledge around.

@daveedvdv - I tried teaching some local high schoolers in some spare lessons they had, and quickly found the problem is that do anything, you need a basic understanding of Lua, which is far from visual or exciting, and a big comedown from their initial expectations of coding a game within a couple of hours. So it was very difficult to keep them on track.

I think your very slow, highly personalised approach overcame that by helping your kids to learn without conscious effort. It is far, far harder for an ebook to do the same thing on its own, unless your kid is naturally keen.

Another problem is that learning isn’t linear. You can’t just start at page 1 and read the book. You have to stop and practise, to become familiar with language and concepts.

I was conscious in writing my own ebooks, as I went from one chapter to the next, that in learning it myself originally, I had spent time “in between the chapters” practising and working to get things straight in my head, before continuing. So I thought of including lots of exercises to work through, but it was a lot of [unexciting] work, and I always skip those myself, so in the end I didn’t include them.

I liked @daveedvdv way of starting with the idea of plotting points to get a grip of x and y, and wondered if it might be incorporated into some kind of learning game (hence the question about some of the one’s that already exist on the App Store). I also think @Ignatz almost certainly made the right decision about the exercises in his book (although you could always put them in an appendix for those who would like to use them.)

That said, I’m not one of these people who necessarily thinks learning always has to be ‘fun’ (this idea is one of the things that is killing education over here at the moment, as well as many of the teachers that I know). I do however think that it should be ‘rewarding’ and for that the learner needs to see some fruit to their efforts in order to be motivated further.

This is just off the top of my head (although follows on from similar discussions recently) but I wonder if it would help to structure a course around a complete project that they could play around with initially (color picker, sprites etc) to make something of their own and then split down into a number of individual and distinct lessons (setup, touch, draw, variables, loops and conditions) to show how they could do something similar on their own. Nice idea?

@ScottDayfdd - a good idea, indeed.

A “step by step” approach can be implemented in Codea by having a project containing a number of progressive lessons, one per tab. Each tab has its own setup, draw functions, etc, completely independently.

Then, code that @Andrew_Stacey wrote can be used to choose a particular tab to run. The bottom link on this page contains a template for this.


I agree with your point about classroom settings vs. one-on-one. One possibility in the classroom setting (which I’ve used to teach college students, and I think might be viable in high-school) is to create an “almost finished” app up-front, and then present the students bits of it, explaining basic elements along the way. Then in exercise sessions, have them modify/improve/customize some of those bits. So it’s neither top-down nor bottom-up, but more of a bite-at-a-time approach.

(I started working on such an approach to teach automata/grammars to my daughters, but got side-tracked in the project for myself :smiley: . That’s where the thread about fast rotations originated.)

Regarding the transfer to written media, you’re right that practice is critical. However, I also think a book can be structured to encourage that practice. E.g., I’m not fond of just having exercises at the end of each chapter (cue the deadly “the proof of this theorem is left as an exercise to the reader” statement >:-) ). Instead, I prefer to complement those with exercises that are worked out in the book step by step, with offers for tangential explorations along the way.

Also the very liberal use of small examples encourages the reader to try, I think. (I have written a book for advanced programmers that uses a large number of tiny examples as the driving force to get the reader through very abstract material and at the same time provide practical guidance. The audience is difference, obviously, but I think the idea of tons of small examples is helpful at all levels.)

@daveedvdv - Nice set of observations there and I agree pretty much with everything you say.

I’m teaching my 8 year old daughter at the moment a bit of Codea as she ‘sees what daddy does’ and wants to have a go. I think with anything like this, getting them hooked with something visually stimulating that they can achieve relatively quickly is the key and keep the lessons reeeeeeeeally short. :wink:

You’ll be suprised how much fun selecting a sprite and moving it under the touch position (using currentTouch) can be for an 8 year old. 2 lines of code (which I helped her type in), a bit of simple explanation and then letting her play for a bit did the trick. Whats interesting is that once you’ve got the ‘visual/interactive bit’ out the way - it was then much easier to teach her the concept of coordinates afterwards and then let her play again with the same setup.
It was then easy to build on this with scale, rotation etc… on the same bit of code and let her play.

I guess my point is (at this age-group) that getting a ‘quick win’ with something visual or interactive BEFORE teaching the actually theory is maybe a better way to go. Kids get bored real quick and want to see something stimulating to inspire them first.

Oh yes, shes just written a Call of Duty clone in Codea and its just been released on the App Store… only kidding :wink:

@ScottDafydd, @Ignatz: Sorry, I hadn’t seen the last two comments preceding mine. Clearly some of the same ideas there.

Also, when I started the iBook I had in mind that I could add video of some of the personal sessions I have with my girls to sort of transfer some of that more personal approach to the “reader”. The problem is that I’m not good with video. Hopefully, the possibilities of iBook-like textbooks are only going to grow in the future.

@andymac3d: I totally agree that a “quick win” is a huge asset in what follows. You’re probably right that it may be best to have a little type-it-yourself program to start things of with before even talking about coordinates and the like.

I forgot to mention that during my teaching sessions with my kids, they’re eager to be in control of the iPad and do the typing. It takes a special kind of patience for me :stuck_out_tongue:

I’m finding some parallels with teaching my daughter a bit about music and more importantly, some simple piano theory. Music tuition can get really stuffy unless you have a good tutor at that age. Kids (and when I was a kid) really hate all the bloody tadpoles, staves and note-stuff that seems to get drummed into beginners - when all they really want to do is to try and make as much noise as possible, or when they’ve got bored with that, either making up a tune on their own or trying to work out what notes go to make their favourite song.

I guess this is pretty much what I said earlier re:coding - a framework for ‘play’ is really important then ‘sock it to them’ with a bit of theory. With music, its then much easier to explain melody and rhythm once they’ve experimented with concepts on their own first.

As a side-note, if anyone does have kids wanting to play the piano - i can heartily recommend PianoMania for the iPad. I think this does some really cool stuff making music theory fun using a range of techniques such as games etc… I’d much rather use this as a method to get her inspired first.

@andymac3d: I can see the parallel indeed.

And as a matter of fact, my girls do study a bit of piano. What kind of level is PianoMania appropriate for?

@daveedvdv - 9-11 it says, but my daughter picked it up quite quickly and shes a bit younger. Be warned, it has some hefty in-app purchase/subscription options for extra songs etc… But, I guess try it out first and see how you go.

@andymac3d : Sounds good, I’ll take a look.

@daveedvdv @andymac - love some of these ideas and how they seem to be forming round a pattern. Agree with the quick win stuff, and how important it is to have play and exploration involved for themselves. Think this is why I prefer to use the term ‘rewarding’ rather than ‘fun’. Just having ‘fun’ can be a passive experience, as can learning theory, whereas play and exploration is participatory and active, and ultimately more rewarding. (And this from someone with quite a healthy love of concept and theory!)

@daveedvdv - what kind of things were you hoping to do with video for your iBook? My day job is in media and design (incl animation) and there are loads of apps on the App Store that do things only professionals could manage a few years ago. For live video, I would recommend taking a look at something like Gravie which allows you to edit, add filters, audio and even some pretty nifty typefaces very easily (think the famous ‘live the language’ videos from a few years ago - worth a google if you’ve never seen). Or you could even use something like Videoscribe to create some cool whiteboard style videos. Happy to help if you need any advice.

@daveedvdv - Have you seen Hopscotch? I think it is produced by MIT - it’s a free coding app for children. With a drag and drop interface. I gave it to my 7 year old and let him play with it without me giving him any instructions. By the end of a 25 minute car journey he had produced at least 2 working programs and was experimenting further. Admittedly it’s not particularly sophisticated and is somewhat limitted to say the least but as a means of building up a generalised conceptual framework regarding what programming is, it is very useful…perhaps because of its limitations. The fact that he has already realised what can and can’t be done with the program automatically has him asking about different languages…sometimes bounds are better than all out freedom.

Another method of teaching is to show them something which appeals and should by analysis be within their grasp. I’ve just put on a 20 line program on Codea Community called crazy circles which is very aesthetically pleasing, simply showing them this and asking how they could modify it (I.e. Squares, rotated squares etc) can be a useful learning experience. I.e. Taking something and personalising it as opposed to building it up from scratch…