[fpc-devel] Generics

Peter Vreman peter at freepascal.org
Wed Apr 12 08:31:58 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.

The short answer on everything you say: Forget Java generics.

FPC is a compiled language where not all types are classes. The only way
to implement it is like C++ templates. It is a known fact that generics
will introduce code bloat, but that is still less than the 15-20mb virtual
machines you need for Java/C#






More information about the fpc-devel mailing list