Learning to Program

by Alan Gauld

Stop Press! Last Update: 27th May 2007

The Web Site

Welcome to the Learning to Program web tutor!

I've been very busy in my day-job over the last year so very little progress has been made, however I am working on the first web programming topic. Meantime there have been several tweaks to the existing topics, including many minor bug fixes and some changes to the colour scheme to reducethe contrast which some folks felt was a bit glaring. The other significant change is that the wxPython example in the GUI topic has been updated to work with the latest versions of wxPython.

The original version of the tutor using TCl and QBASIC is still available here.

The Book

Latest news on my book is that it has moved to print-on-demand. Basically this means that copies are only printed when firm orders are received from retailers. Logically this means you are less likely to see it in the shops but you can still place an order and it will be delivered, it just takes a little longer is all.

The book is now significantly different to the new web site although the basics remain the same. It is stuck at Python version 1.5 and doesn't have the new material, although it has extra examples of its own plus several extra chapters compared to the web site. These include an additional case study for an OO games framework. (A fully commented version of the framework is available on the old Useless Python website as hmgui.zip)

You can order the book on Amazon by clicking here. Most of the other online bookshops have it in stock too.

There is also a Japanese version available from the Japanese branch of my publishers.

I now have a web site set up listing errata and providing opportunities to send feedback and questions.
Please pay a visit if you've bought the book!

The Future

As I said above I am still adding new topics added as part of a new section looking at practical applications of programming. This is in response to many requests from readers who say - "OK, Now I know how to program, but what exactly can I do with my new found skills?" These topics do not feature any VBScript or JavaScript. I'm also playing with the new version of wxPython and may include more GUI stuff based on that at some stage. Also the standard Python library now includes the Tix library which adds extra features to Tkinter so I might write something about that too.

There is a Polish translation underway and the Czech version has been updated to reflect the latest version. As ever, Petr has been my most exacting reviewer and I thank him for his many corrections. Any remaining errors are entirely my fault!

The book is stagnant I'm afraid, but once I get the new topics written I might sound the publishers out about a second edition updating it to the latest version of Python, whatever that will be by then, and adding the new material. But don't hold your breath waiting on that one...

Non English Editions now available!

Martin Pozzi was the first to translate the tutor (into Spanish) and he has now been followed by several others. The following versions are available:

Language Translator
Czech version Petr Přikryl
German Bruno Schaefer
Korean johnsonj
Italian Luca Fini
Portuguese Wilson Edgar
Spanish Martin Pozzi

The tutorials above are all usable but at different stages of completeness compared to the web site. That's because they reflect the state of the web site at the time of translation. The Czech one in particular is very professionally presented including a very attractive appearance. I was so impressed with the style that I have used Petr's stylesheets as the basis for the English version. Hopefully I'll get round to changing the other language editions too.

I think all of the translators deserve a vote of thanks for their efforts in putting this together. It's always better to read a translation of an old tutorial than to struggle reading a new one in a foreign language! If anyone else wishes to do a translation, or update any of the existing ones, just send me an .


As mentioned above there is a Japanese version of my book available too.

New Stuff

Not much because of the work pressure mentioned above!

Download Archive Format Change

I'll be posting both zip and tgz versions of the site from time to time. I don't promise that they will be perfectly up to date but I'll try not to let them get too far adrift. If you want the latest then check the online version.

Linux users can download the tar/gzip version.


Windows users should be able to use that version too since winzip and the freeware archiver Quick Zip by Joseph Leung can both cope with tgz format. I'll also be using tgz format for the non English versions, just look at the bottom of the contents frame for a link.


Finally I have made a basic PDF version available too, it doesn't have any fancy navigation features like bookmarks but if you like PDF format it's here.

And Palm Users Too...

One Palm user has created a Palm doc file of the old site. I haven't had a chance to try it yet but offer it here for those who want it. If anyone has problems with this one then you're on your own, it's unsupported. But hopefully it will be useful to someone. If you don't have a Palm doc reader you can find a choice of freeware ones at this site.


Introduction - What, Why, Who etc.

Why am I writing this?

The reason I am creating this tutorial is that there seems to be very little for the absolute beginner to programming on the Web. Yet the Internet and the Web encourage interest in computers and that interest naturally leads to a desire to "take control", which means learning to program!

Why me? Well I am a professional programmer who came to programming from an electronic engineering background. I have used (and continue to use) several computer languages and don't have any personal interest in promoting any particular tool or language. Oh, and when I started, nobody else seemed to be doing it! Since then several other tutors for beginners have appeared, but this one seems to have acquired enough of a fan base that I'll keep it going.

What will I cover

As much as I can. I will cover the basic theory of computer programming - what it is, some of its history and the basic techniques needed to solve problems. I will not be teaching esoteric techniques or the details of any particular programming language, in fact I'll be using several different languages, since I believe its important to realize that different languages do different things well. That said, the majority of the course will be in the language called Python.

Who should read it?

Put another way: what do I expect the reader to know already?

I expect the reader of this tutorial to be an experienced user of a computer system, probably MS DOS, Windows or Unix although others should be able to cope too. I also expect them to understand some very basic mathematical concepts such as geometric coordinates, sets, and basic algebra. These are all important in todays programming environments, and many programming concepts are based on these ideas. However the depth of knowledge needed is very low and if you do find the math getting too hard, you can usually just skip over a few paragraphs, try the code as it is and hopefully the penny will drop even if the math still confuses you.

One thing you should know is how to run commands from your operating system's command prompt. In Windows this is variously known as a DOS box, the MS DOS Window or MS-DOS Prompt. Basically it's a black window with a white text prompt that usually says C:\WINDOWS> and you can start it by going to the Start->Run dialog and typing COMMAND into the entry box and hitting OK. If you use Linux then you should know all about terminal windows and on MacOS you can run the Terminal program under Mac OS X (which is found in the Applications->Utilities folder).

I will not be covering issues like how to create or copy text files, how to install software, or the organization of files on a computer storage system. Frankly if you need to know those things you probably are not at the stage of being able to program, regardless of your desire to do so. Find a tutorial for your computer first, then when you're confident with the above concepts revisit this site.

Why Python?

Python happens to be a nice language to learn. Its syntax is simple and it has some very powerful features built into the language. It supports lots of programming styles from the very simple through to state of the art Object Oriented techniques. It runs on lots of platforms - Unix/Linux, MS Windows, Macintosh etc. It also has a very friendly and helpful user community. All of these are important features for a beginner's language.

Python however is not just a beginner's language. As your experience grows you can keep on using Python either as an end in itself or as a rapid prototyping language. There are a few things that Python is not well suited to, but these are comparatively few and far between.

I will also use VBScript and JavaScript as alternatives. The reason for this is to show that the same basic techniques apply regardless of the language details. Once you can program in one language you can easily pick up a new one in a few days. Why those languages? Well, for a start they have very different styles to Python so form a useful contrast, and more prosaically if we accept that most Web surfers who are also beginners are using PCs with Microsoft Windows installed, there is a programming environment built in to the operating system called Windows Scripting Host which has support for VBScript and JScript (which is Microsoft's variant of JavaScript). In addition anyone using Microsoft's web browser can also use these languages within their browser, and in fact JavaScript should work in almost any browser. We'll only look at how to run VBScript and JavaScript inside a browser, investigating WSH I'll leave as an exercise for the interested Windows user!

Other resources

There are other Web sites trying to do this in other languages (and in the time since I originally created this site a few other Python sites have appeared). There are also lots of tutorials for those who already know how to program but want to learn a new language. This section contains links to some of those that I think are worthwhile!


Next  Contents

If you have any ideas on how to improve this tutorial
please feel free to