Someone with a detailed grasp of both can write clear code in C, Haskell, Python even BASIC
If you don't grasp either and have no time to be allowed to do it, no language will save you.
Someone with a detailed grasp of both can write clear code in C, Haskell, Python even BASIC
If you don't grasp either and have no time to be allowed to do it, no language will save you.
* dead-simple array/vector operations (http://www.mathcs.emory.edu/~cheung/Courses/561/Syllabus/6-F...)
* many useful built-ins (e.g., DOT_PRODUCT, MAXVAL/MAXLOC, MATMUL, TRANSPOSE)
* standard math libraries (e.g., LAPACK) with lots of very fast functions for linear algebra
mat a, b, x, tmp, c;
// ...
mat_mul(&tmp, &a, &x);
mat_sum(&c, &tmp, &b);
which is what OP meant if I'm not mistaken.Inside the Python code, each light has a Colour, and I built the Colour class with support for various math operators.
Want to make a Colour that's half as bright as another? Colour = OtherColour * 0.5. Want to blend two Colours? BlendedColour = OneColour + AnotherColour.
Doing this made all of the stuff that the code was doing incredibly obvious and straight forward. The alternative would have involved non-obvious helper functions and object methods or doing math directly on the rgb components encapsulated by each Colour object.
This was, for me, somewhat of a "light bulb" moment for operator overloading.
OneColor + AnotherColor does not have any obvious meaning. If colors are RGBA vectors, it could be vector addition. But is that what your blend operation does?
What's wrong with:
BlendedColor = blend(OneColor, AnotherColor)The meaning makes sense to me which, for a one developer codebase, is OK, but it's not something I'd want to do in a codebase supported by a larger team. I expect that in a more complete product that even the term "blend" would have multiple meanings.
Nothing wrong with writing:
Matrix_Multiply(m1,m2);
vs.
m1*m2
The first is not harder to read and not harder to write but I know exactly what's going on.
func main() {
a := big.NewInt(0)
b := big.NewInt(1)
var limit big.Int
limit.Exp(big.NewInt(10), big.NewInt(99), nil)
for a.Cmp(&limit) < 0 {
a.Add(a, b)
a, b = b, a
}
fmt.Println(a)
}
I can't say I'm particularly keen on having to read a.Cmp(&limit) < 0
instead of a < limit
The question is whether it's worth it to write code like this in order to prevent others from misusing operator overloading. I guess it may depend on how much math code you write and how disciplined your coworkers are.For your example, maybe so. But:
m = a * b * c + d * e + f
will be clearer than three Matrix_Multiply and two Matrix_Add calls. And one screen full of lines like mine will be far clearer than five screens full of Matrix_Add and Matrix_Multiply calls. invoice++
is not better than invoice.addToSystem()Also specifically for vectors and matrices for 3D graphics, i prefer to use float mtx[16], vec[3], etc instead of specifying custom types (then i can use the vec_foo calls with matrices with the proper offsets or the normal part of a float plane[4] which is encoded as normal+distance or use the vec_foo calls directly in a vertex buffer, etc).
That is certainly true.
But the language can have a big impact on the difficulty of getting the implementation correct.