:: [DNG] GOTO considered beneficial
Etusivu
Poista viesti
Vastaa
Lähettäjä: Hendrik Boom
Päiväys:  
Vastaanottaja: dng
Vanhat otsikot: Re: [DNG] C exception handling
Aihe: [DNG] GOTO considered beneficial
On Fri, Nov 01, 2024 at 05:39:43PM -0600, Bob Proulx via Dng wrote:
...
> I have always
> considered goto to be a keyword of the damned but this causes me to
> stop and think and consider that maybe I have been too harsh when it
> is used appropriately.


In a parser generator that I wrote in Pascal once, I had a very complicated
search operation that had to recursively wander around the incomplete LR automaton
to do lookahead calculation. And there were two independent sets of hested searches
-- one which had to find sometning satisfyig particular constraints,
and another, nested one that had to search something else. in prder to validate
what the first (outer) one tentatively found.

When a search succeeded it would set a global variable to indicate what had been
found and simply do a GO TO to get out of the entire recursive nest.

Very simple, efficient, and clear.

When later (for whatever reason) converting this to Modula 3, which did not
have such exiting GOTOs, I had to make all those intermediate recursive functions
return and test success/failure return codes -- a much more error-prone activity.

I might add that these GOTOs were not there to handle error conditions.
They were success condition.

I initially tried to use Modula 3's exceptions to implement these successes,
but thsy did not have enough precision to get to the exact right level in the
recursion. A GOTO to a syntactically nonlocal label was exactly the right tool.

-- hendrik