Tom Says: Safe code is boring code!
The world of programming is on its way to becoming very exciting for budding programmers today. Where would I be now if it weren't for QBASIC and its demo game Gorillas? Or the endless directory of submitted programs from QBASIC.com? What an incredible hobby language it was. But it can't stand its own any more. Young people growing up with today's software standards can't be excited by the same technology that got me started.
That's what makes Hackety Hack, Scratch, and LittleCoder so exciting.
Turn Why's (Poignant) Guide to Ruby into a desktop application, and you get Hackety Hack. Another _why production, it's a multi-part tutorial that guides the beginner programmer through creating:
The way he makes such advanced functionality accessible to people that are copying, pasting (and hopefully tweaking) their first code ever isn't new or clever. He's just silently importing modules to make the commands available. It's really the presentation which makes the whole project worthwhile.
Testing real Ruby scripts usually involves reading the output in a terminal. That's the way why's Try Ruby! worked. But that's boring. Hackety Hack pretties output with flourishes like a "barber pole" to show that your script is running, AJAX popups with formatted output, dead simple forms, and an embedded Flash media player. Like Yahoo! Pipes, it eliminates the boring steps of complex processes like playing video or downloading RSS so that you're free to focus on doing something with the data.
For example, look at this code for downloading a YouTube video:
Hacker('why').load_program('youtube.rb')
YouTube.download 'http://www.youtube.com/watch?v=iEWgs6YQR9A', 'ROFLMAO.flv'
puts Video('Downloads/ROFLMAO.flv')
You probably don't have to think very hard to figure out what that does.
Note how the YouTube-downloading library is imported. A major feature of Hackety Hack is the ability for other users to share their code. Shared code can be downloaded using the web interface (see why's page for an example), or used directly with the Hacker('why').load_program method.
But for all it does, there's not much in the way for game-makers. Those people may be more interested in Scratch.
Scratch is what you might get if you used the Lega Mindstorms RCX code editor for graphics programming. Basically, you drag and drop code "blocks" on screen to change behavior behavior of sprites. Because of this, you get instant feedback. It reminds me a lot of making presentations with Ventuz, which uses a tree model, but is otherwise very similar.
I haven't used Scratch, so most of what I know about it was gleaned from the introductory video. I'm much more comfortable with text code than code blocks at this point, so it couldn't suck me in quite as deeply as this next project.
LittleCoder tries to fill the same niche as Hackety Hack and Scratch, and does an excellent job. But it doesn't take the same approach as either. It's neither a tutorial nor an application. It's a Ruby interpreter with DirectX bindings, plus a little extra.
You use it much like a library. All the program does it start a DirectX event loop and run code in a file called "main.rb." That's where you put your code. It gives you some hooks (roughtly the same basic hooks as you would have when programming DirectX directly), and some helper classes for graphics and sound. It manages your sprites and audio resources to a greater extent than, say, pygame, but all this means is that only the fun part of game-making is left.
All the basics can be done with one-liners. You might play a one-off sound with code like Scene.new_sound("beep.ogg").play. You show images with Scene.new_tile("demoblob.png"). After creation, the image is imediately rendered, and redrawn every frame until you quit (or hide it). You create animation by scaling, translating, and otherwise brutalizing that sprite object until the user hits Escape and it all goes away. Experienced programmers might need to take a few breaths and get over LittleCoder's obvious inefficiencies to appreciate it, or at least I did. But I was curious enough to actually try it out.
Just to see how easy it would be, I made a little Tetris clone this afternoon. In just a couple of hours, I had a decent-looking clone with all the basic controls in about 200 lines (without comments). The code is somewhat long and dirty, but it was easy to write. LittleCoder's API is so simple that I only referenced it for about the first 30 minutes. After that, everything came naturally. LittleCoder made things dead simple. As the site says:
LittleCoder is all about experimentation. Just try things, see what happens. Stuff will probably explode, but thats okay!
I had my share of explosions---infinite loops cause the program to hang and need to be quit with force, and most exceptions are silently consumed---but with a little bit of creative debugging I got everything to work. I even learned in the process. Overall, it was a great experience that I'll likely revisit in the future.
Programming Trivia is an article with programming problems I came across in my own code, with notes on my possible solutions. This page is not directed at beginners, but might be interesting to some.
Posted Apr 29, 2007, in the late, late night. Updated updated May 29, 2007, in the late, late night.