Hints for Newbie Programmers

Greg Chao-Kuei Hung
3 min readOct 22, 2020

Programming is fun. If you don’t feel the fun or the urge to play at all, then programming is probably not for you, and you should seriously consider other careers as early as possible. If you are excited about the possibility of instructing the computer to do something tedious for you, but are struggling to get started, then this article is for you.

Most lanuages can be used as your first language to learn programming. I highly recommend python, but javascript or C or GO will do as well. Use the “repl” keyword along with your language of choice to find an online lab.

Just start writing code. Don’t be afraid. Computers — at least the ones you are using — don’t bite. The worst that could happen is that the harddisk is wipe out. And I doubt you are capable of doing it. If you are trying it in an online lab, there is no reason at all for you to get concerned.

What you are going to see most often giving you grief is error messages. But don’t fret. Error messages are friends, not enemies. Pay attention to error messages and google them (minus things specific to your program such as line numbers and variable names).

A good exercise for a newbie is something requiring two nested “for” loops. For example, 9x9 (or FxF) multiplication table, insertion sort, selection sort. or finding a target substring inside a long string (without using built-in functions of course). So here I will use insertion sort as an example to illustrate how to begin with short and simple pieces of code and eventually grow it into a complete program.

Hard-code your data into an array so that the first 3 elements have already been sorted. Write a for loop to insert the 4-th element.

Write another for loop to insert the 5-th element. Repeat for the 6-th element if necessary.

Try to combine the two or three for loops into one. Replace the differing number (4/5/6) with the for loop index variable of the outer for loop.

Sometimes you may see two or even three sets of numbers changing through iterations simultaneously. You don’t need an extra for loop (and index variable) here. What you need is to computer those changing numbers from the single index variable.

Then you will have a complete program. It may just work magically or it may fail on the boundary cases (when sorting the 1st number or when the loop exit out of your expectation).

If it fails, then try to imagine what “small pieces of code” the outer for loop has created for you — it must have created the few for loops for you to insert the first three elements. Imagine yourself to be the computer and manually execute the first few loops to see where your logic failed.

After you finish, you may then google to see how other people write the code, and realize that in this case a while loop may be better than a for loop.

Motivated people learn a foreign language fast. Same with programming. Find interesting problems to challenge yourself. Code often. Then your coding skill will improve.

--

--