[fpc-pascal] with statement using mulltiple objects

J├╝rgen Hestermann juergen.hestermann at gmx.de
Sun Sep 14 12:22:10 CEST 2014


Am 2014-09-14 12:08, schrieb Mattias Gaertner:
 >>  > All seasoned programmers know that and try to avoid the with statement.
 > The quote is from Marius, not from me.

Correct. I deleted the wrong reference. ;-(


 >> Realy? I love it. Consider these two varianst of code from one of my programs:
 >>
 >> ---------------------------------------------------------
 >> with TreeRoot.SubDirs[Low(TreeRoot.SubDirs)]^ do
 >>     begin
 >>     DirLogged             := true;
 >>     DirHatFocus           := false;
 >>     SubDirsExpanded       := true;
 >> [...]
 >> ---------------------------------------------------------
 >
 > and
 >
 > ---------------------------------------------------------
 > d:=TreeRoot.SubDirs[Low(TreeRoot.SubDirs)]; // local var d
 > d^.DirLogged             := true;
 > d^.DirHatFocus           := false;
 > d^.SubDirsExpanded       := true;
 > [...] ---------------------------------------------------------


Long-winded and still not the same clarity as in the with statement.

Do you also prepent *all* function and variable names
with the unit name they come from?
Do you realy *always* write

LazUTF8.UTF8Delete
instead of
UTF8Delete
?

Nested WITH statements and the unit concept share the
same problem but still the benefits outweigh the drawbacks IMO
(once you get used to it and keep possible problems in mind).





More information about the fpc-pascal mailing list