This article is reproduced by permission from the March, 1989 MIDWEST NEWS, the monthly journal of the Midwest Commodore Users Group. Permission is granted to reproduce this article for non-profit purposes only.
Programming Style
I recently heard a conversation in which a man said,"I haven't been able to do much programming lately...my kids are on my computer so much." Along the same line, a friend was waiting for a ride and remarked that he couldn't wait to get home so he could sit down in front of his 64 and "start programming". That sort of bothered me. That struck a wrong chord, but I couldn't put my finger on it. It's come to me now and I think it's noteworthy enough to write about.
All of us who program even a little develop a programming style. That programming style reveals (perhaps unwittingly) much about our programming philosophy. Programming Philosophy is a big term but it just means a collection of ideas and conventions about programming that we have adopted. So today I want to talk about one aspect of programming philosophy.
First: A definition of a program: a set of instructions to accomplish a specific task. A little short, but it's a workable definition. Programming then, is the act or process of creating a set of instructions to accomplish a specific task. Sound good so far? OK, then what has developing a set of instructions got to do with sitting down in front of a computer? Typing then in? Wouldn't that be defined as "Data Entry"? In reality, the only part of programming that requires being seated in front of a keyboard (other than data entry) is debugging.
Programming is an act of the mind. I like the quote in the front of Stan Krute's book "Advanced Commodore 128 Graphics and Sound Programming":
Programming is to the mind
What exercise is to the body.
I can program (and do!) while I'm on lunch at work, while at the laundromat, while waiting at the doctor's office, or anywhere. If you see me walking around Strack's with a dazed look on my face, I'm not ignoring your hello, I'm probably deep in nested loops!
Programming is thinking. That leads me to another aspect of programming. Sitting down in front of a keyboard and starting with line 10 generally leads to sloppy programming. How do I justify that statement? Typing in as you think lends to putting down the first structure that looks like it will work, trying it, and modifying it as the need arises. Doesn't sound all that bad, huh? Note: It is the opposite of planned programming. I don't like flowcharting and I don't like what some call structured programming (a term that has many meanings). I believe that if I was a carpenter and I set down to build a building, I should not set down in front of a table saw and start cutting boards. If I were a plumber I would not pipe a house without first consulting the blueprints. If I were a tailor I would not make a suit of clothes without first taking measurements. Get the point? Everything that is made should have a plan. Sitting down and typing is the opposite of planned programming! I start with a task. I want my computer to do this. Then I break it down into sections; disk access,printer routine,input from user,etc. Then I think each of them through and write down in plain english what I want each step to do. Notice I did not say each "line"--masking an input might take several lines, but it is one _step_ in the program.then if there are difficult sections, I write them out completely. Now, having planned my program through thoughtfully, I am ready to sit down and start writing the actual code. If it is available, I use the computer, if not pencil and paper!
The purpose of this article is not to convert you to my style of writing programs, or to attack any person. It is simply to get you to think about programming and to develop your own Personal Style.
Allow me to quote one of my College professors, Dr. Wendal Evans: