perlmeditation
Sandy
Skript_kiddies
Hi all,
<p>
I am just about to begin a course in programming to a bunch
of 12 year olds at my son's school.
<p>
To the dismay of some, and the amusement of others, I will
be using Perl as my language of choice.
<p>
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,
<blockquote>"Bwa Ha ha ha ha!"</blockquote>
<p>
On a more serious note, I would like to have comments regarding
what and how I will teach these young impressionable
children.
<p>
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 <i>action</i>!
<p>
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.
<p>
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.
<p>
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.
<p>
Here is a simple 'sketch' of my course plan. Any comments (please
be gentle) are appreciated.
<p>
<readmore>
Always, always, use good comments!
<p><b>Item</b><p>
Explain: (1) how to use an editor, (2) what is a perl script,
(3) how to run a perl script.
<p>
Create simple hello world scripts. Run them. Explain each line, especially
how <code>use strict;</code> is almost mandatory. Play with the colours of
Tk.
<code>
#!/usr/bin/perl
use strict;
print "Hello World\n";
</code>
and
<code>
#!/usr/bin/perl
use strict;
use Tk;
my $mw=MainWindow->new(-title=>"Hi Kids!");
$mw->Label(-text=>"Hello World")->pack();
MainLoop;
</code>
<p><i>Concepts to Learn</i><p>
* the shebang line (although not needed for Windows, why not?)<br>
* <code>use strict</code><br>
* quotes<br>
* (variables to be skipped until later)<br>
* the <code>use</code> statement, what libraries/modules are, re-use of code,
etc<br>
* command line vs gui<br>
* symple syntax rules<br>
<p><b>Item</b><p>
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.
<p><b>Item</b><p>
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.
<p><i>Design</i><p>
must design a grid, where to move, etc.<br>
<p><i>Concepts to Learn</i><p>
* variables<br>
* Tk function <code>canvas</code><br>
* Tk canvas function <code>create_rectangle</code><br>
* Tk function <code>repeat</code><br>
* subroutine callbacks (very simplistic explanation at this time) <br>
* simple debugging via print statements<br>
<p><b>Item</b><p>
Once we have a moving square, control it via the arrow keys.
<p><i>Design</i><p>
Use a simple variable to keep track of what direction the square
is moving in, change this variable depending on what key is pressed.
<p><i>Concepts to Learn</i><p>
* binding to events<br>
* logic statements (<code>if (...) {...})</code>)<br>
* passing parameters to subroutines<br>
<p><b>Item</b><p>
Detect if square bumps into the edges of the canvas
<p><i>Design</i><p>
Create border edge of canvas object.
After every move, check if square coordinates are outside of allowed
area.
<p><i>Concepts to Learn</i><p>
* loops and conditional loops<br>
* <code>unless</code><br>
* stopping Tk <code>repeat</code> functions via <code>cancel</code><br>
* returning information from a subroutine via <code>return</code><br>
* get coordinates from a Tk canvas object<br>
<p><b>Item</b><p>
Take time out to play with the colours, the sizes. Let the students
personalize their own program.
<p><i>Concepts to Learn</i><p>
* The programmers are the masters of the program<br>
* computer colours (red-green-blue) etc<br>
<p><b>Item</b><p>
Make a food pellet and eat it. Keep score.
<p><i>Design</i><p>
How to place food. Where, when, etc. Keep and display score.
<p><i>Concepts to Learn</i><p>
* random function<br>
* Tk label<br>
* pointing to variable addresses i.e.
<code>-textvariable=>\$score</code><br>
* variable scoping<br>
* Probably lots more debugging via print statements<br>
* Why <code>$x==$y</code> doesn't always work for floating point
numbers, depending on the operating system, etc. etc. etc.<br>
<p><b>Item</b><p>
Make the worm grow when it eats the food. Lose game if the worm
eats it's own tail.
<p><i>Design</i><p>
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.
<p><i>Concepts to Learn</i><p>
* arrays<br>
* array order<br>
* push,pop,shift,unshift<br>
* looping over arrays (<code>foreach</code>)<br>
<p><b>Item</b><p>
Add sounds
<p><i>Design</i><p>
Decide what events should trigger sounds.
<p><i>Concepts to Learn</i><p>
* using gooble<br>
* how to find free sounds using google<br>
* <code>use Win32::Sound</code><br>
* directory structures<br>
* <code>use FindBin</code><br>
<p><b>Item</b><p>
Add start/stop/continue buttons
<p><i>Concepts to Learn</i><p>
* Tk buttons<br>
* more binding<br>
* Tk colours (background vs highlightbackground, etc.)<br>
* Cleaning up old stuff before restarting game<br>
<p><b>Item</b><p>
And so it continues, with the students driving the modifications at this
point.
<p>
* Change the scoring depending on how many moves the user makes before eating
the food? <br>
* Different levels with different obstructions?<br>
* Different difficulty levels (vary speed, size, etc.)?<br>
* 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.)?<br>
* Making a menu?<br>
</readmore>
<p><p>
I volunteered for this. Now I'm panicked. Too late to turn back....
AAAaaaahhhh!
<p>
Remember me fondly,
<p>
Sandy