How to Learn to Program: Writing Code

Mike McMillan
Level Up Coding
Published in
6 min readFeb 19, 2020

--

You can’t write code before you can read code

The four steps in a sequenced instructional approach to teaching programming are: 1) reading and understanding code; 2) writing code; 3) reading and understanding program templates; and 4) applying program templates to unique situations. I discussed the first step in the process in a previous article and in this article, I dive into the second step: writing code from simple, clear instructions.

The Transfer from Reading Code to Writing Code

A mistake that many programming and textbook authors make when teaching beginning programmers is having the learner start writing code too soon. The beginning programmer needs to spend a lot of time reading code and learning to be able to predict the behavior of a sequence of code before they see it executed.

Learning how to read code should be broken down by programming construct, such as if statements and different types of loops. Before a learner can be expected to write an effective while loop, for example, they should have practiced reading while loops and tracing the code many times in many different situations, such as count-controlled loops and sentinel-controlled loops. It is only after having practiced on loops by tracing multiple times will the learner has enough experience understanding the behavior of loops to be able to start writing their own, effective loops.

It is when the learner starts to write code too soon that they experience errors in their code. They will receive syntax errors if they haven’t read enough code in a programming construct to understand how the construct should be formed. Then, if they aren’t experienced with predicting the behavior of a programming construct through code reading, they will have logic errors in their code when trying to write programs using that construct.

Learning to Write Code

At this stage of a learner’s development, learning to write code involves taking clear, simple instructions and translating them into a program.

Here’s one example of clear, simple instructions involving variable swap:

  • Declare x and y as variables and set them to the values…

--

--

Mike McMillan writes about computer programming and running. See more of his writing and courses at https://mmcmillan.gumroad.com.