From: Phil Carmody on
Juha Nieminen <nospam(a)thanks.invalid> writes:
> In comp.lang.c++ Ali Karaali <alicpp(a)gmail.com> wrote:
>> I use goto to break nested for loops and I can't see a
>> reason to ban goto.
>
> No. The correct keyword for breaking out of nested loops (in C++) is
> 'return'. If you are using 'goto' for that purpose, you are doing it
> wrong.

This is a purely religious point of view.

> "It's not the same thing". Precisely. If you design your code such that
> you can always use 'return' to break out of nested loops, it will become
> cleaner and easier to understand.

In that case you have to pass all state into and out of the function
that performs the nested loop. That might be significantly less
efficient than just having all the state locally, such that the target
of a goto still has access to it all. Again, your point of view looks
religious and blinkered.

> I have been programming in C++ both professionally and as a hobby for
> over 10 years

One should never flaunt ones lack of experience in order to back up
ones argument.

Phil
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
From: Phil Carmody on
James Kanze <james.kanze(a)gmail.com> writes:
> On Apr 24, 1:20 pm, "Leigh Johnston" <le...(a)i42.co.uk> wrote:
>> "spinoza1111" <spinoza1...(a)yahoo.com> wrote in message
>
>> news:051fa27d-5cf8-4f7e-94c8-e9e5b26566b7(a)g34g2000pro.googlegroups.com...
>
>> > On Apr 24, 6:06 pm, Ali Karaali <ali...(a)gmail.com> wrote:
>> >> I use goto to break nested for loops and I can't see a
>> >> reason to ban goto.
>
>> > Why not use break instead? Does the same thing, spares you
>> > from having to define a label.
>
>> Because break only breaks out of the innermost loop, using
>> goto to break out of nested loops is one of the few sensible
>> uses of goto.
>
> But when do you have to break out of a nested loop?

For the same reason you want to break out of a single loop.
Do you have issues with people breaking out of single loops?

> (And of
> course, the only valid use of break in C++ is to end a case in a
> switch. Otherwise, it's just a goto in disguise.)

What do you mean by 'otherwise' - even that's just a goto in disguise?

Phil
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
From: wolfgang kern on

"io_x" wrote:
> [Xpost to: alt.comp.programming, alt.lang.asm,
> comp.lang.c, comp.lang.c++, comp.programming]

> the people that speak not good about "goto"
> are uttled wrong; their code bug full etc

> more distant is your code from goto
> more your code is bug full and incompresible

> the "goto" is the key word for programming;
> all the remain, other than goto or jmp or jc or jz,
> and the easy cpu layout
> is the wrong way for programming

Except that GOTO is a HLL keyword and I'm Asmist and
more machine-code oriented than concerned about needs
within abstract structured HLL-compilers, I see nothing
wrong with GOTO as long it does what a programmer want.

I once checked PowerBasic's GOTO and found it always
compiled a long (16:16) jump, even rare required.
But its syntax checker cried aloud if you tried to
jump out of a [FOR/IF/...]-struct with GOTO.

I don't know C/C+-, but what I see by disassembling their
resulting output seem to end up in heavy bloated code,
perhaps from using BREAK and GOTO within nested blocks,
which the compiler may grant with copying all required
code-trails (stack recover/cleanup) to every added path.
So in this aspect GOTO may be really not the best choice.

see me happy for I don't need to care this in my world :)
__
wolfgang (ALA)










From: Patricia Shanahan on
Alexei A. Frounze wrote:
....
> Surprisingly, my code is pretty clean with gotos, which, btw, I use
> just for almost exclusively 2 things:
> - breaking out of nested loops (not always, if I can do that w/o
> writing more than two lines of code, I don't use goto)
> - jumping to the common cleanup code at the end of the function when I
> detect some error
....

When I was first considering using Java for a project, I was a little
worried about the lack of goto.

I knew I had written a couple of gotos in C and maintained code
containing goto that would have had to be much more convoluted without
it. When I analyzed those uses of goto, I realized they were all in
those two categories, mainly the common cleanup code case.

That meant I would not need goto in a language with try-finally and
named loop break.

Patricia
From: Daniel T. on
James Dow Allen <jdallen2000(a)yahoo.com> wrote:
> On Apr 24, 9:10�pm, "Daniel T." <danie...(a)earthlink.net> wrote:
> > ...
> > everyone who is tempted to argue about this issue to start from
> > Dijkstra's paper rather than simply asserting that "goto is good"
> > without understanding the issues involved.
> >
> > http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_
> > Harmful.html
>
> I did click the link, though I'm sure I'd read the paper a few times
> earlier. It has one key sentence which I think is now widely
> understood: Edsger W. Dijkstra wrote:
> > The unbridled use of the go to statement has an immediate
> > consequence that it becomes terribly hard to find a meaningful set
> > of coordinates in which to describe the process progress.
>
> (Hmmm. Dijkstra *does* write "UNBRIDLED use of goto". Funny how that
> disappears from the pedants' sound-bite summaries.)

Agreed, and many also fail to notice that it is rather hard to use goto
in an "unbridled" fashion in C and C++.

> One of my own goto's appears horrendous, but is actually just a way to
> go to the appropriate progress point when the "meaningful coordinates"
> have been established:
> Pseudo-code comparison
> http://fabpedigree.com/james/gotoalt.htm
> Actual C code
> http://fabpedigree.com/james/dbldum.htm
>
> (Warning: if anyone *does* say anything good about my code, it will be
> a first, and I'll probably faint from the exhiliration!)

It looks as though you have implemented a depth first search. (If it
isn't a depth first search, then I'd say your code isn't readable.) That
said, I fully agree that your code is better than the psudo-code you
present in comparison (you call it "Tim's code".) However, there are
better ways of implementing depth first searches than either of the two
you present.