Wanna Be A Programmer?

Posted on by Chris Warburton

Computers are all around us, and our lives are to a large extent controlled by them. Your bank balance, your phone calls, your email, messaging and Web browsing, games, wages and bills, music, video, literature and image production, trains, planes and cars, it's all controlled by computers.

Software is the stuff which controls computers, and therefore our lives. So who controls the software? Well, if you deal with proprietary software then it's usually controlled by some foreign corporation trying to wring money out of you. If you deal with Free Software then the control is still in the hands of the developers, however YOU can choose the developers. If you don't like what the original developers are doing then you have every right to fork the software and get some other developers to work on it and take it in the direction you want. Often this involves paying the developers a wage, but there is also another option: YOU can develop it yourself! The only skill you need is computer programming, which is a skill that can even be picked up by young children, as long as they have some exposure to it.

So how can YOU learn to program? Well if you're a complete beginner I would follow these steps:

1) Forget EVERYTHING you think you know about programming.

It's most likely bollocks, perpetuated by the media's obsession with stereotypes and putting flashing, unintelligible crap all over any computer monitor that appears on screen, and the proprietary software companys' desire to look like the crap they serve is somehow magical and unequalled. It's not. Programming is easy. It has to be, because computers are so unfathomably stupid. Just because Turner is able to create beautiful seascapes doesn't mean that a two year old can't scribble with a crayon, in the same way that simple programs are easy despite huge ones being hard.

2) Learn to think like a programmer.

2.1)

A nice way to get the hang of this is to play games like this one (NOTE: You may need to install SWFDec to play that). Light Bot features a very simple programming language to control a robot, it is easy to use since each command is an icon and the program (called "main method") is a grid which you drop the icons into then press Go (the program runs like English text, ie. starting at the top left and going across, then going down a row starting at the left and so on). The nice part about it is that the program can only be a maximum of 12 commands long, which is not enough to complete some levels, but there are two functions (reusable blocks of code) available to make repetitive things take less space.

2.2)

After you've completed that game a few times (there are 12 levels) you can go on to Guido van Robot (this may be in your package manager already), which is very similar to the Light Bot game but uses typed commands rather than movable icons, allowing you to make much longer programs. Even without Light Bot's restricted space it is still important to use functions like you've learned, as they are the best way to make large programs more manageble and less confusing. Transitioning from Light Bot to Guido van Robot is an important skill, since it makes sure you know the principles of programming (commands, functions, repetition, etc.) and how to use them, rather than just learning one specific programming language.

2.3)

After you've mastered Guido van Robot and can comfortably tackle any problem without difficulty or confusion, it's time to move on to something a bit less rigid in structure, like the old favourite Logo (there are a number of different Logo programs out there, you can try XLogo and UCBLogo). Logo is a programming language in its own right, but is often used with the "turtle" graphics system, a very similar concept to controlling the Light Bot and Guido van Robot (it can actually be used to control a real robot, but I'm assuming you don't have one :P ). The turtle can be moved to any pixel on the screen by giving it commands like FORWARD, RIGHT 90, and so on, plus it can draw a trail as it goes, allowing you to draw images. Taking advantage of the incredible speed of modern hardware you can make animations, by drawing lines, erasing them, then drawing them again in a slightly different way. Give yourself some problems to tackle, such as drawing a circle, making a function which can draw a circle to a given size (this uses the concept of "arguments"), drawing a spiral (this uses the concept of "recursion"), a stick man, an animation of a bouncing ball, making the ball squish slightly when it bounces, a windmill with turning sails and a growing vine. All of those are possible with a little thought, but remember to use functions and leave yourself a lot of comments throughout your code to remind yourself wha each bit does. When you can make those given examples without much thought you've mastered a lot of the art of programming. Well done :D

2.4)

There are many books out there which can help you learn to program. For instance How to Think Like A Computer Scientist. Googling for guides and tutorials on your language of choice is usually helpful too.

3) Learn one powerful programming language

Logo is a nice little language, but your programs can't really talk to anything else. This requires software called "libraries", and for libraries which are not written in your language of choice you will need a "binding" to access them. I don't know of ANY libraries which are written in Logo, or any bindings to let Logo access libraries written in other languages. This means you'll have to move on to something more powerful :( Since you now know Logo, which is a simplified form of the LISP language, it would be sensible to learn another simple, LISP-like language. I would recommend Scheme, which is a very powerful type of LISP, without a lot of the unneeded crap which exists in LISP. Guile is a very good Free Software Scheme system, which has bindings for many libraries, therefore I recommend your next step is to dive in and learn Scheme using Guile. It is very similar to Logo, except that every command is enclosed in brackets. If you want to make real graphical applications, there are bindings for the Gnome desktop, and even the new Clutter 3D graphics library. Now that you know Scheme you can do anything. Although some things are harder than others...

4) Learn the Object Oriented paradigm

In the same way that functions are an INCREDIBLY useful tool to make programs short, readable, understandable and maintainable, there are a few different progamming 'paradigms'; ways to structure and think about your programs and how they work, which will make your life easier and avoid getting headaches.

The first paradigm you used was "procedural programming", where the code describes the procedure to follow, "do this, then do that", but there are many more, some of which you've touched on. "Object Oriented" programming (OOP) takes functions one step further and groups them together into so-called 'objects'. To run a function you must ask the object which contains it. Objects have a type (a "class"), which can be a subclass of another class. For example "dog" might be a subclass of "animal", so that every function which "animal" can do ("breathe", "eat", etc.) a "dog" can do implicitly. Every object, for instance "Lassie", is an 'instance' of its class, for instance "Dog". Objects can also implement different roles (called "interfaces"), like "Lassie" can implement "Entertainer" and "Pet" (since not all "dogs" are "entertainers" or "pets"). By dividing a problem up into the different classes and objects it involves, the program becomes as simple as describing how they interact (eg. "lassie.fetch(big_stick)"). Learning the Object Oriented paradigm will make your life a LOT easier when you start to make large programs, but it is not very easy to do on your own.

5) EXPERIMENT!

If you have an idea or a question, try it out and see what happens! You can ONLY learn through experimenting and playing, there just isn't another way to do it.

6) Learn more languages

Scheme isn't the only kid on the block. There are many other languages you may like to learn. Good choices would be Smalltalk, Ruby, Python, Javascript, Vala and, if you're feeling masochistic, C, C++ and Java. The more languages you learn, the more approaches you learn to tackle problems with and the more you learn about why certain languages do things in certain ways (and therefore how to use them more efficiently). What may be hard in one language may be easy in another, so having a substantial set of knowledge is always a good thing.

7) Contribute to Free Software!

It might seem a daunting prospect to make your own Web browser, file manager or music player, but there are already many such projects out there with the code fully available for you to download and play with. Every Free Software project welcomes new developers, even if you're just fixing a bug which really annoys you. If you contribute to a widely-used piece of software like Firefox or Gedit then your changes, if approved by the maintainers, will be used by millions of people worldwide. If your changes aren't approved, but you would still like to make them available, you can keep them in a distributed version control system like Git or Bzr, letting you cherry-pick the upstream changes you want, and keep any changes you make yourself, and also let other people get your modified version.

Most importantly, don't be scared by all of the complicated stuff you see computers doing every day. Computers don't get harder and harder to program over time, they get easier and easier, since all of that fancy stuff has already been written! You might not understand how an image gets from the hard drive to the screen, but you don't need to know or care (I don't!), other people have already written libraries to do that. You just have to say something like "display(my_photo.jpeg)" and voila!

With computers becoming more and more integral to our way of life, I encourage everyone to at least attempt following some of those steps, if only to realise that computers aren't unknowable, magic things; they're understandable, controllable and most importantly they are changable. Posessing an attitude (like my Mum) of "I don't understand these things" is retarded. I didn't know how to piss standing up until I tried it.