Jump to content

David Heffernan

Members
  • Content Count

    3536
  • Joined

  • Last visited

  • Days Won

    175

Posts posted by David Heffernan


  1. The try finally here isn't protecting the execution of the constructor. It protects against exceptions in the code that runs after the constructor completes, after the try.

     

    Look at the code in your post. The try finally is not active when the constructor runs. If an exception is raised in the constructor then the try is never reached.

     

    So, yes, you do need the try finally. 

    • Thanks 1

  2. 10 minutes ago, Mike Torrettinni said:

    I thought he was referring to record helpers.

    I literally wrote class helpers. 

     

    2 hours ago, Mike Torrettinni said:

    Whenever I think about these I remember 'you can only have 1 active record helper at a time...' and I stop as I have no idea if that means it will stop other helpers working.

    It will. That's a problem if you are using other helpers for the class. Are you? 


  3. 3 hours ago, Mike Torrettinni said:

    You can't always extend some things, right? Records are one of them... for example: I used to have xml library that had XMLNode.GetAttributeAsInteger, the new (better) xml library doesn't. So, since .ToInteger fails on empty strings, and I prefer using StrToIntDef as little as possible, I just added the new method to the library source.

    This is what class helpers are for. 

     

    3 hours ago, Mike Torrettinni said:

    Or Virtualtreeview - for years I had my own AutoFitColumnWidthIncludingCaption, which was implemented I think in one of the latest updates (this or last year) -so I guess I will not need this patch anymore.

    Likewise. 

    • Thanks 1

  4. 9 minutes ago, chkaufmann said:

    So just that I get it right: Because my return value is an interface type, the compiler adds something like this as first statement of the method:

     

    Result := nil;

    Not quite. The default initialisation is outside the function. 


  5. You don't get this because the return type is a managed type and so is actually passed as an extra var parameter. So the variable is assumed to have been default initialised outside the function. 

     

    I'm not trying to defend the compiler design here. The handling of function return variables is a complete mess in my view. They should be passed by value from callee to caller. The whole hidden var param is a weird hack from the ancient past that should never have been done. 

     

     

    • Like 2

  6. 2 hours ago, Arnaud Bouchez said:

    It occurred to Eric at least with DWS. He actually monitored it before fixing it.
    Of course, he dealt with a language compiler and execution stack, but I guess a lot of other kind of projects may have very tiny objects - if the SOLID principles are properly followed.

    I'm not denying the existence of the problem.  I'm just putting up a flag to say that I believe that in a great many codebases you are very unlikely to encounter it.

     

    So, don't get to too stressed about this, and perhaps don't worry about trying to fix the problem unless you know for sure that you are affected by it.

×