[Lazarus] 'with' is evil, isn't it?
Lukasz Sokol
el.es.cr at gmail.com
Wed Aug 3 14:22:19 CEST 2011
On 03/08/2011 13:00, Alexander Klenin wrote:
> On Wed, Aug 3, 2011 at 22:34, Michael Van Canneyt
> <michael at freepascal.org> wrote:
>>
>>> Of course, a disambiguation facility would be even better,
>>> but I am afraid FPC developers will resist this improvement :(
>>
>> Frankly, I don't understand the discussion.
>> I use 'with' all the time because it increases readability and reduces
>> typing.
>
> Agreed.
>
>> I don't want to be punished with heaps of warnings simply because I use a
>> language feature. Yes, I am aware that there are risks involved.
>
> This is why I suggested to restrict warnings only to a cases
> where actual ambiguity exists, which is actually quite rare.
> Maybe even warning is too much, and it should be a hint.
>
> Anyway, my preferred solution would be to allow aliases in 'with' statement,
> which would improve readability even further while sacrificing only a
> few characters:
>
> with a := MyCompomentList[0] do begin
> Rectangle(0, 0, a.Width, a.Height);
> end;
>
> No chance of ambiguity at all.
>
IM(H)O,
with a:TMyType := MyComponentList[0] do
begin // 'a' only valid from here, spew an error if 'a' is declared, even if different type
end; // 'a' only valid until here
-> based on: look at what E:Exception in try..except..end; does ->
My 2gr.
Lukasz
More information about the Lazarus
mailing list