Learn To Program 2: Ground Rules
So you’ve decided you want to learn computer programming. That’s great! Now what?
I’m not going to start teaching you to write programs in this article; instead I’m going to give pointers and topics for thought that apply equally to all beginning coders.
Self-taught or go on a course?
Until relatively recently there weren’t any official courses for software development, so most or all of the old-timers were self-taught.
Self-teaching has risks and benefits. You can work at your own pace, on topics that match your interests, in the comfort of your home, and create the applications you want to create. However, without the benefit of peer review, it is easy to develop bad programming habits, write programs that are inefficient and improperly written, and generally head in the wrong direction without knowing it. A lot of self-teaching material both on the internet and in books is dross, but as a beginner it is hard to tell the difference between a good tutorial and a bad one.
On the other hand, I have a masters degree in Computer Science and I can say that it was a complete waste of time and money. They taught nothing that wasn’t readily available and better explained in much cheaper books, much of the teaching was irrelevant to real-world programming, much of the material was out of date by modern programming standards, and worst of all, the course was presented in such a way that if I hadn’t known programming could be exciting before I started, I would have certainly lost my interest long before the end. On top of that, no employer has ever asked to see my degree – they just look at the portfolio on my web site to see that I know how to write modern code.
If you have the discipline required, I would recommend a combination of self-teaching and constantly asking questions and seeking peer review online. Sites like stackoverflow.com are great for beginning programmers; there are many experts there who are happy to take sensible questions from newbies and answer them constructively, along with an enormous library of existing questions and answers.
Why algorithms matter
An example will illustrate: suppose we have a bunch of numbers like 1, 3, 8, 23, 104, 500, 750, 1020, 1021, 1022, 3456. If asked to search through this data to find where 1022 is, a typical beginning programmer might write a program to examine each number in turn from the start, until 1022 is found. This works, but it’s a bad solution. Because the numbers are sorted in order, we can instead use something called a binary search. A binary search starts in the middle of the data and cuts it in half on each turn. For example, here the search will start with the “middle” number – 750. The number we are looking for is higher than this, and because we know all the numbers before 750 in the list are smaller, we can immediately ignore all of them. This leaves 1020, 1021, 1022 and 3456. We then pick the middle number again – there actually isn’t one here so either 1021 or 1022 will be chosen. In just 2 (or at most 3) attempts, we have found the number we want – checking each number in turn from the beginning would require 10 attempts.
To successfully teach yourself, you must practice rigorously. No amount of reading books and theory will help if you don’t sit down and code! Take any examples and tutorials you find, and alter them to see how they behave when you change the code. Satisfy your curiosity. Set yourself exercises or look for simple exercises on the web. Some programming books also contain exercises – sadly they are few and far between and mostly aimed at advanced programmers.
One very important thing when self-teaching is to check out algorithms – this means things like sorting, searching and generally re-arranging and crunching through data. An easy mistake to make as a beginning programmer is to try and work out how to do these things yourself and then come up with a slow or inefficient solution. Virtually every type of operation you may want to do already has well-established and tested algorithms (ways to do it), and usually more than one, so that you can pick the one that is most efficient for the kind of work you are doing. Many books teach the “how” of writing code but they do not teach algorithms.
Buy some books
There is a plethora of great resource material out there in both tutorial and reference format; there is also a lot of badly written hard-to-understand dross. The publisher of a book is often a good indicator as to its quality: books from O’Reilly, Wrox Press (now defunct but the books are still available) and Apress are generally of a high quality. Be wary of anything from Sams Publishing and don’t buy a For Dummies or a Learn In 21 Days-type book as they are usually thin on content and not very well-written (there will, of course, be exceptions both ways).
Be wary when choosing your book not to pick one that is too old. Languages evolve quite quickly and a book that was relevant 10 years ago may contain examples that don’t even work in today’s programming environments.
It is hard for me to recommend current beginners books, simply because the ones I read are very old and I haven’t needed to buy any beginners books for some years! However Google will help here, simply search for “best xxx beginner book” where xxx is the language you want to learn, and you will find a mountain of forum posts from experts with good recommendations. For example, Google reports that the best beginners programming book for C++ is probably Accelerated C++. Be sure to check several sources and pick whichever book gets the most recommendations from people who seem to know what they are talking about – some intuition is required here!
Amazon is a great place to pick up hard-to-find programming books, but don’t pay too much attention to the reader reviews as many of them will be beginners themselves who aren’t really qualified to say whether a particular book is good or bad.