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.
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.
advertisement
- Getting to grips with Microsoft's IT Health Environment Scanner
- Virtualise your servers
- The changing face of travel gadgets
- Build your own distributed file system
- The bulletproof Dell that costs an arm and a leg
- Microsoft Office 2010 Technical Preview: Q&A
- Lawnmowers, the TyTN II and one odd insurance request
- There'll never be a bulletproof OS
- How far can we trust apps?
- Five nice touches in Outlook 2010
- Why Britain's watchdogs have fewer teeth than goldfish
- Tabbed documents: how to make Office 2010 great
- Outlook 2010 People Pane – does it spell death to Xobni
- Microsoft Outlook 2010 screenshots
- Co-Authoring in Word 2010 and SharePoint Foundation 2010
- Microsoft Outlook 2010 screenshots: Backstage view
- Flash 10.1: Developing for Desktop and Device
- Microsoft Office 2010 screenshots: Recover unsaved items
- Microsoft Word 2010 screenshots: Text Effects
- Microsoft Word 2010: inserting screenshots
- Q&A: Why Conficker was a victim of its own success
- App developers losing faith in Android
- Biz Stone: Murdoch's Google veto will "fail fast"
- Google adds automatic captions to YouTube
- China ramps up cyber spying
- Mozilla maintains dependence on Google
- Windows 7 flying off the shelves
- Google Chrome OS: full details unveiled
- AOL slashes 2,500 jobs
- YouTube begins streaming full-length shows
advertisement
Printed from www.pcpro.co.uk


