Programming 101

Posted on: 28 Feb 2009 12:38:13 PST
Categories: Archives Scribbles
Tags: programming tips

Actually, the titleā€™s somewhat misleading, and somewhat fancy. Never mind that.

Continuingā€¦

What I really want to discuss here are tips for beginners on the art of programming. (Yes, programming is an art, as well as manual labor. :))

Most of us, when told to program or make an application, proceed directly to writing code. Well, this sounds somewhat logical; after all, when we say we ā€œprogramā€, we mean we ā€œwrite code and compile it into a useful program.ā€ Well, do you know what happens when we proceed directly to coding? Here are some (based on my experiences also):

1. Buggy code. 2. Inefficient code. (The algorithm is slow) 3. Inelegant code. (The code is very long, maybe 500 lines being the shortest) 4. Mental block. (You stare at the screen doing nothing, trying to think of what will type next) 5. Wasted energy. (It takes a very long time to debug code, to rewrite the code if necessary)

And others a professional programmer would know about.

Anyway, why care? Just like we care about making our computers start up faster and our programs load faster, so do we in developing code. FYI, elegant programs donā€™t get born by a person sitting in front of the computer all day writing code, but from persons who look at things in a different perspective.

As an analogy, consider Newton. It was said that he formulated the Laws of Motion by watching an apple fall, and it took him two years to formulate his full-fledged theory. Note that he didnā€™t just sat on a bench with voluminous Physics books manipulating equations to make his theories laws. He used a falling apple as a basis of his laws (which holds true up to now). Thatā€™s looking things at another perspective.

The same applies to Computer Science. Those thinking that CS people are geeks who only write code for a living are totally wrong. (This description applies more aptly to script kiddies.)

That aside, here are my tips to those people, especially beginners, who would like to learn how to make their own programs:

0. RESIST THE TEMPTATION TO WRITE CODE. 1. Identify the problem(s) first. 2. Use the divide-and-conquer strategy: divide the problem into smaller, manageable sub problems. 3. For each sub problem, think: If I were to solve this, how, as a human, would I do it? 4. Based on your answer(s) in #3, get a piece of paper and a pen, and try doing it. 5. If it works, proceed to step 6. Otherwise, revise the solution (or go back to step 1) 6. Try to piece together the solutions to the sub problems into one coherent solution, then analyze if the solution is good enough. If you find something missing (or something wrong), go back to step 1 or 2. 7. Write your solution in pseudocode. 8. Test again by hand if the solution is working and if good enough. 9. Try implementing the solutions to the sub problems in code. (Here, you get to write the actual code, but the code to the sub problems only.) Debug errors while as you go along. 10. Write the whole application code and debug.

Writing in pseudocode means that you get to write the code in a semi-programming language. That means it has the components of a programming language, but still independent enough to be implemented in different programming languages (meaning that your pseudocode should be written in such a way that it can be translated in different programming languages such as C, Ada, Lisp , BASIC, etc.).

Remember, the best way in doing this is that you should have interest in what you are doing. After all, if you have no interest in it, youā€™ll just end up making ā€œletters in the sand.ā€

Another thing is that you should give yourself time and space to do it. Yes, there are people who can write efficient and very elegant code when put under very limited time frames and excessive pressure, but then not all people are like them.

Consider also your own abilities. If what you are doing requires more knowledge of the subject matter, donā€™t be afraid to research about it.

Also, a very important tip: do not fear rewriting your code (or the algorithm). There are many instances wherein rewriting helps produce quality code.

Remember this: Programming is an art, not just a hobby or a way of living. Therefore, if you want your art to be high in quality, you should have the patience, knowledge, and interest on it.


Comments

None.

Want to comment? Send an email.