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

ik idokan at gmail.com
Tue Aug 2 17:08:55 CEST 2011


On Tue, Aug 2, 2011 at 18:03, Marcos Douglas <md at delfire.net> wrote:

> 2011/8/2 Max Vlasov <max.vlasov at gmail.com>:
> > Hi,
> >
> > Personally I stopped using 'with' keyword long time ago, but there are
> code
> > fragments from the past and today I fixed a little bug showing again that
> > it's a evil. TCanvas in lazarus has width and height properties while in
> > Delphi it hasn't (at least some time ago). So the code below leads to
> > different results in lazarus and Delphi, at least for design-time
> drawing.
> >
> > procedure TControlDescendant.Paint;
> > begin
> >   with Canvas do
> >   begin
> >       Rectangle(0, 0, Width, Height);
> >   edn;
> > end;
> >
> > So not only the 'with' context can silently change while the project is
> > evolving, it can also change while it's being ported...
>
> IMHO, 'with' should have an implicit pointer like 'self' (could be
> 'this' or whatever).
>
> Eg:
>
> procedure TControlDescendant.Paint;
> begin
>  with Canvas do
>  begin
>       this.Rectangle(0, 0, this.Width, this.Height);
>  edn;
> end;
>

That's also bad. Because I can use for example "with" the following way:

with area, canvas do
  begin
    Rectangle(0,0, with, height);
  end;

If you'll have "this" or "self" or $_ (in perl :)) it still contain the same
problem. I prefer explicit code then implicit code. It's more readable and
less error prone.

I think that "with" like "goto" need to be enabled by special parameter and
not allowed by default.


>
> Marcos Douglas
>

Ido


>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110802/95f35289/attachment-0003.html>


More information about the Lazarus mailing list