Learning to program

MatrixWhat is it like to learn the skill of computer programming? This was the question in a recent online Python programming course. Students were asked to respond to an essay question on the challenges of learning to program, so here are my thoughts.

Some people think computer programming is difficult to learn because they are “not good at logic” or “not a computer person”. Taking an attitude that programming is hard will prevent learning.

Programming is a cognitive skill, like doing mathematics problems, writing English or drawing.  It is possible to learn these skills with the right attitude, perseverance and time to learn and explore.

Computer programming used to be the speciality of “computer scientists” working behind the closed doors of the “computer room”. Programming was seen to be a specialized skill. Programming is now a skill that is important to all sorts of people and professions – teachers, artists,  musicians and students. Programming languages such as Python, VBA (Visual Basic for Applications) and Processing allow us to expand our use of computers and to augment our thinking. This is why learning to program is so useful.

At the heart of programming is creating an algorithm or procedure to solve a problem. The first concept to learn is taking a problem and making a program to do the job.  Mathematics is a good example – here is a problem:  read a series of numbers entered by the user then print the total, smallest, largest and average values.

When I was a first year university student I bought a Hewlett Packard HP-25 Programmable Calculator. It could be programmed with up to 49 steps and a book of programs was supplied with the calculator – mostly for solving problems of mathematics and statistics. The Computer Science subjects started in second year university.

I learnt programming in high school days using the BASIC language but I didn’t have a computer to try out my programs!  At university we started learning  FORTRAN.  The  first challenge was understanding the language syntax. It is best to learn a little bit at a time, just like learning to speak another language. A good way to learn is have a tutorial style introduction – maybe a good book, which teaches you the language step by step. My preferred way of learning a language is to study a well written book, and this is how I learnt C, Perl and Python.

In conjunction with learning a language, it is handy to have a quick reference guide to the language. I used to use “Quick reference cards” – a few pages of summary information. Now this information should be available in the online documentation, in a PDF file or built in to the editor. Having access to the documentation and good examples is helpful for learning.

Computer programs manipulate data, so an important thing to learn is how computers store data. Numbers – integers and real numbers are stored differently, sequences of characters are “strings”. I learnt that computers work  in binary (base 2) and it is not possible to exactly store real numbers like 1/3 (0.333333333).   A computer will calculate 3 times 1/3 sometimes as 0.9999999. This  is called rounding error.

The next thing to learn is about data structures where these basic units of storage are grouped. The simplest structure is an array – usually one-dimensional, multi-dimensional arrays can be introduced for the mathematically minded, but the next data structure that is taught is the dictionary.  Computer science teaches more complex structures such as trees, and linked lists  but the occasional programmer can usually get by with arrays and dictionaries.

Once you have chosen a language to use, you need to know how to compile or run the script, as well as the best way to edit the source code of the program. This is the environment of the compiler or interpreter. You need to know how to install this environment and check that everything is working.   A good editor makes the work easier with features such as color coding the syntax, indentation, and handling comments.

Programming style is important. This relates to how you should choose variable names and function names, and code layout such as the use of spaces around equal signs, and indentation. A lot of this is handled by the editor. When I learnt FORTRAN programming we used a text book on programming style, and in my first job there were standards for COBOL language. Good programming style makes the code easier to read and maintain.

A big challenge of learning to program is “debugging” – finding the reason why the program doesn’t work. When I learnt to program I was encouraged to “desk check” the code, which means pretending to be the computer, looking at each line of code and manually calculating the variables. I wouldn’t recommend this now – it is better to use print statements to let the computer tell you what it is doing. If you don’t know what the program is doing, include print statements to tell you the value of variables or the location in the script, for example,  print “routine A started” or  print “A is “,a.

The way we were taught programming at university was having to code interesting problems. First we had to understand what the actual problem was, how to store the necessary data, design the logic or program control, then write and test the program.   I remember one assignment which was simulating traffic lights and estimating how many cars would be waiting when the light turned green. This involved using a random number generator to decide if a car had arrived at the lights.

Another aspect of programming is learning about libraries or modules of routines. These are collections  of programs written for a specific purpose and can be used in your program. For example, in Python the “os” library provides a set of routines for  operating system commands, copying, renaming files, etc.

There are many domains of programming – subject areas or disciplines. This will direct how programming is taught and the types of programs. For example, Processing is a great environment for creating interactive graphics. Python can be used to read text, process files, perform maths or statistics problems, manipulate databases, create plots, or build a Graphical User Interface. VBA can enhance the power of Microsoft Office products.

Further Information for Python

This was the essay question:

Write an essay as to why you think it is so difficult for many people to learn programming. If you are a skilled programmer think back to when you were first learning and talk about what worked and what made it challenging. If you have tried to learn to program and had problems – talk about the factors in how you were taught that lead to non-success. If you have never even tried to learn to program, talk about what you think will be the greatest challenge to learning to program. The maximum length of the essay is 1000 words. Part of the reason for a word limit is to make you express your thoughts in an organized and somewhat succinct fashion. It is acceptable to have less than 1000 words. References are optional – use them if it is appropriate for your essay.”

 

Advertisements

Author: charuzu

I live in Sydney and interests include music, piano playing, technology, cooking, English language, public speaking, Toastmasters, Asian culture (especially Japan and Korea), cinema, personal development, productivity and making friends with people from around the world.

One thought on “Learning to program”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s