Glas :Re: [glas] MTL3 design ? [was MTL project site is up] |
From: Theodore Papadopoulo (Theodore.Papadopoulo_at_[hidden])
Date: 2005-02-02 14:33:26
Sorry, I'm jumping in the discussion.... but I just subscribed to the
list.
> >>>> operator= for vectors does not require both vectors to have the same
> >>>> size. Thus the lhs will be resized to the size of the rhs. But again
> >>>> this poses a problem with stack-based objects because they can't be
> >>>> resized. And why actually do you prefer to resize the lhs instead of
> >>>> requiring that both vectors have the same size?
Speaking of mathematical vectors, this always puzzled me !!! The size of
a vector is part of its type and assigning one vector with another one
of different size gives nothing (but the need to add some runtime
checks), is error prone and is akin to re-using a same variable name for
different objects.
The mathematical vector is not a collection of objects as std::vector.
It has different properties and the more of them you can impose the
better it will be.
Note that does not necessarily means that each vector of different size
should be given a different C++ type, but merely forbids the above
assignement operations (as well as some others).
Actually, in my work, I find the need for both type of vectors or
matrices: fixed sizes at compilation time and fixed size at
initialisation time, period. I almost never have to resize a vector or
to assign one type of vector into an another one.
> Whether or not it's expected or intuitive is highly subjective. The
> question is: will it prevent enough bugs to justify the inconvenience?
> IMO the answer is no.
IMO the answer is definitely yes.
I do not understand where is the inconvenience for linear algebra (in
mathematics all vectors are given a unique size and all algorithms are
depicted that way as far as I know).
And it will definitely catch most dimensional problems as soon as
possible.
Theo.