[fpc-pascal] some new features to delphi prisem
Jürgen Hestermann
juergen.hestermann at gmx.de
Wed Feb 24 07:10:21 CET 2010
> You are looking at the wrong example! Clearly, for variable assignment
> you don't gain anything. But for a function argument you do!
Realy?
> WriteLn('The value is ',(if X then 'true' else 'false'),
> ' at the moment.');
Well, *this* can be done much easier ;-):
-------------------------------------------
WriteLn('The value is ',X,' at the moment.');
-------------------------------------------
But even if X is not boolean I would find that much more readable:
-------------------------------------------
if X then s := 'true' else s := 'false',
WriteLn('The value is ',s,' at the moment.');
-------------------------------------------
Even with the need of an intermediate variable (most of the time
you can reuse an existing variable) I would prefer this one over
the quite confusing nesting of case statement in an expression.
It states much clearer what happens.
> MakeBackup(FileName,ChangeExtension(FileName,
> case BackupExtension of
> exBak : '.bak';
> exBkp : '.bkp';
> exTilde : '~';
> else '.bak'
> End));
Again, this would be much clearer code:
-------------------------------------------
case BackupExtension of
exBak : s := '.bak';
exBkp : s := '.bkp';
exTilde : s := '~';
else s := '.bak'
End;
MakeBackup(FileName,ChangeExtension(FileName,s));
-------------------------------------------
More information about the fpc-pascal
mailing list