[rust-dev] Fwd: &self/&mut self in traits considered harmful(?)
SiegeLord
slabode at aim.com
Thu Jun 19 04:24:16 PDT 2014
On 06/17/2014 07:41 AM, Vladimir Matveev wrote:
>> Overloading Mul for matrix multiplication would be a mistake, since that operator does not act the same way multiplication acts for scalars.
>
> I think that one of the main reasons for overloading operators is not their genericity but their usage in the code.
>
> let a = Matrix::new(…);
> let x = Vector::new(…);
> let b = Vector::new(…);
> let result = a * x + b;
>
> Looks much nicer than
>
> let result = a.times(x).plus(b);
>
> In mathematical computations you usually use concrete types, and having overloadable operators just makes your code nicer to read.
Fair enough (indeed I don't think the current operator overloading is
usable for generics), but I still stand by my point. It is just more
useful in practice to sugar the element-wise multiplication than matrix
multiplication (i.e. I find that I use the elementwise multiplication a
lot more often than matrix multiplication). This isn't unprecedented, as
Python's Numpy library does this too for its multi-dimensional array
class (notably it doesn't do this for the dedicated matrix class... but
I found it to be very limited and not useful in generic code).
-SL
More information about the Rust-dev
mailing list