mm wrote:
Using "Exit" is not of a bad programming practice. Suppose one has to
write a big procedure, say 150 lines of code. Suppose now that, instead
of writing

  if X = 0 then Exit;

at the beginning of the procedure, one writes

  if X <> 0 then
  begin
    ...

Does a reader immediately see that, when X = 0, the procedure does
nothing? No. They have to read all the code, to search for the "end"
that closes the "begin" in order to get sure there are no instructions
after this "end". In such a case, with the "Exit" instruction the
procedure is much easier to read.


I have to agree, and can give an even better example. In the software I write, many times there are several conditions which need to be checked. If any of these conditions apply, then an appropriate result code should be set and the rest of the routine should not be executed. An example:

if ( payments per year <> 12 ) then begin
  Result := 1;
  exit;
end;

if ( rate = 0 ) then begin
  Result := 2;
  exit;
end;

... add 10 more checks

' ok - we have made it through all the validation checks, so now lets do some actual work
' relevant code goes here

The above is *so* much clearer than implementing 12 nested levels of if..then..else.

Alan
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to