[Lazarus] 'with' is evil, isn't it?

Hans-Peter Diettrich DrDiettrich1 at aol.com
Wed Aug 3 16:02:55 CEST 2011


Jürgen Hestermann schrieb:
> cobines schrieb:
>> In case Qarray[QuaderNr]^.Teilung[R] is an object I usually do:
>> tmp := Qarray[QuaderNr]^.Teilung[R];
>>   
> Yes, of course. But it's just so much easier to use "with" which does 
> the same in the background and save you from adding local variables 
> yourself.

With is only "easier" to use from the writers viewpoint. For an reader 
it's much harder to figure out what's going on, and code is more often 
read than written.

When something has to be changed later, it's often recommended to remove 
the With first, before trying to change anything else.

When something changed in the related data types, then it's not clear 
why the code fails now, because it's impossible to reconstruct the 
*previous* meaning (without reverting everything to an earlier state).

IMO there exist only very few situations, where With is both safe to use 
and easy to read.

DoDi





More information about the Lazarus mailing list