mathnet-symbolics icon indicating copy to clipboard operation
mathnet-symbolics copied to clipboard

Suggestion: Hardcoding more than once is error prone

Open sadqiang opened this issue 6 years ago • 1 comments

I think hardcoding "x" more than once should be avoided because it is error prone. It potentially causes runtime errors.

            var x = Expr.Variable("x");
            Func<double, double> f = (x * x + x - 6).Compile("x");
            Console.WriteLine(f(0));

My suggestion is as follows:

            var x = Expr.Variable("x");
            Func<double, double> f = (x * x + x - 6).Compile(x);
            Console.WriteLine(f(0));

Any comments are welcome. Thank you.

sadqiang avatar Dec 17 '18 13:12 sadqiang

It would also be more consistent with the rest of the API.

Technically, if we'd change the argument to expect a SymbolicExpression, the former notation with a string would still work due to the implicit cast from string to the expression. We'd need to verify it also works with the params array overload though.

cdrnet avatar Dec 18 '18 10:12 cdrnet