[fpc-devel] Generics Basics
Daniël Mantione
daniel.mantione at freepascal.org
Wed Nov 9 17:16:09 CET 2005
Op Wed, 9 Nov 2005, schreef Bram Kuijvenhoven:
> > 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?
In C++ an assignment involves calling a copy constructor. If a type has no
copy constructor (i.e. a struct), believe it or not, it gets a constructor
automatically.
It is also possible to get automatic destructors. Don't know how, but it
happens.
This means that all template methods that use assignments or new, destroy,
etc. need a call to a different constructor/destructor, depending on the
template type.
> > 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).
Important for a programming contest is the ability to build
datastructures, i.e. building trees and graphs in PHP can be a challenge.
Performance is bad. That is why PHP is not used.
Having some data structures readily available is an advantage, and this
advantage can be implemented with templates.
However, coding in Pascal isn't bad at all. First, it's fast. Standard
input is way more simple that Java for example. Usage of sets can save a
load of memory compares to C programmers that use arrays of bytes, not to
mention that memory constraint are a real punishment for Java programmers.
> BTW I'd like to help writing a container library, but plan to wait for
> Generics support first.
It can take a while until the development version is stabilized. Not sure
if that is a good idea. Enjoy FPC's new language features in the
meantime; they aren't used a lot unfortunately :(
Daniël
More information about the fpc-devel
mailing list