[fpc-devel] Generics Basics

Bram Kuijvenhoven kuifwaremailinglists at xs4all.nl
Wed Nov 9 14:46:25 CET 2005


Daniël Mantione wrote:
> Op Wed, 9 Nov 2005, schreef Bram Kuijvenhoven:
>>Daniël Mantione wrote:
>>(Ok, maybe I'm exaggerating a little bit, but don't you agree generics /are/
>>useful?)
> 
> Certainly I do agree. However, they *will* be used to introduce the 
> bloated programming I described. I don't think we should be happy with 
> that.

You are right, unfortunately it will be used in that way too.

>>Won't the compiler sometimes be able to handle this smarter? When the code
>>generated for vector<TClassA> and vector<TClassB> is equivalent, we only need
>>to include it once in the resulting executable, right? The only thing is we
>>have to see when this situation occurs.
> 
> These tricks have been used in some C++ compilers with very limited 
> success. The problem is that class_a has a different virtual 
> methods/constructors/destructors than class b, so the code to be generated 
> for them will be different, even though they are still just basically 
> arrays of pointers.

If a class only uses the :=, = and <> operators on the generic type, the code could be the same for all specializations for classes, or am I mistaking here? (The only problem is RTTI perhaps.)

Is there a problem with C++ that they can't use this? Or am I just overlooking something? (that is of course not unlikely) Can you give an example please?

> No. Pascal is not a deficient language in any way; it has way more usefull 
> features than C++ has. What will save it is good, very good development 
> tools and good, very good libraries.
> 
> If you think templates will save Pascal, or it will die without, that is a 
> very naive thought. The most used language is stil standard C. Why?

You are right that good libraries and development tools are *very* important for the future of Pascal. Generics support is not the most important thing for that. (Though I think it is at least quite important) And you are right, Pascal definitely has some advantages over C++.

For algorithm programming contests, perhaps XML or compression libraries are not so important. Generics (and a corresponding container library) can help a lot there though. On the other hand, use for programming contests doesn't measure to what extent a language is 'alive' - e.g. PHP is a popular language, but not used at the ACM contests (ok, it is a scripting language, but still).

BTW I'd like to help writing a container library, but plan to wait for Generics support first.

Bram



More information about the fpc-devel mailing list