Six Exercises to Learn Programming
Posted by: Rea Maor In: Programming - Thursday, November 1st, 2007So here are our future hackers, who have picked their first language, have gotten through all the intermediate exercises in the book. Right when you finish your first book in your first language, that’s when you feel curiously unsatisfied. You don’t feel like you’ve mastered the art, but you’re not sure where to go next.
These are some simple exercises in problem solving and design. They are suitable for almost any programming platform, and will be challenging enough that you’ll get a good workout while at the same time not be so intimidating that you’d give up. Furthermore, these are similar in scope to the kind of toy problems they might hand you when you interview for a coding job.
#1. A number-based casino game.
The point here is not to do a bunch of fancy graphics - keep it to the command line, and build the best simulator you can. A game like craps, roulette, or keno is very easy to simulate from the command line. This exercise will help you bone up on: random numbers, numeric ranges, light data tables and arrays, and building a simple interface.
#2. A card-based casino game.
Here again, you can just build a command-line simulation. Cards can be represented as “Ah, 10c, 8d, Qd, 2s” for instance. Poker, blackjack and Texas hold-em are all simple enough to simulate this way. This exercise will help improve large data table and array manipulation, since you have to keep track of what cards are where. Also, creating one “deck of cards” as a stand-alone object, which you can then drop into any game ready to go, will be your first run at practical object-oriented programming.
By the way, being good at programming casino games isn’t just empty exercise - if you haven’t noticed, the Internet is swarming with online casinos. Every time a site puts up a game, somebody got paid to code it…
#3. Conway’s Game of Life.
You can’t beat Life, the original cellular automation, for a handy toy problem. It’s just right for the intermediate programmer. And Life becomes a fascinating hobby in itself; there’s a broad hobbyist community out there frantically searching for the next P-232 glider gun or whatever. It has a jargon of its own… here’s a good guide to get started. This exercise will help teach optimizing for speed, two-dimensional array logic, and algorithms.
#4. A GUI interface for an existing command-line app.
I suggest this because a full program in GUI mode may prove frustrating. However, gluing a front-end onto a command-line program will be better for focusing on the important parts of a windowed or dialog program. You could do a front-end for a file compressor, a file manager that executes simple move, copy, and delete functions in the background, an IRC chat window, or dozens of other simple projects. This will boost your interface design, using window and widget toolkits, and simple callback control.
If you find that you’re really good at taking a complex command-line program and building an easy-to-use graphical front-end for it, you’re in luck. There’s dozens of open-source programs out there waiting for your magic touch, and GUI application programming is where a lot of the application money’s at, anyway.
#5. A graphics-based game.
As opposed to building a dialog application, making a game will require dealing with a raw graphics library, such as ncurses, SDL, VGA, Mesa, or OpenGL. You’re taking a mighty big step, here, so may I suggest something simple like an old arcade game? Pac Man, Tetris, or Space Invaders are all excellent first-time choices which all have minimal sprite animation. This will teach a lot more object-oriented design and complex interactions with a working graphics library.
#6. An editing tool.
By the time you’ve coded this far, you’re almost ready for the big time. And you’ve probably met with frustration at various editors you’ve used, and had some ideas on building one of your own. So give it a shot! Make a simple text editor, an HTML editor (easier than you think!), or if you’re really brave (don’t say I didn’t warn you!), an image editor. No, you do not have to produce Photoshop or Microsoft Office on your first try - go for light and fast with a few features. Who knows, you just might build a tool that’s so handy that you might end up using it yourself!
Related Posts:
- Slot Machine Hacking
- Free Software Graphics Programs That Aren’t Gimp
- The C++ Language
- Programming FAQ
- HOWTO Learn Programming






