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?
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?
the "creator" is responsable for "freeing"
ReplyDeleteIf 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.
ReplyDeleteOtherwise, 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.
I'd accept it if it was named
ReplyDeletefunction CreateSourceAMSIDTypeList: TStringList;
Personally, I've come to prefer using anonymous methods.
ReplyDeletevar
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.
It's a free-standing method that gets assigned to a combobox, as in
ReplyDeleteMyComboBox.Items := GetSourceAMSIDTypes;
Nick Hodges Where I have similar routines, I pass the combobox into the routine that fills it.
ReplyDeleteIn that case, it would be a lot cleaner to do
ReplyDeleteprocedure SourceAMSIDTypesPopuplate(const Items: TStrings);
...
SourceAMSIDTypesPopulate(MyComboBox.Items);
Maxim Abramovich Oh yeah, it is indeed. Hence my interest in it. ;-)
ReplyDelete"MyComboBox.Items := GetSourceAMSIDTypes;"
ReplyDeleteI'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...)
TStrings seems more appropriate :-P
ReplyDeleteEric --
ReplyDeleteI agree with you -- it should take ownership in this particular case.
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#...
ReplyDeleteEric Grange I didn't know you don't get the VCL source in Starter... That's legitimately disappointing
ReplyDeleteThe 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.
ReplyDeleteFré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 ;)
ReplyDeleteUsually they strip out the comments. Must have missed that one. ;-)
ReplyDeleteNick Hodges It is, but to expect much return on the starter version with no source and no printed docs is also a bit much.
ReplyDeleteNobody prints docs anymore.
ReplyDeleteStarter 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.
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.
ReplyDeletePeople pay money for editions that have it, and less for those that don't, so clearly it does have value in the market.
ReplyDeleteNick 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...
ReplyDeleteUnless it is factory which returns new instance.
ReplyDeleteNick 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.
ReplyDeleteKevin --
ReplyDeleteHow 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.
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.
ReplyDeleteHowever, 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?
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?
ReplyDeleteSeriously, 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.
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)
ReplyDeleteKevin --
ReplyDeleteIt'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.
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.
ReplyDeleteBTW: 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.
I'm talking about theoretically removing things as a way to illustrate the value of the VCL source code. That's the point --
ReplyDeleteThey 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.