Re: OON: matrix 'object' operations

From: Konrad Hinsen (hinsen@ibs.ibs.fr)
Date: Thu Mar 20 1997 - 08:35:21 EST


> 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

I wasn't referring to the memory problem; that is indeed the same.
But value semantics add lots of problems: copy constructors, overloading
the assignment operator, the need for separate reference variables. Each
of which is a potential source for subtle bugs. And what advantages
do you get in return?

I don't see any solution to the memory allocation problem without some
form of lazy evaluation that includes an analysis of the expression
being evaluated. Ideally this analysis should happen at compile time,
but I don't know any language that allows the specification of
type-specific compile-time optimization rules.

> assume the former.) Also, it is quite possible (and not that hard) to
> implement reference semantics and reference-counted storage in C++. Then the

True, but I have the impression that this is considered "against the
spirit" of the language and therefore rarely done. And it certainly
doesn't make a program easier to understand if there are both types
of semantics around.

> 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

That's is probably true. Once more compatibility rears its ugly head.
Why is everyone so keen on compatibility? As long as I can link C code
to whatever language I am using, I am happy. Once you drop the
compatibility requirement, there are other OO languages (e.g. Eiffel
or Oberon) which are much simpler and cause much fewer surprises.

> 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

I guess a good code optimizer could make a reference-semantics approach
equally efficient, but I don't know whether this has actually been done.

-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-4.76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:05 EST