[fpc-devel] Generics
Flávio Etrusco
flavio.etrusco at gmail.com
Tue Apr 11 18:42:04 CEST 2006
On 4/11/06, Marco van de Voort <marcov at stack.nl> wrote:
>
> > Templates' pros:
> > - support of primitive types;
> > - flexibility (ability to call non-virtual and non-related methods,
> > operators, etc);
> > - ability of coding for speed.
> >
> > Type erasure generics' pros:
> > - No additional generated code, no code bloat;
> > - Code is easier to understand (no additional trips for symbol resolution);
> > - Easy (possible ;-) to debug.
> > - Much easier to implement (in the compiler) ;-)
First, I should have made it more clear that I meant:
- Templates = C++ templates = macros;
- Type erasure generics = Java generics = the template has an
equivalent _single_ class, for which templates parameters are resolved
by normal OO, and each "template instance" (e.g. TList<TItemType:
TComponent>) don't generate any additional code, the instance types
are only know at compile-time and checked and exposed for external
code.
To summaryze yeat more:
Generics are much simpler to use and to implement, I'm afraid poeple
will overuse (and use badly) template flexibitlity, and there's no way
to implement 'properties' without getter methods when using "type
erasure" through templates.
> What I don't understand is all these differences between templates and
> generics while the only difference is that for classes you do type erasure.
>
> Note that for reference types you can also do type erasure under FPC _AND_
> classes are always reference types.
Can you please be more specific? English is not my native language and
I'm having some trouble to understand what you meant.
Best regards,
Flávio
More information about the fpc-devel
mailing list