[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GSoft BASIC Ramble
On Jun 8, 3:49 am, limtc <thyech...@gmail.com> wrote:
> I am so used to "leave" and "exit" that I am not aware that it is not
> part of Standard Pascal!
>
> I hate "goto" - sign. I assume I have to relearn what I learned in
> Pascal class - use a repeat/while loop with a boolean flag... but this
> seem to clunky compared to "leave" and "exit". You really sure there
> is no other way...?
>
> On 6月7日, 上午8时48分, Polymorph <polymorp...@hotmail.com> wrote:
>
> > I know a lot of old timers like GOTO statements even in high-level
> > languages and I've heard all the merits before, but I still reckon
> > they're a poor substitute for a well implemented language construct
> > (for example a "leave" or "exit" statement). That's my opinion anyhow.
Strangely enough, the reason there is no leave or exit statement in
Pascal is precisely because it is essentially a goto statement without
a line number. Anyone who criticizes goto because it is not structured
enough should not be using leave or exit, or break, continue and
return in C (except for the last line of a function). One of the
central tenants of structured programming was to have exactly one way
in or out of a loop or procedure.
Aha! But why did Pascal, the ultimate structured programming language,
still have goto, you ask triumphantly. Actually, for error handling.
It was illegal to jump _into_ a loop or procedure, but guess what: You
can actually jump _out_ of a procedure in ISO Pascal. This capability
was important before try-catch blocks arrived on the scene. This
important capability is not addressed by leave or exit, and without
it, goto probably would not have been in the Pascal language.
Ironically, few Pascal compilers actually implement goto properly,
allowing a jump out a a procedure.
So, the best solution to moving code from Complete Pascal to ORCA
Pascal is to eliminate the very idea of jumping out of a loop.
That said, I occasionally used a goto myself to improve efficiency
when exiting a loop. I also vastly prefer goto to C's break and
continue, precisely because it is easier to tell exactly what the
statement is doing--which loop does break leave? What if they are
nested--how do I jump out of multiple nested loops? To me, if you are
going to "break" out of structured programming for the convenience of
leaving a loop early, you should "goto" the best way to do it.
Also, Pascal was always intended to be a minimalist language. Unlike
C, it largely kept that design goal, remaining remarkably uncluttered
and thus easy to learn and use. Since goto can accomplish everything
exit or leave can accomplish, plus be used for the only legitimate
structured programming task for this kind of statement (error exits),
why clutter the language?
Because you like the statement, of course. Everyone makes different
design decisions. Good thing you have the source. :)
Mike