[OT] [sdiy] IN your mind, what is ....

Magnus Danielson cfmd at bredband.net
Wed Feb 4 20:18:15 CET 2004


From: "Shokwave" <shokwave at nb.aibn.com>
Subject: Re:[OT] [sdiy] IN your mind, what is ....
Date: Tue, 3 Feb 2004 22:20:39 -0400
Message-ID: <00c701c3eac5$7c0a90f0$c9a1b3cf at miramichi.nbcc.nb.ca>

> 
> ----- Original Message ----- 
> From: "Magnus Danielson" <cfmd at bredband.net>
> 
> > So, when I am seeking to
> > find out what I need to know in order to become a good C++ programmer (and
> BTW
> > I know a number of things in C++ which I can give very good reasons for
> NOT to
> > use at all or very restrictive). I tend to work kind of OO-oriented in C
> > instead.
> 
> This reminds me of goto's in C. I make a point of showing my students some
> of my code that contains a line like:
> 
> if(stuff_happened) goto error;
> 
> ...nestled at the center of a deeply nested loop. They always look at each
> other, and gingerly one will raise a hand and say "but other instructors
> told us to never use a goto", and I grin peacefully like Buddha and say
> "Yes, *you* shouldn't...unless you know you should. Try and write that code
> without one, and show me a CLEARER way to do it. If a goto doesn't make the
> code CLEARER, do not use one." I only ever get one or two students who ever
> use a goto after that...but I'd get none unless I *did*, and the one or two
> that ever uses a single one knows damn sure why they did it, because they
> made sure they grokked why *I* used one first.

The GOTO issue is, as you say, widely missunderstood. You must go back to the
early days of programming (we are in pre-C history) and see that as the
programs got larger (and after the introduction of subroutines/functions) they
still saw the wild goto-usage that we have in traditional BASIC etc. With now
late Edsger Dijkstra's article "Go to statements considered harmful" in March
1968 we see a very clear defamation of the goto statement. Donald Knuth spends
a significant part of his "Literate Programing" book (page 17-89 including no
less than 103 references) which is an article called "Structured Programming
with goto statements" from Computing Surveys, Volume 6 of December 1974 on the
topic of goto-statements, and he gives quite good advice on when to use goto-
statements, and in the end you basically came to the same conclusion. I do
recommend reading that article (and indeed the rest of the book too).

Using it in for example error cases or other places where it is more natural
to do goto than transforming the code so you avoid using goto, but get a much
more complex code and thus is more probable to make an error or the reader of
code is more probable to missunderstood, in such cases goto is the WISE thing
to use. Also, gotos should only be used to labels inside a particular function,
or you are BEGGING for mercy at a debugger near you very soon.

Cheers,
Magnus - could use goto more often



More information about the Synth-diy mailing list