[fpc-pascal] The reason why linus torvalds hate-pascal

Rodrigo Palhano rodrigo at speedcase.com.br
Thu Apr 17 19:26:55 CEST 2008


this

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

is better than this ?

if ( payments per year <> 12 ) then begin
   Result := 1
Else if ( rate = 0 ) then
   Result := 2;

or even this ?

begin
  If not CheckPayments (Result) Then
     CheckRates(Result);
end;

Well, i guess that´s particular, i am just not a huge fan o EXITing code  
in any
unpredictable place.


On Thu, 17 Apr 2008 13:10:09 -0300, Alan Krause <alank at shermanloan.com>  
wrote:

> 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 at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



-- 
Rodrigo Palhano
---------------------------------
Equipe SpeedCASE
http://www.speedcase.com.br



More information about the fpc-pascal mailing list