From -1794911941895506313
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,6bd75668e589c3cb
X-Google-Attributes: gidf78e5,public
From: bradds@concentric.net (Bradd W. Szonye)
Subject: Re: PROPOSAL: Parameterized return/break/continue for nested loops
Date: 1996/10/14
Message-ID: <01bbb84c$37b2a360$1e74adce@azguard>
X-Deja-AN: 189386751
references: <01bbb541$57db1d60$31d8cac6@chico> <53f2vu$fd0@panix.com> <m3hgo3ns0p.fsf@gabi-soft.fr> <325D288D.3713@ebc.ericsson.se> <53o50l$e7e@news1.infinet.com>
x-original-date: 12 Oct 96 14:47:31 GMT
organization: Doubleplus Corporation
x-auth: PGPMoose V1.1 PGP comp.std.c++
newsgroups: comp.std.c++
originator: austern@isolde.mti.sgi.com


Mike Harrold <ao@infinet.com> wrote in article
<53o50l$e7e@news1.infinet.com>...
> Bjorn Fahller (ebcbear@ebc.ericsson.se) wrote:
> : While a named break is indeed a goto, a goto is by no means a named
> : break. As a rule of thumb, I think the use of goto is a very good
> : sign of something being very wrong in the source code. I cannot see
> : anything such about a named break.
> 
> No, no, no and no again. Someone has obviously been reading too many
books
> about "structured programming" written in the 1980s. Using a goto does 
> *not* signify something is 'very wrong in the source code'!

The way I see it, there are two ways of looking at things like multiple
returns, ifs, gotos, breaks, loops, and continues. You can say that if and
goto are the fundamental branch and jump instructions and that loops,
breaks, and continues are merely semantic sugar to make them easier to
write. Another way is that ifs, loops, breaks, and continues are the
fundamental branch and iteration instructions, and that gotos and multiple
returns are merely implementations of that technique. Some people would
like to remove that 'implementation' technique from the higher-level
languages and hide them in the generated code. Teaching languages like
Pascal take the latter approach, systems languages like C the former, and
most languages are somewhere in the middle.

> : If possible (and I know it isn't,) I'd very much like to see goto
> : removed from C++ (and any other language too, for that matter,)
> : once and for all, and have it replaced by something more structured
> : that fills the one use of goto I can see that is not a sign of poor
> : coding.
> 
> Why? They serve a very important purpose; or would you rather have the
> language cluttered with even more useless keywords? Think about it,
> a 'break' within a switch is essentially a goto. Break may look more
> elegant but it is merely a short cut for a goto. Sure, you can add
> test conditions, etc, etc, etc, to avoid using a goto, but if you are
> writing optimised code, sometimes the use of a goto is just unavoidable.

It's not even a matter of optimization; it's a matter of style.

I sometimes like to write poetry. In fact, my favorite sort of poem to
write is an Elizabethan sonnet. Done properly, such a sonnet needs four
quatrains and a couple, in perfect iambic pentameter, with rhyme scheme
ababcdcdefefgg, no rhymes repeated, all rhymes perfect, each quatrain a
different extended metaphor building toward the couplet which summarizes or
'punch-lines' the sonnet.

That's an extremely rigorous form, and extremely challanging and *fun* to
write! I take the same approach to programming. Some programs are 'free
verse' using the entire crazy and sloppy range of the English (or other)
language; some programs are very precise and carefully structured both
syntactically and semantically.

X3J16 is in the same position as Daniel Webster: he wanted to standardize
(standardise?) American English spelling and meaning of words at a time
when such things were chaotic, before they got more chaotic. It wasn't his
job to remove 'bad' words from the language; merely to standardize prior
art. In some cases, he may have intentionally or accidentally introduced
new usage into the language. But it was not his job to ensure that the only
poems you could write were perfect sonnets. In the same way, the committee
cannot try to make sure that we can write only perfect programs.

You can't goto the middle of certain verses any more, but you can still use
a rough stretch of rhyme and meter to get the overall flow of the program
to work. Please excuse the horrible mixed metaphor. I personally take the
sonnet approach to programming; I restrict the parts of the language I use,
falling back to cheap hacks only when time is tight, the program doesn't
matter, or I can't figure out the right way to do it yet. It's still an
internal embarassment (to me if no-one else) when I can't write a 'perfect
sonnet' in code however.

> The gentleman (I forget his name *blush*) who first called goto's evil,
> also said they served a purpose. As long as they are used for that and
> only that purpose, they are a perfectly acceptable method. The orginal
> poster specified the classic example of where a goto is needed.

There's some debate about how exactly Edsgar Dijkstra felt about gotos at
the time of the "Considered Harmful" paper. Some think he added the 'goto
is occasionally useful, when used properly' part either because of
practical limitations of then-popular languages or as a simple hedge to
deter 'flames'--riding both sides of the fence.
-- 
Bradd W. Szonye
bradds@concentric.net
http://www.concentric.net/~bradds
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



