Konrad Hinsen wrote:
> But that's a problem specific to C++; most other OO languages use
> reference semantics. Which makes me wonder: is there a technical reason
> why C++ is the most common OO language for numerical work, or is it
> just due to the relatively easy availability of C++ compilers?
> >From my personal experience, C++ is about the least convenient OO
> language in existence.
I agree that one cannot write "A = B * C" in C++ without allocating extra
memory. However, the same is true of languages with reference semantics. B *
C will still create a new object which will then replace the object referred
to by A. It is possible that the language designer had this in mind and that
A is therefore garbage collected before B * C is evaluated, but if this is not
the case the memory usage is the same. (I'm not sure which is the case but I
assume the former.) Also, it is quite possible (and not that hard) to
implement reference semantics and reference-counted storage in C++. Then the
no-extra-storage call would look like "A.free(), A = B * C".
I think C++ is popular because it is fast and type-safe while remaining
compatible with existing C code and it will become more popular as templates
come into more common use. Reference semantics are nice for dealing with a
few heavyweight objects (like big arrays) or when performance isn't critial
(most of the program), but when I want to write a class containing three ints
and then store 100,000 of them in a hash table I don't see anything better
than C++ and a hash table template written by someone else. If I only want to
write "A = B * C" I'll use MATLAB or Python.
-Jim Phillips
jim@ks.uiuc.edu
This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:05 EST