From: Nick Keighley on
On 24 Apr, 16:48, "Leigh Johnston" <le...(a)i42.co.uk> wrote:
> "Daniel T." <danie...(a)earthlink.net> wrote in message
>
> news:daniel_t-DBCC13.11141024042010(a)70-3-168-216.pools.spcsdns.net...
>
> > 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.
>
> > I'll give you a reason to ban goto. This is a line of BASIC code:
>
> > 90 x = 5
>
> > Now, I ask you, where is the line that was previously executed? Is it
> > directly above line 90, is it directly below it, or could it be anywhere
> > in the program? Because of the goto statement, simply because an
> > unstructured "goto" is possible in the language, you have to analyze the
> > entire program to know the answer. If we ban the use of "goto", we can
> > confidently know exactly what line of code comes before line 90.
>
> This channel is about C++ not BASIC, you do not have to analyze the entire
> program in C++ as goto can only jump within the same function so comparisons
> with BASIC is silly.

there's longjmp
though even that can only jump upstack

From: spinoza1111 on
On Apr 25, 5:50 pm, Nick Keighley <nick_keighley_nos...(a)hotmail.com>
wrote:
> On 24 Apr, 16:48, "Leigh Johnston" <le...(a)i42.co.uk> wrote:
>
>
>
>
>
> > "Daniel T." <danie...(a)earthlink.net> wrote in message
>
> >news:daniel_t-DBCC13.11141024042010(a)70-3-168-216.pools.spcsdns.net...
>
> > > 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.
>
> > > I'll give you a reason to ban goto. This is a line of BASIC code:
>
> > > 90 x = 5
>
> > > Now, I ask you, where is the line that was previously executed? Is it
> > > directly above line 90, is it directly below it, or could it be anywhere
> > > in the program? Because of the goto statement, simply because an
> > > unstructured "goto" is possible in the language, you have to analyze the
> > > entire program to know the answer. If we ban the use of "goto", we can
> > > confidently know exactly what line of code comes before line 90.
>
> > This channel is about C++ not BASIC, you do not have to analyze the entire
> > program in C++ as goto can only jump within the same function so comparisons
> > with BASIC is silly.
>
> there's longjmp
> though even that can only jump upstack

Hmm, I never have to use longjmp, since I tend to factor more.
Factoring a problem is resisted in Amerikkkan programming because
Amerikkkan managers don't want employees to be "creative", and it
takes a minimal amount of creativity to create a new C function.
Employees who learn how to construct and manage large systems are
innately dangerous, since their knowledge might transfer to labor
union organization or political causes above the level of Tea Baggery.

This is why properly factored code that consists of properly
functionally bound units often ENRAGES managers, and programmers
alienated and dispirited by the corporate rat race.

If it contains small functions whose purpose can be expressed in a
well-constructed sentence it is an image of a decent society in a
society that thrives on exporting death and importing alienation.

It's ideologically safer to use slop programmerese such as "I don't
wanna call dis function in multiple cases becuz dat is bad" in order
to show you know your place in the pecking order.

The ideal program is a single main() routine that does everything: a
model of a Fascist society.

Ein reich! Ein Fuhrer!
From: bartc on

"James Kanze" <james.kanze(a)gmail.com> wrote in message
news:30002fc4-d539-446c-ac84-84dcf5b8c954(a)t36g2000yqt.googlegroups.com...
> On Apr 24, 10:26 pm, Phil Carmody <thefatphil_demun...(a)yahoo.co.uk>
> wrote:
>> Tim Streater <timstrea...(a)waitrose.com> writes:
>> > I haven't used a goto since 1978 (when I stopped writing
>> > FORTRAN).
>
> Me neither.
>
>> I'm with Knuth.
>
> In other words, if goto makes the code simpler, it means that
> you haven't found the correct expression of the algorithm.

That may not matter. Sometimes goto or multi-level break can be a useful,
temporary way out of a tricky situation.

Later on it can be fixed up properly, but often the code is still subject to
changes and might end up completely differently or even disappear entirely.

No point in that case to introduce extra variables, logic, functions, in
short turn the code upside down to remove a goto or break, when a minute
later you have to do it all again.

> And of course, the problem isn't with goto, per se. It's with
> the way it is used. But because it can be abused so badly,
> modern languages (including C and C++) provide all of the
> necessary structures (and then some) so you don't have to use
> it.

There are sometimes nice control structures not directly available in the
language (language designers seem a conservative bunch...). Although it
would be better to try and get along with what there is, goto is a useful
extra tool, especially if translating from another, more expressive
language.

But it can cause problems if used without discipline and in a haphazard
manner (jumping into or out of expressions for example). But then, so can
any other feature.

--
Bartc

From: Leigh Johnston on


"James Kanze" <james.kanze(a)gmail.com> wrote in message
news:f8ad45ef-b5e6-488c-8940-5841b2408e0b(a)11g2000yqr.googlegroups.com...
> 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? (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.)
>
> --
> James Kanze

I don't use goto much, I have just three uses of it in my entire codebase
and in all cases it is for breaking out of a nested control structure: two
are for exiting a switch inside a while loop and the other is exiting a
nested for loop. The alternative to using goto in these cases would involve
the creation of an extra exit flag that would have to be checked at each
level which is not always desirable.

/Leigh

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