[rust-dev] Fwd: &self/&mut self in traits considered harmful(?)
Vladimir Matveev
dpx.infinity at gmail.com
Tue Jun 17 04:41:37 PDT 2014
> 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.
That said, for mathematicians it is absolutely not a problem that multiplication for matrices works differently than for scalars.
More information about the Rust-dev
mailing list