Learning programming isn’t as hard as some college graduates and experts make out. In fact, it is easy to become a reasonably proficient hobby programmer, within a short space of time, given the right mindset and grounding.
That mindset includes being able to break down and solve problems, something that can be taught, as well as a disposition towards experimenting. Trial end error plays a huge part in the learning process, as does a good understanding of the basics.
All programming languages share some elementary concepts. Once these are understood, learning the actual language becomes much easier, and as they are also transferable in many cases, understanding them will help learn almost any programming language.
Remembering that a computer program is just a bunch of instructions that tells a computer what to do, the four basic programming concepts are:
- variables – places to store information
- decisions – ways to interpret information
- loops – doing the same thing over and over
- subroutines – named chunks of instructions
The first of the building blocks, a variable, is just a named box into which information can be put. It can also be taken out, modified, and put back in again (hence the name ‘variable’: the contents can vary.)
Variables can also be tested against conditions, which allow the programmer to build a bit of decision making power (or logic) into a program. The programmer can tell the program to execute a specific instruction if a variable meets certain criteria. Humans do this all the time: “If it is sunny, then I’ll go to the beach, otherwise I’ll go to the mall.”
On occasion, this is a decision that will have to be taken over and over again. Staying in the mall until the weather improves enough to warrant a trip to the beach, for example. Or, lying on the beach until the surf’s up, checking periodically.
These are examples of loops, repetitive behaviour that can be built into the program. A human might build up a set of instructions:
- Lie on the beach
- If you get warm, check the surf
- If the surf’s up, go surfing
- Go back to lying on the beach
Now, each of the instructions entails a whole booklet of other things that the surfer has to do; and these are the equivalent of a program’s subroutines. For example, to “check the surf”, there will be more instructions that let the surfer look at the waves, evaluate them, and decide whether the surf is up or not.
In programming, we can give these subroutines meaningful names, and use them in code as a kind of shorthand, assuming that the steps that the computer needs to go through to actually achieve something are written (defined, in programmer-speak) somewhere.
Programming languages all have a certain syntax and structure that allow the programmer to build up these sets of instructions, and they’re all different. But, these four concepts are common to almost every language, and are vital to being able to create even simple programs.
It is important to appreciate that these are merely building blocks with which it is possible to construct all manner of more advanced features. Some of these include objects, modules, libraries and various other ways to encapsulate behaviour such that it can be used to build complex systems.
However, much can be achieved with only these four concepts, in almost any language. Many aspiring programmers probably don’t even realise that they have the means to start programming right away, without investing in software or following a college course.
All that is really required is a will to get started, and some help and guidance from someone who has trodden the same path. A book or two will also help, but they’re not required for you to learn programming, now!