Question of the Day: Is it ever appropriate to do something like this:

Question of the Day:  Is it ever appropriate to do something like this:

function GetSourceAMSIDTypes : TStringList;

I say no.  I say you should pass in a parameter to be filled instead of returning an instance.  

What say you?

Comments

  1. the "creator" is responsable for "freeing"

    ReplyDelete
  2. If it's a Get then it's appropriate if it's a getter for a property, and the returned objects is owned by the object with the property.

    Otherwise, if the list is created, then it should be named CreateXxx or something similar.

    Passing a parameter to be filled is limiting, as it means you can't specialize the class you create (f.i. you may want to return a TStrings, but internally create a TAugmentedStringList).

    If you want a method to fill something, then unless you have some performance requirements, you should pass a callback as parameter, not a container/collection class.

    ReplyDelete
  3. I'd accept it if it was named
    function CreateSourceAMSIDTypeList: TStringList;

    ReplyDelete
  4. Personally, I've come to prefer using anonymous methods.
    var
      MyList: TStringList;
    begin
      MyList := TStringList.Create;
      SourceAMSIDTypeList.Enumerate(procedure (const Item: TMASIDType)
        begin
          MyList.Add(Item.ToString);
        end);
      ...

    Mostly because it leaves me free to treat the list content in different ways in different places.

    ReplyDelete
  5. It's a free-standing method that gets assigned to a combobox, as in

    MyComboBox.Items := GetSourceAMSIDTypes;

    ReplyDelete
  6. Nick Hodges Where I have similar routines, I pass the combobox into the routine that fills it.

    ReplyDelete
  7. In that case, it would be a lot cleaner to do
    procedure SourceAMSIDTypesPopuplate(const Items: TStrings);
    ...
    SourceAMSIDTypesPopulate(MyComboBox.Items);

    ReplyDelete
  8. Maxim Abramovich Oh yeah, it is indeed.  Hence my interest in it.  ;-)

    ReplyDelete
  9. "MyComboBox.Items := GetSourceAMSIDTypes;"

    I've grown to consider that properties of object type should never have a setter in Delphi unless they take ownership of the object. Having a setter that does an Assign is just asking for memory leaks.

    The VCL is particularly bad in that regard, as it's a mishmash of some taking ownership and others doing Assign. With experience you come to know them, but for a newbie? The doc is the only way to know (and we all know the state of F1...)

    ReplyDelete
  10. Eric -- 

    I agree with you -- it should take ownership in this particular case.

    ReplyDelete
  11. Maxim Abramovich You don't get VCL source in Delphi Starter. And telling a newbie he has to look into the VCL to know how to use something as simple as a combo box won't exactly make Delphi look better than Java or C#...

    ReplyDelete
  12. Eric Grange I didn't know you don't get the VCL source in Starter... That's legitimately disappointing

    ReplyDelete
  13. The VCL source is one of the most valuable parts of the product -- to expect to get that with the low-cost version is a bit much.

    ReplyDelete
  14. Frédéric Hannes they don't want you to see the ugly comments in the source code before you buy the full version ;) SOAP* units comments = pure fun ;)

    ReplyDelete
  15. Usually they strip out the comments.  Must have  missed that one.  ;-)

    ReplyDelete
  16. Nick Hodges It is, but to expect much return on the starter version with no source and no printed docs is also a bit much.

    ReplyDelete
  17. Nobody prints docs anymore.  

    Starter is just that -- for starters.  When you move past the need for it, you need to pay for the features that you need.

    It's really hard to come up with a profitable SKU at that price point.  I think they actually did a good job.

    ReplyDelete
  18. It's 2013.  Other than a source of reference for Delphi developers, I doubt the VCL source really has that much value in today's market.

    ReplyDelete
  19. People pay money for editions that have it, and less for those that don't, so clearly it does have value in the market.

    ReplyDelete
  20. Nick Hodges Those are good points, but as a starter, I'd find it hard to learn Delphi if I couldn't at least check out the VCL source...

    ReplyDelete
  21. Unless it is factory which returns new instance.

    ReplyDelete
  22. Nick Hodges Only if source is the sole reason people pay more for editions that have it.  Since editions that have it also include features in addition to source code, it is not possible to make such a determination.  Anyway, I've caused some thread drift here, so I'll leave it.

    ReplyDelete
  23. Kevin --

    How much could EMBT charge for a Pro version minus the VCL Source code?  

    The answer to that question is how much the source is worth.  I suspect that it's not a small amount.

    ReplyDelete
  24. Nick Hodges  I think there would only be two reasons for EMBT to not include source.  One would be to protect their IP.  Clearly this isn't the case because one can get the source in other editions.  So, we're left with the other reason, a misguided way to motivate people to pay for a higher priced SKU because EMBT views VLC source as some type of feature worth paying for.

    However, the real value of that "feature" is that the VCL source is a great reference and learning aid, and not including it is like not including documentation.

    If EMBT's intention is to grow their user base, shouldn't they make it as easy as possible for people to learn and understand Delphi; especially those at the entry level?

    ReplyDelete
  25. Simon Stuart Ok, let's be ridiculous.  Why not have a set-up where the developer is charged some small fee per LOC compiled successfully?

    Seriously, having VCL source gives little added benefit other than the major benefit of a reference and learning aid.  Why hold that back from them?  If that answer is simply, "because, I can make money by charging them for it", then I think that is a twisted view on how to grow sales.

    ReplyDelete
  26. It's a bit confusing as to the ownership of the TStringList so this syntax is best avoided.  Using a var or out parameter would be clearer.  I guess one could say the code has a bad smell (ripe for refactoring)

    ReplyDelete
  27. Kevin --

    It's not hard to see:  If you took the VCL Source out of the Pro SKU, EMBT would have to charge less -- no one would pay the Pro SKU price for something less than the Pro SKU.

    Thus, the value, measured in dollars, for the VCL source is the actual difference between the two prices.  What that is, I don't know, but it's a real number -- I suspect it approaches a couple of hundred dollars.

    Or look at it this way -- what would happen if they stopped shipping the VCL source with the Pro SKU?  People would go nuts, and rightfully so.  

    That "level of nuts" is a measure of the actual dollar value of the VCL Source.

    ReplyDelete
  28. Nick Hodges Who's talking about removing things?  There's nothing stopping EMBT from adding value to a SKU, such as Starter, without increasing its price.  They tweak SKU feature sets all the time without adjusting price.

    BTW: Delphi feature matrix, 16 pages. A lot more than just VCL source separates Starter from Pro.

    Anyway, neither of us are in a position to change what EMBT does, so as often happens in the Delphi non-tech NG, the discussion becomes pretty much pointless  to continue after each person has stated opinions which, speaking only for myself, are unlikely to change.

    ReplyDelete
  29. I'm talking about theoretically removing things as a way to illustrate the value of the VCL source code.  That's the point --
    They could add the VCL source to the Starter, but that would seriously poach Pro sales -- believe me, I spent huge amounts to time looking at this.

    ReplyDelete

Post a Comment