Structured Programming

John Chambers jc at minya.UUCP
Fri Mar 3 08:57:32 AEST 1989


> >And how many times have we been burned because we forgot whether a
> >loop construct will always execute once or not; and how many compiler
> >bugs were based on misunderstandings like that? Mistakes of that sort
> >are few when you do the loop counting in the HLL and use goto's. 
> 
> Anyone who doesn't familiarize himself with his tools can get hurt
> using them.  Software engineers are almost universally in agreement
> that proper control constructs reduce error, and chief among these
> constructs is while...do...done in various guises.

True, but it's still easy enough to get burned.  And at the risk of 
being guilty of the sin of preaching to the choir, I'd like to remark 
that, while I have been burned by this in many languages, so far I've 
never had such problems in C.  C is one of the few languages that does 
loops right, i.e., iterates exactly when the terminating test is true.  

Most languages' standards/specs/whatever allow the compiler writer to
handle the null case in a way that makes the non-null case the fastest;
C compiler writers aren't allowed such trickiness.  It's a real help to
know that the code will loop just as many times as I tell it, no more, 
and no less.  It's also a big help to know that the "control variable(s)"
are guaranteed to keep their final value, and that the compiler can't
play efficiency games that work differently on different systems.  I
like the idea of a program that does exactly what I say, even (especially) 
when there's a "better" way.

Now if we could only do something about the occasional (about once a
month in my case) wasted time due to typing "=" when "==" was intended.
Oh, well, nobody ever claimed that C was perfect {;-}

I could also make some nasty remarks about the leeway in the order of
evaluation in C, but I'll leave that as an exercise for the reader...

-- 
John Chambers <{adelie,ima,mit-eddie}!minya!{jc,root}> (617/484-6393)

[Any errors in the above are due to failures in the logic of the keyboard,
not in the fingers that did the typing.]



More information about the Comp.unix.wizards mailing list