Jun

17

Programming: Step 1

June 17, 2013 | 1 Comment

Intimidated by your latest programming task? Code taking longer than you think it should? Here’s a tip –

template for flow chartsWhen I was in college, flow charts were what the “cool kids in computer science” did – a phrase Darling Daughter Number One has informed me is oxymoronic. Seriously, when I took Fortran and Basic in school part of what we bought for class were these plastic green templates that had different shapes for decision ( ◊) , disk output, tape (!) output, printed output and so on.

I very seldom use flow charts any more unless it is for a VERY complicated project and I’m not suggesting you necessarily should.

Because I have been doing it for a long time, much of the programming I do is like writing this blog – dashed off at random.

Lately, it has occurred to me that for all but the simplest tasks, the best way to do it is probably mid-way between the two.  Write down what you intend to do. If you are like me you will probably write it in code-lish (that is like Spanglish but with a programming language instead of Spanish).

For example, I’m writing a computer game for kids and in part of it I want the answers to be numbers like refrigerator magnets and they can drag them around on the “refrigerator”. The right answer will have to be broken down into digits.

i = rightanswer.length ;

do while i < 0 ;

Make the array

Do 1 to right answer length

Array[x] = substring(rightanswer, first digit – hundreds place)

i–

end ;

Then I thought, you know, in this case, the right answer isn’t going to be more than three digits because these are problems for young kids. Instead of all of this, I could just do:

i = rightanswer.length ;

x = substring 1st digit

if  i > 1 {y = substring 2nd digit }

if i > 2 {z = substring 3rd digit }

While normally  IF statements are not considered as elegant as arrays and violate the DRY principle (Don’t Repeat Yourself), this is only 3 lines.

My point is, that none of this yet involved any typing or testing. I did it with a pencil and paper (yes, they still make those).

Pencil in its natural state

Pencil in its natural state

The first step in programming is to think about what you want to accomplish and how you are going to do it. After you have done that, you should sit back, evaluate it and ask yourself if perhaps there is a simpler or better way. In short, step one is to THINK. Maybe IBM was on to something 80-plus years ago.

Think sign from IBM

 


Comments

Name (required)

Email (required)

Website

Speak your mind

1 Comment so far

  1. You have your survey data, now what? : AnnMaria’s Blog on June 26, 2013 3:21 pm

    […] As I said before, the first step in programming is to THINK. This applies to statistical programming as well, which is what you are going to do with your survey data. […]

Blogroll

WP Themes