-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
I know operator overloading is considered out of Zig scope.
But no issue seems to make the following case so here it is.
Operator overloading matter in scientific computing
Consider writing polynomial addition with function
p = 2*x*y + 3*z + 5y - 8*x;
assume x, y and z are some other complex polynomials.
With functions, this becomes
p = sub(add(add(mul(2, mul(x,y)), mul(3,z)), mul(5,y)), mul(8,y))
Is the intent clear in the previous line?
Isn't forcing the previous line on user breaking Zig simplicity principles?
Zig promises to make scientific computing easier and fun
When writing numerical code in C++, memory leak is a pain.
With Zig focus on no 'undefined behavior', writing fast numerical can be made much easier.
C++ is currently a big entry barrier in high performance numerical computing.
Why 'printf' and not '+'
Zig brings a new paradigm where function previously hidden in the compiler internal are now in userland.
Why limit this paradigm to standard function call?
Zig offers an all encompassing approach that offers a build system and a package manager.
There are many domain where operator overloading is crucial.
For example, in Fortran '+' is overloaded in the compiler to support vector addition.
If Zig doesn't offer operator overloading, users will either:
- write some complex preprocessor to get it,
- stick with C++.
These two solutions break many Zig principles.