So my last post about with statements was about me using one, and instantly realizing "what I had done." This post about with statement is just to make your eyes bleed. Courtesy of the VirtualTrees.pas...

So my last post about with statements was about me using one, and instantly realizing "what I had done." This post about with statement is just to make your eyes bleed. Courtesy of the VirtualTrees.pas...

  with FHintData, FDrawBuffer do

Now who's idea was it to allow with to use more than one variable at a time? Why this insanity? LOL! It's almost as if the developers are DARING me to figure out what they are doing, heh.

Comments

  1. Withception... gotta go deeper! I'm sure I saw a with statement in our code base with'ing 4-5 objects at once.

    ReplyDelete
  2. VTV source code is a nightmare tbh and these withs are a big reason why.

    ReplyDelete
  3. Stefan Glienke Agreed. But it's a really good component. I ran into this because I found a condition where freeing a frame that has this control in it at just the time it starts a hint animation causes the hint window to request a font object from a node after the control is gone. Hard to figure out the best way to fix it when you step into code that is filled with such things as nested with clauses! (Calling Application.CancelHint before letting the frame get destroyed was my ultimate solution, rather than trying to muddle in code like that.)

    ReplyDelete
  4. This is what I meant by 'nested with' earlier... ;-)

    ReplyDelete
  5. Code from old days ... nowadays you can use generics and closures to build &With.Values( foo, bar ).&Do( procedure ( const f: TFoo; const b: TBar ) begin ... end ); to have a with look and feel without the dark sides of plain with

    ReplyDelete
  6. Oliver Münzberg How does that construct replace with in any form. A simple variable declaration for f and b would do that without closures, generics while keeping best generated code possible. With is an excuse to extract code into its own method where it belongs or hiding LoD violations.

    Your construct also still requires writing f.Something or b.SomethingElse while a with does not which is the point (and danger) of with.

    ReplyDelete
  7. Stefan Glienke It is the same as with with ... the best/safe/robust code is without

    ReplyDelete

Post a Comment