http://www.perlmonks.org?node_id=508131

Hi all,

I am just about to begin a course in programming to a bunch of 12 year olds at my son's school.

To the dismay of some, and the amusement of others, I will be using Perl as my language of choice.

At work, many accuse me of using this course as an evil plot to convert the world's future programmers to the perlish way of doing things. All I can say to that is,

"Bwa Ha ha ha ha!"

On a more serious note, I would like to have comments regarding what and how I will teach these young impressionable children.

Firstly, after have taught children before (many many moons ago), I can honestly say that if I were just to teach programming the same way that we teach adults to program, the children will become bored very quickly. They want action!

So, I thought about it some, and decided that we would have a project, where we would create a simple interactive game. Remember the old DOS game "nibbles"? It's the worm that has to eat food, gets bigger and bigger, and cannot eat it's own tail.

There are other things to consider as well. This is an after-school course, and there are no marks, grades, or other such stuff. My goal is to teach the children the basics, let them play with the more advanced stuff with out necessarily understanding all the intracies and details. Hopefully this will inspire a few of them to learn more after the course is finished.

In preparation for this course, I actually wrote the code (using Tk) for my own version of the nibbles game to see how easy it is, and what knowlege would be required of the students. I think it's not too bad.

Here is a simple 'sketch' of my course plan. Any comments (please be gentle) are appreciated.

Always, always, use good comments!

Item

Explain: (1) how to use an editor, (2) what is a perl script, (3) how to run a perl script.

Create simple hello world scripts. Run them. Explain each line, especially how use strict; is almost mandatory. Play with the colours of Tk.

#!/usr/bin/perl use strict; print "Hello World\n";
and
#!/usr/bin/perl use strict; use Tk; my $mw=MainWindow->new(-title=>"Hi Kids!"); $mw->Label(-text=>"Hello World")->pack(); MainLoop;

Concepts to Learn

* the shebang line (although not needed for Windows, why not?)
* use strict
* quotes
* (variables to be skipped until later)
* the use statement, what libraries/modules are, re-use of code, etc
* command line vs gui
* symple syntax rules

Item

Show where to find the documentation (we are using ActiveState on Windows). Explain about web-forums, although I don't think they would be quite ready for perlmonks yet.

Item

Start with a very simple Tk window, with a canvas object, and a rectangle on it. Make it move. Again, let the kids play with the colours.

Design

must design a grid, where to move, etc.

Concepts to Learn

* variables
* Tk function canvas
* Tk canvas function create_rectangle
* Tk function repeat
* subroutine callbacks (very simplistic explanation at this time)
* simple debugging via print statements

Item

Once we have a moving square, control it via the arrow keys.

Design

Use a simple variable to keep track of what direction the square is moving in, change this variable depending on what key is pressed.

Concepts to Learn

* binding to events
* logic statements (if (...) {...}))
* passing parameters to subroutines

Item

Detect if square bumps into the edges of the canvas

Design

Create border edge of canvas object. After every move, check if square coordinates are outside of allowed area.

Concepts to Learn

* loops and conditional loops
* unless
* stopping Tk repeat functions via cancel
* returning information from a subroutine via return
* get coordinates from a Tk canvas object

Item

Take time out to play with the colours, the sizes. Let the students personalize their own program.

Concepts to Learn

* The programmers are the masters of the program
* computer colours (red-green-blue) etc

Item

Make a food pellet and eat it. Keep score.

Design

How to place food. Where, when, etc. Keep and display score.

Concepts to Learn

* random function
* Tk label
* pointing to variable addresses i.e. -textvariable=>\$score
* variable scoping
* Probably lots more debugging via print statements
* Why $x==$y doesn't always work for floating point numbers, depending on the operating system, etc. etc. etc.

Item

Make the worm grow when it eats the food. Lose game if the worm eats it's own tail.

Design

Make a worm out of an array of rectangles. When moving worm, just move tail to where the new position of the head should be. Add new rectangles at tail position as worm grows.

Concepts to Learn

* arrays
* array order
* push,pop,shift,unshift
* looping over arrays (foreach)

Item

Add sounds

Design

Decide what events should trigger sounds.

Concepts to Learn

* using gooble
* how to find free sounds using google
* use Win32::Sound
* directory structures
* use FindBin

Item

Add start/stop/continue buttons

Concepts to Learn

* Tk buttons
* more binding
* Tk colours (background vs highlightbackground, etc.)
* Cleaning up old stuff before restarting game

Item

And so it continues, with the students driving the modifications at this point.

* Change the scoring depending on how many moves the user makes before eating the food?
* Different levels with different obstructions?
* Different difficulty levels (vary speed, size, etc.)?
* Keep a best score page (This would be good because it would involve learning about files, reading and writing to them, maybe even simple parsing, sorting in order of who's best, etc.)?
* Making a menu?

I volunteered for this. Now I'm panicked. Too late to turn back.... AAAaaaahhhh!

Remember me fondly,

Sandy

Replies are listed 'Best First'.
Re: Teaching Children How to Program
by GrandFather (Saint) on Nov 13, 2005 at 19:43 UTC

    You timed this question very well! Yesterday our 12 year old son asked me how to write script for a game system (Morrowind). So I signed him up with PerlMonks and pointed him at the tutorials section. He started with baby steps. We managed to skip over most of the stuff about getting Perl installed etc., down to the hello world - which of course was a little more interesting when we substituted his name.

    After that it was mostly feeding him little bits to augment the stuff he was reading in the tutorial. For example, at one point he wanted to check that a reply was a number, so I wrtoe a "magic" isNumber sub for him using some regex "magic". He was very happy with the magic, and spent the rest of the afternoon writing Perl to ask questions (sometimes in a loop for a "correct" answer), check answers and do simple arithmetic ("Half your age is ...").

    At the end of the afternoon he knew about variables, print, <STDIN>, chomp, eq, ne, lc, last, redo, strings and interpolation (although not explicitly, just through use) and probably other stuff I don't remember. He is also keen to learn more. He was very keen to post his "first program" to PerlMonks. Anyone want to suggest a suitable section (Meditations perhaps), but I disuaded him - somewhat reluctantly.

    If anyone wants to /msg Panda, he'd probably be quite excited :)


    Perl is Huffman encoded by design.

      This is the first program I made. It's relatively simple but it helped me understand the basics.

      use warnings; use strict; print "What is your name?"; my $name = <STDIN>; chomp $name; print "Hello, $name:)\n"; print "How old are you? "; my $age = <STDIN>; chomp $age; print "You are $age years old!\n"; $age = $age / 2; print "Half your age is $age years.\n"; my $sum; { print "Enter a number... "; $sum = <STDIN>; chomp $sum; if (! isNumber ($sum)) { print "Please use numrals.\n"; redo; } else { last; } } my $nextsum = $sum / 2; print "Half of $sum = $nextsum"; sub isNumber { my $value = shift; return $value =~ /^[.\d+-eE]+$/; }; print "\nTell me $name, would you like to try a test? Yes or No.\n"; { my $answer = <STDIN>; chomp $answer; if ("no" eq lc ($answer)) { print "Oh well, have a good day!"; exit; } if ("yes" ne lc ($answer)) { print "Please answer yes or no $name\n"; redo; } } print "The question is: What is the square root of 36?\n"; my $answertwo = <STDIN>; chomp $answertwo; print "Correct! Have a good day!" if "6" eq lc ($answertwo); print "Sorry, you're wrong. Have a good day!" if "6" ne lc ($answertwo +);

      As you can see, it goes like this:

      What is your name?your name Hello, your name:) How old are you? 34 You are 34 years old! Half your age is 17 years. Enter a number... 5 Half of 5 = 2.5 Tell me your name, would you like to try a test? Yes or No. yes The question is: What is the square root of 36? seven Sorry, you're wrong. Have a good day!

        Oh, no - you've inherited the same indentation style!

        :-)

        (welcome, and good job .. much more ambitious than those silly 'hello world' programs ;-})

        if "6" eq lc ($answertwo);

        <kidding>
        I'm very interested in knowing the uppercase of "6" :)
        </kidding>

        Lots of goodies in there. Good stuff!

Re: Teaching Children How to Program
by Tanktalus (Canon) on Nov 13, 2005 at 19:41 UTC
Re: Teaching Children How to Program
by dragonchild (Archbishop) on Nov 13, 2005 at 20:43 UTC
    My 10-year old has been on me to teach him how to program for a while. After an abortive attempt to start with logic and flowcharts, I've decided to use a language that provides instant feedback. I want to use Lisp. I may choose to use Ruby, but I'm pretty sure it will be Common Lisp. Reason? I want my son to think logically before procedurally or OO-lly. I want him to design bottom-up instead of top-down, which is what the procedural languages practically demand that the programmer do.

    What I do know is that you have to spend time on the editor as well as the language. If the programmer has to fight the editor just to get hello_world.* to work, then the programmer will associate programming with frustration. That's bad.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

      When "teaching" Panda yesterday, I pointed him at Komodo. Nice GUI IDE with an editor that just works (Panda has used Word and other similar editors before) and the immediacy of pressing a button to run the code he was playing with combined with the feedback of syntax checking as he was editing removed a vast amount of frustration.

      Of the languages that I've played with (see my home node), Perl is the one that I would choose for teaching simple programming concepts without having to worry very much about types and the difference between numbers and strings and other such unimportant cruft. DWIM saves the day :).


      Perl is Huffman encoded by design.

        I agree that Komodo is a very nice editor, especially if one is just learning. However, I've had equally good results with the Open-Source Eclipse project, using the incredible EPIC plugin to enable Perl projects.

        It takes a little more initial setup than Komodo, but I have found many more useful features in Eclipse/EPIC as I have been writing more and more code; Eclipse also seems to perform better for me, but YMMV on that one.

        I will say this: I really enjoy ActiveState's graphical debugger, part of their "PDK" software. Unfortunately, I don't think that component is available for free. A close second is Devel::ptkdb, which is a Tk-based GUI debugger for Perl code.

        <-radiant.matrix->
        A collection of thoughts and links from the minds of geeks
        The Code that can be seen is not the true Code
        "In any sufficiently large group of people, most are idiots" - Kaa's Law

      You could also try scheme instead of common lisp, PLT scheme can be very nice for beginners.

      Update: my father tought me Basic when I was young btw.

        My grandfather (no relation to my Grandfather) taught me BASIC when I was 10 on his TRaSh 80. Those were the days. Fiddling the tape player volume as you carefully try for the 4th time to load a gigantic 15k program. Why, when I was a boy we had to program uphill in 10 feet of snow.

        The library was my sole teacher. No humans required.

        I started off with Basic (on a Dick Smith VZ200) when about 10/11 years old. I started to teach myself Pascal when 13 and I didn't get into C and assembler until I was around 14. I still have the Turbo C 2.0 manuals from then and use the library reference even today.

        Teaching kids who want to learn is a worthwhile endeavour. But anyone who wants to know will learn of their own accord.

        I guess pointing kids in the right direction is the main thing..

Re: Teaching Children How to Program
by eric256 (Parson) on Nov 14, 2005 at 03:44 UTC

    Your course seems a bit hard. ;) Realy it depends on the students you will have. If you have 12 year olds who signed up for the class optionaly then maybe your course is perfect. I would recommend having an example script of each step that your young programmers can work from. Maybe printed exampls so that they have to at least type them. I think the hardest part with any new programmer is teaching the logical portion. Perhaps with your course you would have a flowchart-ish description of the days goal. Then your sample code could have that exact description embeded in it as comments in the correct spots. This would allow you to reinforce the logic aspect and still give everyone a chance. The advanced students will ignore or embelish your code, the lower ones will get the crutch they need. You probably also want to schedule time or a few days to let people catch up and get personal attention plus advanced students would get time to explore beyond your lesson plan.

    One last note, if you do use Tk maybe prebuild a library (call it a game library or something) that does lots of the work for them. Depending on the skills they have  use GameLib;  my $name = get("What is your name?"); is lots easier and more bang for there buck.

    Final side note: I learned programming in the back of my 6th grade class with basic and logo. The teacher realized I got more out of that then the math she was teaching (which in 6th grade is pretty low stuff) and figured i was less of a distraction back there than bugging her with questions during her lesson. ;)


    ___________
    Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;
      I was planning on writing the bits of code, in class. Rather than start with a finished example, where all the bugs are eliminated, I thought it would be useful for them to see me make mistakes, and what methods I use to track down the mistakes and fix them.

      At the end of the class, each student can have a copy of what I did, so that they can play with it and expand on it if they want.

      I am also setting up a private forum, so the more adventurous kids can post questions etc (just like perl monks).

      Sandy

        That is very useful. I found that my best asset was the ability to make fun of myself when I made a bug happen. It was great to see the kids work up the courage to figure out and point out my mistakes. Most of the kids I worked with came from a 2nd-generation hispanic immigrant society where the cultural imperative is to stay off the radar scope, so this was very gratifying to see.

        The first two years, when we had a very gifted teacher to work with, this worked well, but the last year, the replacement wasn't as secure in her classroom leadership. I and the other in-class volunteer discovered that she was very unhappy when I demonstrated my imperfection. It sounds like you will not run into this kind of thing in a direct sense, but be alert. The 'management buy-in' may disappear due to circumstances outside your control. The parents loved what we did and supported it vociferously, but support evaporated from the administration for reasons I have already described.
Re: Teaching Children How to Program
by robot_tourist (Hermit) on Nov 14, 2005 at 11:46 UTC

    I wish I'd been on your class when I was 12. Your lesson plans are pretty good, but perhaps there are a few too many concepts for the first Item. If you are good at explaining those concepts and your class is intelligent enough, that's fine, but the first Item looks a little heavy to me. Personally, I would look more at variables first than code re-use.

    When I started programming all I had was the manual of my dad's C=64. As I didn't have an IQ of 200 I was always amazed when I read about games programmers, like the Darling brothers, who were publishing their own games when still at boarding school. I pretty much gave up on programming as a hobby until my late teens when I finally understood the DATA lines in C=64 programs and I could suddenly design my own sprites! Unfortunately I didn't persevere with collision detection. To my shame it took until 2nd year at university to understand how to program things, not just a single sprite, on a frame-by-frame basis. We were in pairs for a practical class and my partner had a loop to decide what to do with each sprite at each frame.

    How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
    Robot Tourist, by Ten Benson

Re: Teaching Children How to Program
by BioGeek (Hermit) on Nov 14, 2005 at 15:23 UTC
    An interesting read is also this series of blogposts about a dad who teaches his six-year-old son to write a simple game (in Python - but his observations are aqually applicable to Perl).
Re: Teaching Children How to Program
by samizdat (Vicar) on Nov 14, 2005 at 13:57 UTC
    First off, congratulations on taking on the greatest challenge there is. Before 'No Child Left Behind' wiped out most opportunities for free-form education, I spent almost three years of happy afternoons figuring out how to open up the field for ten year olds. See the 8-yr olds thread already posted for my previous commentary and a link to an article with a lot of ideas we tried.

      Thank you for your comments.

      The students have a computer room at the school, where they are allowed free accesss before and after school, and at lunch time, as long as they make an appointment.

      I'm still not sure if they have internet access at the school.

      For those kids with home computers, I prepared a 'take-home' package with ActivePerl and CrimsonEdit (opensource and freeware).

      Strangely enough, one of the earliest discussions about this course was money. The home and school association wanted to charge for it. I, however, refused to teach the course if they charge money. The kids at this school come from a wide variety of economic conditions, and I hate the idea of some kid wanting to take the course, but not being able to.

      OT: I'm not familiar with the 'No Child Left Behind' politics. How does that interfere with expanding childrens' horizons?

      Sandy

        Sandy, I am glad you refused to take money for the course. I am bothered by how much the schools expect to extract more money on top of what they get from taxes, although I am also seeing how little preparation and outside education many parents send their kids to school with. My five year old is reading as well as most second-graders, but other kindergarten kids can't even recognize thirty-six letters and numbers. It's a tough situation, and I certainly can't blame most teachers. None of the kids are dumb, they just haven't been exposed to anything useful.

        NCLB has an admirable (stated) goal, but, like most political solutions, it's abysmally stupid in both mandate and execution. It's all about testing and success in the artificial world of performing well on the test. The school where we worked is one where many kids come from dysfunctional homes and low expectations. The school's administration has been replaced by one which accepts the "reality" of the importance of scoring well on the tests, and so, many classes are now geared towards teaching children the tricks of how to get high scores on rigidly defined tests. These tricks are of questionable utility in any other context.

        Even before NCLB, much public school time was taken up with rote learning and repetition. {or worse, administrative crapola!} With very little research, you will discover the fact that this mode of education produces only short-term benefit, leading to the cycle of learn-test-forget-repeat which we all remember. Far better methodologies exist, but there are many political reasons why Skinner's methods trump Piaget's and Montessori's in the world of "public" education.

        Public education's goal is to reinforce the status quo, because the real customers aren't the children, but the government. This is not a call to become cynical, but, rather, a reality which must be dealt with. Most teachers and most parents will not accept the results produced by the system we are saddled with, and so, there is always room to find a way to make a difference. Make the most of the opportunity you have, and let us all know what you discover!
Re: Teaching Children How to Program
by Cap'n Steve (Friar) on Nov 16, 2005 at 05:21 UTC
    Yikes! Either those are some smart 12 year-olds or I'm a little behind the curve, considering that my final exam in programming as a high school senior was to make a Tic-Tac-Toe game in Visual Basic.

    The way I learned programming went in this order:
    1. Logic first: At around that same age with Turtle Tracks.
    2. Slightly more advanced: I learned some Basic in a math class at around 14.
    3. Perl: At 18 in community college. My final for that was a web page that would store names and phone numbers and allow adding and deleting.
    It seems to me like you're throwing them in the deep end pretty quickly, but then again I'm not exactly a great programmer so maybe it'll work.