Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-11

Generics vs TCollection

10 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I was reviewing some old code that used TCollection & TCollectionItem descendants. This made me think... With the introduction of Generics, is there really still a need for TCollection/TCollectionItem?

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net
Jonas Maebe
to Graeme Geldenhuys
Graeme Geldenhuys wrote
I was reviewing some old code that used TCollection & TCollectionItem descendants. This made me think... With the introduction of Generics, is there really still a need for TCollection/TCollectionItem?

At the very least, backward compatibility with existing code. We even still ship a Turbo Pascal-compatible "objects" unit.

Jonas

Unknown author
to Graeme Geldenhuys: I was reviewing some old code that used TCollection & TCollectionItem descendants. This…
Graeme Geldenhuys wrote 5 lines
Hi, I was reviewing some old code that used TCollection & TCollectionItem descendants. This made me think... With the introduction of Generics, is there really still a need for TCollection/TCollectionItem?

I have tons of code that uses them. Lazarus has tons of code that uses them. There is no way that we're going to rewrite all that stuff.

So: yes, even if only for backwards compatibility.

Nothing stops people from not using it, and use generics instead, if they are so inclined.

Michael.

Graeme Geldenhuys
to Unknown author
I have tons of code that uses them. Lazarus has tons of code that uses them. There is no way that we're going to rewrite all that stuff.

Sorry for any confusion. I did not post this with the intention of removing TCollection/TCollectionItem classes from FPC. I'm simply asking from a functionality point of view. Can Generics replace the usage of TCollection/TCollectionItem in all cases? Purely from a functionality point of view, it seems like it should be possible - but I know nothing of Generics (never used them).

I know Lazarus IDE uses TCollection in many property editors. Could Generics even replace those use cases too? I guess this might be better asked in the Lazarus mailing list.

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net
Graeme Geldenhuys
to Jonas Maebe: At the very least, backward compatibility with existing code. We even still ship a Turbo…
Jonas Maebe > wrote
At the very least, backward compatibility with existing code. We even still ship a Turbo Pascal-compatible "objects" unit.

Please see my reply to Michael. I had no intentions in recommending the removal of TCollection. I'm just comparing functionality of Generics with TCollection.

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net
Unknown author
to Graeme Geldenhuys: Sorry for any confusion. I did not post this with the intention of removing…
Graeme Geldenhuys wrote 11 lines
On 8 November 2011 12:13, wrote: > > I have tons of code that uses them. Lazarus has tons of code that uses them. > There is no way that we're going to rewrite all that stuff. Sorry for any confusion. I did not post this with the intention of removing TCollection/TCollectionItem classes from FPC. I'm simply asking from a functionality point of view. Can Generics replace the usage of TCollection/TCollectionItem in all cases? Purely from a functionality point of view, it seems like it should be possible - but I know nothing of Generics (never used them).

You should see it differently: there is a generics collection which performs the same function as TCollection/TCollectionitem.

The difference is mainly that in the case of TCollection(Item) you need to override the items property; With generics, you can skip this step. At the expense of copying the whole TCollection code each time you create a specialized descendent.

Michael.

tcoq
to Unknown author

It's also possible to create a generic descendent of TCollection, where the only duplicated code is the property override. This is probably the best of both worlds: reusing the TCollection while moving to generics. Best regards
Thierry
----- Mail Original -----
De: "michael vancanneyt"
À: "FPC-Pascal users discussions"
Envoyé: Mardi 8 Novembre 2011 13h22:31 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: Re: [fpc-pascal] Generics vs TCollection

...
The difference is mainly that in the case of TCollection(Item) you need to override the items property; With generics, you can skip this step. At the expense of copying the whole TCollection code each time you create a specialized descendent.

Michael.

Felipe Monteiro de Carvalho
to Graeme Geldenhuys: Sorry for any confusion. I did not post this with the intention of removing…

In my experience generics are very good, but they are not without problems. There are some limitations in the implementation and I have already hit some bumps in the road when using them (search the mailling list, I don't remember exactly the issues)

But I can't compare them to collections, because I never use them except in the LCL parts that use them, my favorites are TFPList, and the generic equivalent (TFPGList or something like that).

Felipe Monteiro de Carvalho
Michael Van Canneyt
to tcoq: It's also possible to create a generic descendent of TCollection, where the only…
tcoq wrote
It's also possible to create a generic descendent of TCollection, where the only duplicated code is the property override. This is probably the best of both worlds: reusing the TCollection while moving to generics.

Hm. I fail to see this: Where is the gain in that ?

Michael.

Show quoted text 23 lines
Best regards Thierry ----- Mail Original ----- De: "michael vancanneyt" À: "FPC-Pascal users discussions" Envoyé: Mardi 8 Novembre 2011 13h22:31 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: Re: [fpc-pascal] Generics vs TCollection ... The difference is mainly that in the case of TCollection(Item) you need to override the items property; With generics, you can skip this step. At the expense of copying the whole TCollection code each time you create a specialized descendent. Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal