fut
fut copied to clipboard
Field initializers don't work in C#
The following code translates to C# normally
NumericExpression# e = new NumericExpression { N=0 };
but it doesn't compile becouse field N is private.
I can create Init(double)
method, but it is confusing, especially when the class is public and may be used in other code.
Is there a real reason why there is no normal constructors in Fusion?
Thank you for your question! Error reporting is still the weak part of fut
, but it is slowly improving.
What is your language background?
Fusion is not a C# clone, but needs to balance several target languages. In particular, decisions that would make sense for C# output, are not necessarily good for other languages.
In C#, all objects are allocated on the heap. This is not what C or C++ programmers expect. To satisfy these targets, Fusion allows both heap allocations and in-place objects. This adds some complexity. Adding constructor parameters would add more complexity. Adding overloads (which C, JS and TS don't have) would add even more complexity. Are you aware of how many ways are there to initialize a variable in C++? There are even dedicated methods in std::vector
to support construction parameters, such as emplace_back
. C++ programmers would expect these, but generally programmers are either unaware of the complexity of C++ or scared by it.