I've been asked by friends and acquaintances who want to get into computer programming what to do. I find myself wanting to recite the same things over and over again. Rather than do this, I thought it might be easier to put my thoughts up online.

Why learn to programme computers?

There are a number of reasons to learn to programme computers:

  1. It's useful. A microwave cooks food. A washing machine cleans garments. A computer runs programmes. For most people, this will be software that's available commercially or free from the Internet. If you know how to programme a computer, you can tell it exactly what you want it to do. One thing that computer programmers find incredibly frustrating is watching other people do the same thing over and over again on their computer. Whenever I see that, I always want to say "why are you doing that? The computer is there to do that for you!". Those who can programme their computer can get a lot more done because they can automate repetition. Sometimes programmers take this to excess and spend hours writing a programme to do something when they could just get on and do it in half the time.
  2. It's a commercially valuable skill. Because it's useful, programming is also valuable as a commercial skill. This means a number of things: firstly, it means that one can get a job building software or websites or whatever. But it also means that if you are in business, you can write little programmes that make things more efficient. This seems to me to be the great unserved need: Google write software, but small companies don't.
  3. Computer programming lets you think about mathematics in a practical way. When a maths teacher bangs on about Base 10, many students turn off. If you are involved in computing, the actual use of, say, decimal numbering (vs. binary, octal, hex) becomes clear. Functions, algorithms, set theory, geometry and logic - all are important in programming, and unlike in the classroom, getting logic wrong means that code doesn't compile or errors happen. This can have actual real world effects - planes crash, missiles misfire, people lose money and so on (see Therac-25 and MIM-104 Patriot).
  4. It helps you understand your computer better. To most people, computers are a big, scary magic box. They really aren't. They seem magical, but if you know where to look, you can learn every step of what goes on when you do something. When, for instance, you print out a document, you can understand down to the bits and bytes what is going on, at least in overview. This is intellectually satisfying, but it's also liberating in a very practical sense: by knowing what is going on, you free yourself from nonsense perpetrators - when someone comes and says that their software is powered by "whizbang hyperclouds", you can say "what on earth are you talking about?". Understanding computers tends to make one more sceptical regarding claims people make about them - the people most opposed to, say, new government IT projects like DNA databases, ID cards and the National Identity Register tend to be people with expertise in computing. That's because we know what the risks are, and we know what nonsense has been used by IT suppliers to sell the state on the scheme. This kind of healthy scepticism and bullshit detector is something sorely needed in most areas of life. Science, criminal investigation, philosophy, history - all require a sceptical outlook. Programming computers makes many think more logically, more sceptically and to try and see bugs before they appear rather than just telling oneself that it'll all be fine.
  5. It's a lot of fun! It's really very exciting to have the computer do what you want. There is a real warm satisfaction in getting the code to work just how you want it to.
  6. For plenty of us, it's the one thing that we're actually really good at. We often discover other things we are good at, but at least during our childhood years, sometimes computer programming is the only thing we don't suck at! Many programmers try to imagine what on earth we would be doing if we couldn't hack around with computers. I tend to think that we'd find other things to do that'd fill our time.

What sort of skills do I need?

To be a good programmer, you need to be able to think logically and abstractly. You need to be able to cope with complexity - this webpage is just a bunch of ones and zeros sitting on at least one computer, but there are many layers of abstraction. Each layer of abstraction adds more complexity.

Beyond the intellectual skills, you need to have a lot of patience, persistence, the ability to be calm rather than panic when faced with a problem, be able to communicate clearly, open to collaboration, and be able to cope with sometimes very opinionated, abrasive people. Being able to absorb and retain large quantities of information is helpful.

Most of all, you need to be creative and interested in solving sometimes difficult problems.

What about mathematics?

Some people say that mathematical ability is required to be a good programmer. This is sort of true: the logic and rigour that mathematics requires and inculcates is a very useful thing in programming. Some types of programmes that you might choose to write will require you to have knowledge of higher mathematics, although not all will. Many of the theories in computer science will require mathematical knowledge and ability to understand.

There are many programmers (myself included) with minimal formal education in mathematics. My final qualification in mathematics is a grade B at GCSE level (age 16 that is). Part of the problem, I am told, is that the way we teach mathematics in schools sucks and puts people off. I'm pretty sure this is the case. I'm sure that if I were to apply myself seriously to the problem, I could learn a great deal more mathematics than I currently do. Formal logic (in philosophy) all looked like jumbled-up incantations, but I can unpick that (and, in my opinion, my programming skill has improved for it).

I think it can be summarised thusly: if you know your maths, great, you'll probably find programming easier than if you didn't. If you don't, don't worry about it. You can pick it up both by osmosis and by self-study. If you are completely unable to think logically and even grasping the lowest level of abstraction eludes your feeble brain, well, programming may not be for you.

See these discussions for further information and perspectives on this:

My first programming language

Have I convinced you that learning to programme is a good idea?

Okay, then we should probably choose a programming language to use. Back when I first started using computers, the computers on the home user market already had the choice of programming language made for you. They all came with some version of BASIC, and that version differed ever so slightly from the other versions of BASIC on other computers. My first language was BASIC - AMSBASIC (from Amstrad) and BBC BASIC (from, duh, the BBC).

Choosing a programming language is an interesting thing. Some people think of programming languages a bit like standards: they look at computer programmers as a community and see thousands of languages and then wonder why we have them. Couldn't we just come up with one true language that we'd write all software in? That would be nice. The reason we have lots of programming languages is that they are good at different things. You can express the same thing in many different ways. The reasons why people use a particular programming language fall into many different categories: some of it is subjective and based on personal preference. For instance, I use Ruby because I like the way it looks. It is a nice language to read. I like the fact that it has some fairly lax rules about syntax. I like the fact that I don't have to hit my 'shift' key as often as in other languages I have used. There are some other reasons too which are subjective. But there are objective reasons too why some languages are more suitable than others: some languages actually run faster on some machines, some have more advanced compilers or interpreters, some have better libraries available for achieving a particular task.

What does a newbie need out of a programming language? What about kids? This list are some of the features I'd suggest a programming language should have for a beginner:

If the programmer is a child, we can add one more requirement to the list:

Amazingly, with the exclusion of the children-specific requirement, most of those requirements are pretty much the same things I look for when I'm evaluating a programming language. I add a few extra things and deprioritise a few on the list, but the requirements are ridiculously similar.

What languages satisfy this list?

Most people will immediately respond: "Python!" Python is well-documented, has tons of good example code. The syntax irritates me slightly, but a lot of people really like it. It's consistently designed by smart people who know what they are doing. It's actually a useful language both for learning and for actual practical application - it's used heavily at Google. It has an interactive REPL - Read-Eval-Print-Loop system. This means you can develop code by typing it directly into a shell. The user community tends to be helpful and generous with their time. They also have worked hard to make sure there are a fair few libraries available for children. Python is especially good as it's been designed specifically for teaching.

Even if you move on to other languages, learning Python is a wonderful experience. Unlike other languages I have seen that target beginners, it doesn't teach bad habits (as BASIC used to, and, in my humble opinion, PHP still does). For kids, there are a number of modules and projects based around Python that are good ways to learn: there is a good turtle graphics mode, there's PyGame and much more. Have a look at Snake Wrangling for Kids. The One Laptop Per Child project also include Python on their laptop as a language for children and newbies to learn.

Ruby is also a wonderful language that satisfies many of those criteria. The syntax differs in some interesting ways from Python, and there are less modules available - there are certainly not many modules for children, so I'd perhaps not suggest Ruby as a great language for kids. But for adult newbies, I think Ruby is a fantastic first language. It's also one of the languages I use most often.

There are some programming languages that have been designed specifically for children: Scratch and Alice. Of the two, I prefer Alice. Alice is interesting because it works in a 3D world by default - all the objects are 3D graphics which interact with each other. Another reason it's quite interesting is that you can actually construct a world in Alice's 3D environment and then see what it would be like in Java code. Don't be put off by the fact that these are programming languages for kids: they are just as useful for teenagers and adults to use. I know, for instance, that Scratch has actually been used successfully to teach students at Harvard Law School to help familiarise them with the sort of thing that programmers do (so they can think in a richer way about Internet and computing-related law and policy issues).

What do I actually need to start?

Simple:

You may have both already. Most Linux installations these days have Perl and Python already installed. OS X already has Perl, Python and Ruby installed. They may not be the very latest version, but that doesn't actually matter.

As for a text editor, if you are running Windows, you already have Notepad. Notepad is perfectly fine, but it's a bit limited. Have a look at TextEditors.org to find a good text editor. It doesn't matter which one you use, so long as you are comfortable with it.

With any new programming language, try and find a decent tutorial to go through. Python's wiki has a list of tutorials for non-programmers.

Powered by WiGit