Make C# maths stuff look like maths #9553
Replies: 3 comments 2 replies
-
The symbolic language used for math itself is ... not so consistent. Different advanced areas define different simplified forms, which may not be always compatible or distinguishable.
I'm also a non-English speaker. In my view, the "fluent" English words are quite not readable. However, I do consider the OOP syntax with operators are readable. It's clear about what operations to do, or what semantic to achieve.
The C#-ish expression is global using static GlobalConstants;
public static class GlobalConstants
{
public const double π = Math.PI;
}
This requires custom prefix-operator support (#3172). But in real world, people will definitely define helper functions for common operations like Laplace Operator. The delegate-oriented form in the example won't be used in real-world, because it would be much worse than SIMD-optimized operators.
The story is different in handwriting/printing and computer typing. In computer we tend to make names longer because the tooling can fill the name. With (extended) Hungarian naming convention, it becomes |
Beta Was this translation helpful? Give feedback.
-
<irony>I actually find this more readable. 😀 In my eyes, mathematicians are like programmers with poor coding standards. They tend to use non-descriptive ultra short variable and constant names, preferably single letters. If they run out letters, they start to use the Greek/Hebrew/gothic alphabet or accents/strokes rather than starting to use descriptive variable names. 😂</irony> |
Beta Was this translation helpful? Give feedback.
-
When I see |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello fellow coders,
since this is my very first language proposal, please be patient and kind. By the way, I guess my C# language skills may be better than my English language skills... :-)
Still, am I the only one who's suffering from a lack of freedom in naming fields and operators? The best thing regarding code within the last few days was finding out that greek letters are perfectly valid variable names, thanks to copilot, yessss!
Now, greedy as I am, look at a line of code (written in a fluent'ish style for a reason) like:
if (alpha.isIn.Range.From(0).Inclusive.To(Math.Pi).Exclusive ...
Compare to:
if (α ∈ [0 .. π[) ...
Imagine a library's method like MyMathLib.Gradient(MyMathLib.ParametricVector<Func<T, T>, Func<T, T>, Func<T, T>>). The issue that the shipped libs seem to lack such a type (a parametric vector) doesn't matter at the moment. Instead, imagine:
var v = new ParametricVector<double>(Math.Sin, Math.Cos, t => t);
and then:
var r = ∇v;
I know, this is like opening Pandora's Box because... Shouldn't vectors be decorated with a harpoon, or set in italics or in bolds? What about indices?
Perhaps I am the only one who'd love to see such possibilities, but think of code in the AI context where maths are getting more and more complex, and the domain's topics are moving from coders to (also) mathematicians.
Beta Was this translation helpful? Give feedback.
All reactions