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

Sven Barth pascaldragon at googlemail.com
Thu Aug 4 08:10:42 CEST 2011


Am 03.08.2011 09:31, schrieb Michael Schnell:
> On 08/02/2011 06:39 PM, Jürgen Hestermann wrote:
>>
>>
>> In general I find the "with" statement very useful and have used and
>> do use it a lot.
> If you are clever enough to avoid confusion ;) . (Such as a nested with
> that defines the same identifier for both "with"ed record and maybe same
> is also defined as the "implicitly with"ed "self" (instance record).
>> And it also saves the program from calculating array indices and other
>> references in these expressions multiple times so it speeds up the
>> code too.
> A decent compiler should be able to perform this optimization on it's
> own account.

The code that calculates the indices and handles other references could 
have side effects, so the compiler would not be able to optimize them. 
If you use this code once inside the "with"-clause you tell the compiler 
to do that calculation only once and that you are aware of possible side 
effects (or thus not occuring side effects).

Regards,
Sven




More information about the Lazarus mailing list