Programming and Education (aka. How to learn to program)

Writing software (aka. programming) is something which obviously has to be learned over a period of time. Some programmers are self taught, while others have been trained in schools. The question comes up, what is the best way to learn how to program ?

My own experience provides me with some advantages. I was introduced to programming back in the 1970’s in high school because I had an advanced math class. We were given access to a terminal connected to a nearby college mainframe and started learning Basic. I had one course in Fortran in college (didn’t finish college having to leave because of personal reasons), but then my programming education ended.

Years later I picked up programming as a hobby, starting with a TI-99 computer and then a Commodore 64. My real programming education was a “self taught” experience, rather than a formal education in programming. I started out teaching locals how to use their home computer to program, but this lead to some custom programming opportunities for local businesses. I had a strong math background which is one reason programming came natural to me. Today I write tools for other programmers to use. My customers often comment about how clean and easy to read my code is. There are some good reasons for this.

There are a number of lessons I have learned, which may be helpful to others, especially those wanting to teach themselves programming and those who are teachers who want to teach programming.

Lesson 1:

Math skills are important !

Teachers often may struggle with the details of how to teach programming, but one thing easily overlooked is math skills. Rather than being overly concerned about things like “what programming language to teach” or whether to teach object oriented coding, concentrate on teaching math along with programming so students can see the one to one relationship between code and math. You need to be able to visualize a problem, seeing how math plays a role in it. I started really learning how to program using BASIC on a TI-99 computer, which by todays standards would be consider the “stone age” of programming. But my math skills turned a simple language into a powerful tool.

Lesson 2:

Learn the basics about how a computer works !

I think it is very, very important to learn some simple basics about how a computer works. Things like what a CPU is and how it works with memory. What are Bytes, Bits, Nibbles.  What is machine language. The more you appreciate how a computer really works, the more you will appreciate how your computer code depends upon this knowledge. It is critical to being a good programmer.

Lesson 3:

Learn how to write some very, very basic machine code (not assembler)

When I started learning how to program using BASIC on the Commodore 64, I quickly realized that I needed to learn how to write some machine code. In those days it was critical to writing anything with some degree of speed of execution. I feel that this actually benefited me a great deal, because it made me appreciate more what a CPU really does and how my code (machine or even high level) was effected by how the CPU does things. I wanted to write a simple family friendly video game for the Commodore 64, so I wrote my own compiler first, which compiled a very BASIC like syntax (code) to pure machine language. I sold the game to a computer magazine and made about $1500 from the venture. I learned 6502 machine language which is very easy to learn and it was a great experience.

This knowledge has been critical to even my current programming, even though I use a high level language today (PowerBasic). It is one of the reasons I prefer a real compiler rather than one which generates managed code (dot.net) or a scripting language. I want the full power of the CPU at my control!

More than this, this knowledge actually effects how I decide to code things. You see, if you don’t understand what happens at the CPU and memory level, you won’t appreciate how your codes execution speed is effected when you write your code. For example, at times I will see a programmer trying to do something a little low level with graphics where he/she tries to accomplish this using GET/SET PIXEL commands of their programming language. If you understand how a computer stores that pixel data (ie. 32 bits in RGBA format) and the loops a simple GET/SET PIXEL command must go through to just deal with that one pixel, you will quikcly learn that it is not the best approach to graphics. I work a lot with DIB Sections in Windows where I am dealing directly with the Bitmap (graphic) image via memory addresses and the speed when is amazing.

The point is, that the knowledge of how a computer works and how even simple high level code when converted to machine language has to do a lot more than you might think, greatly effects how you will write the high level code.

Lesson 4:

Don’t start with OOP (Object Oriented Programming)

I am not against OOP ! It is very powerful when used correctly. Sadly, OOP is not the panacea first thought, which will solve all a programmers problems. It even has its downside. To be a good programmer, one really needs to get used to writing code. A procedural based language often accomplishes more in this learning process. This is why BASIC has been so popular as a learning language. It is simple and procedural by nature (Subroutines and functions). Don’t be fooled by an OOP language which is called Basic. What you need is a procedural language which forces the student to learn how to write code. As one progresses in programming, they will later make choices about what language they like most and what language makes them more productive. The key when learning is to get used to “thinking in code”.

Languages like Microsofts Small Basic, while they have their place, have a downside. They give the student the false impression they are programming, when actually the language is doing all the work for them. The language may allow you to draw things, rather than write code. It may allow you to do very, very high level things (ie. video, animation) with almost no code at all and it gives the student the impression that have written real code, when actually they are simply using a high level component of the language which does all the work and they have written almost nothing of value themselves.

To illustrate, its kind of like learning how to work with wood. In school students often start with hand tools first, before using power tools. Why ? Because it teaches them basic concepts which will be critical when the move to power tools later. Actually you will appreciate (and properly fear) power tools more this way. For example, a student slips and cuts himself with a hand saw. Likely it won’t be too damaging and they will live through it, but they learn to be more careful when using tools. Now imagine if they started out with a table saw. One error and it could be disastrous. Also there are times that even when we have power tools, that a hand tool is actually better to use in some situations.

Programming is not much different. By learning just basic coding, rather than all the high level drag and drop stuff, one learns the key concepts to writing code. When one moves on to more high level tools, they will likely make better choices in the tools they select. Also one will be able to use low level tools when they actually serve better.

Lesson 5:

Learn to build libraries !

One important lesson in programming which needs to be learned is the importance of building your own libraries (reusable code). Craftsmen of all sorts soon learn the lesson that they need to learn to build their own tools and devices to improve their work and to make it go faster and more reliably. As a wood worker, I quickly learned how to make my own jigs to solve problems or to automate a task.

Programming requires learning to build ones own tools to help automate the task. Also the old saying “don’t reinvent the wheel” holds true in programming. Learn to write your own library code of reusable stuff.

Lesson 6:

Make something useful !

Imagine being a wood working class and all you ever do is sand or cut pieces of scrap wood. You would get bored very quickly and you would not see the value of what you are learning. What a student needs is to build something useful. Imagine all you learn, when you are asked to build a bird house in wood working class. Now that is useful. So to with programming. Students need to solve real work tasks for the experience to truly benefit them. The more complex the task, the more the student has to think and use their brain power. Don’t under estimate this. I have seen experienced programmers ask questions on how to so something, where as if they just took a little time to sit down and think deeply about it, maybe they could have solved the problem themselves.  Maybe this is a reflection of how they were taught in the first place.

Programming is an art !

Programming is a skill !

It needs to be taught like other arts or skills.