Teaching programming part 2

Ok here’s my favorite program to play with for teaching children their first lesson
// Simulate the world being destroyed (or prospering)
using System;
namespace worldsim
{
class MainClass
{
public static void Main(string[] args)
{
// Number of life forms on Earth
int people = 400;
int animals = 300;
int plants = 500;

int day = 0; // Days past since start of simulation
int maxDay = 100; //

// while days not maxed and there are more than 0 people
while(day 0)
{
people = Convert.ToInt32(Convert.ToDouble(people) * 1.02);
people--;

animals = Convert.ToInt32(Convert.ToDouble(animals) - (Convert.ToDouble(people) * 0.1));
animals--;

if (animals < 0)
{
animals = 0;
// Starving people
people = Convert.ToInt32(Convert.ToDouble(people) * .9);
}

day++;

// Show daily populations report
Console.WriteLine("day: " + day);
Console.WriteLine("people: " + people);
Console.WriteLine("animals: " + animals);
Console.WriteLine("plants: " + plants);
Console.WriteLine();
}
}
}
}

I just give this code to everyone after briefly explaining a few basics of programming, introducing them to a terminal, etc. Programming in crazy. You can’t just learn it quickly through lecture; you learn by doing. This program is a primitive world simulation where humans and other lifeforms exists, eat each other, and reproduce. By a few lines of code we can make the population explode, die out, or attempt to reach equilibrium. The Convert.Towhatever I say is evil magic for now and just copy and paste it as needed. Same with using System; The ; is evil magic too, designed to make programming hard. The point is to have fun. You know its working when kids start coding in lines that contain words they think you would yell at them for writing. The best part is you see how each student learns almost instantly! Some will do exactly what you tell them and try to make a persistent where all the creatures co exist. Some will work together while some will turn to you for help. Now you can cater to each type. The students goofing around thinking they are 1337 haX0rs making flying pizza’s attacking digital humans while want more challenges and must be allowed for creativity, else they will start playing video games. Others need some hand holding and more explicit direction before they get too deep into all this crazy programming jibberish. Either way is fine.

This program also makes a great lead-way to learn object oriented programming, since it’s easy to make people into objects with methods like eat, reproduce, etc. But that’s later. Now they need to know how to program and what the “evil magic” is. This stuff is boring at first, but hopefully after seeing what programming can do they will be motivated for the task. Also I stay away from integrated development environments at least for a lesson or two. They teach kids to follow the evil magic of pressing buttons and suddenly the code works. This leads to treating code like witchcraft. They might start putting ;’s all over the place just to make it work, instead of figuring out why the ; should be there in the first place. That’s a bad habit that some people never break out of. They need to know what a complier, managed vs unmanaged code, and libraries are. Lectures about these topics are garbage if they know pressing F5 makes the program magically work, they will ignore you. Sure you could test them on knowing these buzzwords, but then they memorize instead of comprehend. So get in a terminal and compile! Make sure all the evil magic of programming is turned into understandable ideas.

Oh and one more thing, please don’t use the boring Lets Make a Calculator! program. Try to get feedback from kids and let them decide what they want to make. They are learning concepts, not how to make a stupid program that’s already been made 100,000 times before.

2 thoughts on “Teaching programming part 2”

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA Image

*