Ok, I thought this would be an easy post, but apparently not. WordPress seems to choke wholehartedly on PHP code posted inside the TinyMCE editor. That is kinda rank. But I guess you get what you pay for, huh?
I posted about this entry at the PHP Developer’s Network Forums. But I thought it was good enough to recall here.
So my 10 year old daughter asked me to teach her how to write programs ‘like you do at work daddy’. So I brought her into the room, opened up and editor, had a brief discussion on servers and server-side language scripts, then explained what PHP is and how it works on the server, then had her write her first program.
So my 10 year old daughter asked me to teach her how to write programs ‘like you do at work daddy’. So I brought her into the room, opened up and editor, had a brief discussion on servers and server-side language scripts, then explained what PHP is and how it works on the server, then had her write her first program.
< ?php
echo 'hello world this is sarah';
?> |
This evolved into
< ?php
$text = 'hello world this is sarah';
echo $text;
?> |
At about this point my nine year old came and asked to participate along with us. So we got to throwing some stuff out and this is what we ended up with after about 20 minutes:
< ?php
$text = 'hello world this is sarah';
$num = 10;
$joiner = ' and I am ';
if ($num == 10)
{
echo $text . $joiner . $num;
}
elseif ($num == 11)
{
echo 'I am 11';
}
else
{
echo 'I am totally not 10';
}
$counter = 0;
$limit = 100;
$inc = 10;
while ($counter < $limit)
{
if (!($counter % 10))
{
echo '10 is a modulator of ' . $counter . '!';
}
else
{
echo 'I am only ' . $counter . '!';
}
$counter += $inc;
}
$now = time();
echo date('l F jS, Y', $now);
?> |
My daughters, in about 20 minutes, now understand how to declare and assign a variable, how to tell PHP what a string is and what an integer is, how to write a conditional (if/elseif/else), how to write a while loop, how to increment a counter, how to use a function (and what a function is) and how to read the PHP manual. Frickin amazing.
Me: How does PHP know when it is the end of the line?
They: The semicolon.
Me: What do the quotation marks on a variable value mean?
They: That the value is a string.
Me: If we loop do a while loop where a var is less than 100, what is the maximum value we’ll see when echoing the increment value?
They: 99.
Me: And if we change the increment value to 10, what is the largest value we’ll see?
They: 90.
Unbelievable. Even a 9 and 10 year old can get this pretty quickly.
/ apologizes for the blog like post, but I just wanted to encourage those folks that think this is too hard to pick up on. Start slow and it can be learned. Just ask my kids.
EDIT | I should note that they are by no means pros at this. But they have a strong understanding of the concepts, as evidenced by their ability to tell me what would appear on the screen as they read the code line by line.