Introduction
As a developer, I participate in writing a lot of mathematical code every day, and I would like to add very little syntactic sugar to C # to make writing and viewing code easier.
I have already read about this thread and this other one for possible solutions and just wanted to know what is the best direction and what efforts he can solve to solve only the following three syntax problems *.
*: I can survive without the syntactic sugars described, but if this is not too much work and Roubaix-Goldberg design for a simple compilation process, it may be interesting to explore further.
1. Several output arguments
I would like to write:
[double x, int i] = foo(z);
Instead:
double x; int i; foo(out x, out i, z);
NB: out parameters are placed first, and foo declared as usual (or the same syntax is used).
2. Additional operators
I would like to have some new unary / binary operators. I don’t know how to determine for them (and this seems rather complicated in order not to introduce ambiguity in the analysis of sources), in any case I would like to have something like:
namespace Foo { using binary operator "\" as "MyMath.LeftDivide"; using unary operator "'" as "MyMath.ConjugateTranspose"; public class Test { public void Example() { var y = x'; var z = x \ y; } } }
Instead:
namespace Foo { public class Test { public void Example() { var y = MyMath.ConjugateTranspose(x); var z = MyMath.LeftDivide(x, y); } } }
3. Automatic name insertion for static classes
It is extremely unattractive to endlessly repeat Math .BlaBlaBla () everywhere in the computational code instead of writing directly and simply BlaBlaBla.
Of course, this can be solved by adding local methods for transferring Math .BlaBlaBla inside the calculation class. In any case, it would be better if there was no ambiguity at all, or when the ambiguity was resolved using some implicit keyword, to automatically insert class names if necessary.
For example:
using System; using implicit MySystem; // Definying for 'MyMaths.Math.Bessel' public class Example { public Foo() { var y = 3.0 * Cos(12.0); var z = 3.0 * Bessel(42); } // Local definition of 'Bessel' function again public static double Bessel(double x) { ... } }
It would be:
using System; using MySystem; // Definying for 'Math.Bessel' public class Example { public Foo() { var y = 3.0 * System.Math.Cos(12.0); // No ambiguity at all var z = 3.0 * MySystem.Math.Bessel(42); // Solved from `implicit` keyword } // Local definition of 'Bessel' function again public static double Bessel(double x) { ... } }
* The compiler can simply generate a warning to indicate that it resolved the ambiguity, since an implicit solution was defined.
NB: 3) satisfies enough for solution 2).