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

Max Vlasov max.vlasov at gmail.com
Wed Aug 3 19:11:36 CEST 2011


On Wed, Aug 3, 2011 at 7:15 PM, Michael Van Canneyt
<michael at freepascal.org>wrote:

>
> Like I said, there is a 'risk' when using with, I know this. But I think it
> is very small indeed.
> (in fact, last week I had such an error after refactoring code, but it was
> the first time in maybe 10 years)
>
> I just don't think that the solutions presented will make it any better.
> Say you introduce a switch that forces you to use 'With'.
> Then what ?
>
> You'll have to check all 'with' statements because suddenly they no longer
> compile.
> I doubt this will make you find the bug. In the worst case, you'll end up
> prefixing the wrong properties with 'self'.
>
>
>

Let's forget about the suggestion with mandatory self, it wasn't a good for
plenty of reasons :). I'd left with the one that shows error when 'with'
brings unambiguousness. I think there's no big problem with unique names
like myspecialproperty or something like this, but there are also:

count, length, items, width, height

used many times in lcl and elsewhere (btw, it's interesting to know the name
of yours in your example). Introducing the switch and enabling it now and
forever will be like an investment to the future, you won't notice the
difference right now, but it will make you safer later if some of the object
used in 'with' statement introduce a property with one of those frequently
used names and this could instantly change the context of some lines.

Anyway, it's not a big deal to encourage the developers who has many more
important things to do, maybe a reason to look into the internals of
freepascal myself and find out more :)

Max
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110803/cc59c71e/attachment-0003.html>


More information about the Lazarus mailing list