How Do I Learn to Code?

Computer programming is fascinating and useful, but very confusing for the beginner. There are so many different tools, systems, and schools of thought on the subject that it is hard to know where to begin. Thus the need for articles like this one. Here I will answer some frequently asked questions about code and offer my own opinion on the best way to start. Much of my advice is simply the complement of the mistakes I made in the learning process. Hopefully I can spare you some of the headaches I put myself through!

How much math do I need to know?

When you're starting, just Arithmetic. A little algebra( especially a knowledge of functions ) will help, but is not strictly necessary. As your knowledge becomes more advanced, you'll want to learn Trigonometry and Linear Algebra. Calculus and other advanced maths may or may not be necessary, depending on what programs you're trying to write. Actually, an excellent way to learn Math is to write programs that model them. This is an exciting stage of learning to program, when you can program to learn.

Math and Code have a dichotomous relationship, forming something like the Yin and Yang of the problem-solving cosmos. They complement each other. Math studies the relationships between variables as encoded by equations, Code commands variables to undergo change through processes. Since Code runs on a machine, you can see the result, and interact with your programs. The proof of a program is that it works, which anyone can see, but the proof of a mathematical theorem is just as abstract as the theorem it proved.

What Language should I start with?

Start with Scheme! Python is a close second. Of course, if you know anyone who codes, take advantage of their experience and try their language. In general, make sure whatever language you start with has an interactive mode( e.g. has an interpreter ). In general, there are two ways to code: batch mode and interactive mode. In batch mode, all of your code for a project, held in text files, is fed into the compiler which produces the program for you. In interactive mode, you can type any piece of code into an interpreter and see immediately what it does. Programming in Interactive mode will help you learn more quickly, is easier to debug, and just way more fun.

I recommend that you focus on learning the basics and writing small programs for a while. The important thing is that you develop an intuitive model of how the machine works, what your programs mean, how algorithms work, and what the different data structures are like. Once you have this inner-eye you can search out any language you want.

What else should I learn?

Learn to use the command-line. Also, get a machine with a GNU/Linux Operating System. If you're not ready for that step, install MinGW on Windows.

What's a 'Programming Paradigm'?

They are metaphors or models of computation, designed to simplify and organize programs by structuring them in larger logical pieces than is avilable on the raw hardware. The machine itself only 'speaks' machine code, a language where each instruction is represented by a number, and can perform such operations as: reading a word from memory into a register, writing a word in a register to memory, and adding the contents of two registers together. Trying to write any program of signifcance in Machine code is not easy. Back in the day, programmers wrote their programs in machine code. But the programs quickly exhausted the limits of human comprehension. It became clear that a method(paradigm) was needed for organizing these fantastically complex programs.

There are two ways to apply a paradigm. One is conventionally. In this way, programmers just mutually agree to design their program a certain way, according to certain principles. The other way is linguistically. In this way, programmers design a programming language with higher-level abstractions and an easier-to-read syntax. The new languages form a bridge between the programmer and machine code. Ultimately all computation still boils down to machine code, but programmers can write in higher-level languages and let interpreters/compilers translate that code into a form that the machine will understand.

The clearly distinct paradigms are Functional, Procedural, Logical, and Object-Oriented. Most programming languages tend to favor one paradigm over another, though they typically support features from a broad spread of paradigms. The Procedural paradigm crops up in most languages - and actually Logical is pretty hard to combine with other paradigms, but I digress. Most coders have their own favorite language or paradigm, and flame wars over which one is best are not unheard-of. Ultimately, a paradigm is just a tool. If it solves a problem elegantly, great. If not, try a different paradigm. It's most important to understand the problem independently of any particular language or paradigm. If you really understand the problem, writing a solution is as simple as finding a language that you can express your ideas in.

Student Beware!

You don't need to go to school to learn how to code. If you are teaching yourself, however, be prepared. Expect to spend considerable time and energy studying the basics. Always make sure to practice whatever new concept you're learning, and write small programs at first. You will learn more quickly and understand better by making ten small programs then by struggling to finish one gigantic one. More importantly, you'll actually enjoy coding when you have completed projects to look back on. Also, learn how to use the command-line.

Learning this stuff is challenging and confusing, but it is also tremendously rewarding. Don't wait, jump in and figure things out as you go - that is the only way anyone has ever learned anything in the real world.