Re: OON: matrix 'object' operations

From: Konrad Hinsen (hinsen@ibs.ibs.fr)
Date: Fri Mar 21 1997 - 05:18:51 EST


> However, when you want a class to behave like an elementary type value
> semantics are indispensable. Imagine implementing complex numbers or
> quatertions or 3-vectors with reference semantics. In order to be safe you
> would have to make them immutable. This eliminates expressive syntax such as
> "A.z = 0." and replaces it with things like "A = vector(A.x,A.y,0.)" or worse.

Immutable types have the nice feature that there is no practical
difference between value and reference semantics, so a clever
optimizer could produce the efficiency of value semantics even in a
reference semantics language. It is true that some operations become
more complicated, but I don't find myself often in a situation where I
have to change one component of a 3-vector.

> As for copy constructors, etc., these aren't any harder than writing a copy()
> method in another language and for objects that don't allocate memory they
> are synthesized automagically by the compiler. Also, any bugs in these

They aren't harder once you know how everything works, but from my experience
with explaining C++ to others, they are a major stumbling block. The
automagical construction by the compiler only adds to this: you have to
understand exactly what the compiler does for you to know whether it's
fine or not.

> I'll agree that mixed semantics make code confusing, but every language uses
> value semantics for elementary types. Therefore, C++ makes the different

But these are immutable types, where it makes no difference. For example,
in writing Python programs I usually think of everything as reference
semantics. I know that for efficiency small integers are effectively
translated to value semantics, but I don't have to know.

Still providing both semantics makes sense, of course, but I'd rather
see it as an explicit language feature with support for both (I think
Sather does it). C++ lets you do reference semantics, but you have to
do all the low-level work yourself (reference counting etc.).

> But if you really wanted aliasing or reference semantics you could use
> pointers or references to make it explicit. This is why I love the power of
> C++.

I love it too. I just wish it came at a smaller price in terms of
complexity.

-- 
-------------------------------------------------------------------------------
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