Phlip said:
I mean an easier syntax can eliminate the need for the entire concept of
generics. If everything is an object, including classes, then you can pass a
class name into a function: foo(MyClass). Then you declare the function as
foo(klass), and to get an object you use MyClass.new(). This provides the
entire Prototype Pattern, built-into the language.
So far -- yes.
But again --- Each type of language may have a easy syntax providing
the ability to be generic, but the point is to be generic without
loosing speed and that is only possible with a compiler language not
with interpreters or just in time compilers. Of course there are
examples where templates are just used to compensate the insufficiency
of C++. First a popular example for that. For vectors a,b,c,d you may
write: a = b + c + d
The main reason why e.g. Fortran is faster on that than C++ (without
templates) is that Fortran is just summing up the vector components and
assigns them to a. In contrast C++ creates an object for c+d and then
adds the components of this temporary object to b leading to a new
temporary object whose components are assigned to a. Using templates it
is possible to get the same behavior for C++ as in Fortran and in fact
to get the same speed (there are publications on that). So this is as I
said an example where templates are used to cure insufficiencies of
C++, but thats not always the case. Also a simple example for that: In
my daily work I am often using a class for n-dimensional grids (with
variable size for each dimension), where I need several different
iterator-classes e.g. for iterating over a specific grid-shell. Of
course there are mathematical rules to calculate the step the iterator
must take from one grid-point to the next one depending on the number
of dimensions and the size of each dimension. But these values (the
step-size) are calculated at compile time giving an advantage in speed
that could not be realized by an interpreter. You can't build in
specializations for such specific tasks into a language.
Uh, Python, Ruby, and Smalltalk?
(I think Smalltalk is the language of the future, and it always will be!)
Smalltalk is something I definitly have to try out (I never had a look
on a smalltalk program until now.).
But Python is something I am really used with (I have heard that they
solved the huge bugs in the garbage collection for version 2.5 -- is
this right?). But I encountered the frontiers of python very early that
forced me to switch to C++ (today I am very happy that I have
switched). I still think it's a nice language to do little tasks if you
have not much time. In fact it doesn't take a week to learn Python -
that's a feature. Of course for me it is now principly unsufficient,
because I am doing scientific programming and there speed matters. My
programs that I ported from Python to C++ are faster by a factor
between 160 and 220. So for me it's just a 2 days calculation what
needs one year in python.
Best regards,
gn