Skip to navigation

PCPro-Computing in the Real World Printed from www.pcpro.co.uk

Register to receive our regular email newsletter at http://www.pcpro.co.uk/registration.

The newsletter contains links to our latest PC news, product reviews, features and how-to guides, plus special offers and competitions.

Real World Computing

Programming for kids

Posted on 28 Apr 2009 at 12:02

MySQL fan Ian Wrigley discusses computer programming for children, and goes back in time with linux.

To give you a taste of just how easy things are to create, try downloading Shoes and following along with this basic tutorial. For your first program type the following Shoes code into a text editor. If you don't have a programmer's editor on your machine then just use the faithful old Notepad on Windows, or TextEdit on the Mac (being sure to choose "Make Plain Text" from the Format menu). When you're done, save it as program1.rb.

Shoes.app {

background red..white

@btn = button "Click me...", :margin => 10

@text = para "", :margin => 10

@btn.click {

@text.replace "Hi there! You clicked the button!"

}

}

Once it's saved you can run it by launching Shoes from the Start menu on Windows and selecting your file when you see the file selector box, or else just launch Shoes and choose "Open..." from the File menu on the Mac and select the file. You should see a window appear with a graduated red-to-white background and a button. Click on the button, and the text will appear.

If you've ever done any programming before - or even if you haven't but you have a relatively logical mind - that code should be pretty easy to understand. All I've done is specify that the background should go from red to white and then I've created two graphical elements, a button and a blank textbox, insetting them both by a 10-pixel margin from the edges of the window. When the button element is clicked, the blank textbox is replaced with that "Hi there..." message.

Let's get just a little more complex now. Type the following program into your editor as before:

Shoes.app :width => 300, :height => 500 do

background white

stack :margin_top => 50, :left => 50, :width => 200, :align => 'center' do

para "Simple addition"

@f1 = edit_line(:width => 30)

@t = para "+"

@f2 = edit_line(:width => 30)

@b = button("=")

@res = para ""

end

@b.click do

@res.replace @f1.text.to_i + @f2.text.to_i

end

end

In this program I've created two edit fields and a button, and when the button is clicked the @res paragraph is replaced by the sum of the values you enter in those two text fields. The only tricky thing here is that I needed to turn the text values in those two fields into numbers, and I did this using the standard Ruby method to_i which tries to convert any data type to an integer. (Incidentally, since Ruby supports fractions called Rationals and complex numbers right out of the box, this program can be trivially modified to add those too.)

These aren't particularly exciting applications, but they're just the very tip of what you can use Shoes to program. For example, take a look at the screengrab of a game of Tetris on this page, which was completely programmed in Shoes. Its source code is freely available on the website along with the code for tons of other games and utilities.

If you have a child who's starting to get interested in programming then Shoes might just be the way to get them started off. It isn't perfect of course and there are bound to be frustrations as you learn your way around the different widgets the graphical builder offers, but it's a great little utility, and I really like it despite the incredibly irritating, cutesy feel of the manual. Those who know me well will confirm that for me to accept something that irritating means that the product must be something quite special...

Managing MySQL

Regular readers will know that I'm a huge fan of MySQL. In fact, I have to declare an interest as I'm currently working for Sun/MySQL as a trainer here in the States, teaching courses for database administrators and the like: take that as a disclaimer concerning any positive mentions of the product I make from here on in.

1 2 3
Be the first to comment this article

You need to Login or Register to comment.

(optional)

Ian Wrigley

Ian Wrigley

Ian Wrigley runs W A Communications, a Los Angeles-based technology consultancy. He's an advocate of open-source technologies, particularly on the server side, and is on the board of directors of the British Academy of Film and Televsion Arts/Los Angeles.

Read more More by Ian Wrigley

advertisement

Most Commented Real World Articles
Latest Real World Computing
Latest Blog Posts Subscribe to our RSS Feeds
Latest News Stories Subscribe to our RSS Feeds
Latest Reviews Subscribe to our RSS Feeds

advertisement

Sponsored Links
 
SEARCH
SIGN UP

Your email:

Your password:

remember me

advertisement


Hitwise Top 10 Website 2008