[fpc-pascal] The reason why linus torvalds hate-pascal
Vinzent Hoefler
JeLlyFish.software at gmx.net
Thu Apr 17 19:03:17 CEST 2008
On Thursday 17 April 2008 17:53, mm wrote:
> Rodrigo Palhano a écrit :
> > On Tue, 15 Apr 2008 19:39:37 -0300, Zaher Dirkey <parmaja at gmail.com>
wrote:
> >> I use GO TO when teaching pascal, but after all i ask them to not
> >> use it, it
> >> just a bridge to learning the logic of programming language.
> >>
> >> There is another word i hate to use it it is EXIT.
> >
> > I also understand EXIT as a bad programming practice, it makes life
> > harder for code readers.
>
> I don't ;-) Even Ada has an "Exit" instruction which one is better
> than the Pascal one because, with Ada, "Exit" is a keyword.
Careful. Ada's "exit" is not Pascal's "exit", it's much more like
Pascals "break" (and thus shares the same deficiences when it comes to
the possibility of obfuscated control structures, but can be even
worse).
What Pascal programmers know as "exit" is called "return" in Ada and in
functions it always comes with the result, which makes it equivalent to
FPC's "exit (ReturnValue);". Which is actually a quite good feature,
because it usually leads to less uninitialized function results and an
| exit (SOME_FAILURE_CODE);
clarifies the intention to the reader a bit better than
|if We_Are_Screwed then
|begin
| Result := SOME_FAILURE_CODE;
| exit;
|end {if};
or the usual shortcut:
|Result := SOME_FAILURE_CODE;
|
[... code ...]
|
|if We_Are_Screwed then
| exit; // Result should still be SOME_FAILURE_CODE,
| // but did you really check?
|
[... more code ...]
|
|Result := EVERYTHING_WENT_WELL;
So "exit" is not that bad and IMO can't be abused too much. But YMMV, of
course.
But with the former "break" you can write *really* obfuscated code.
(Pascal's) "Exit" is "exit" and there's no guessing where that leads to.
With "break" you always have to check the code surrounding the
statement.
Vinzent.
More information about the fpc-pascal
mailing list