Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Hardcoding more than once is error prone #66

Open
sadqiang opened this issue Dec 17, 2018 · 1 comment
Open

Suggestion: Hardcoding more than once is error prone #66

sadqiang opened this issue Dec 17, 2018 · 1 comment

Comments

@sadqiang
Copy link

sadqiang commented Dec 17, 2018

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.

@cdrnet
Copy link
Member

cdrnet commented Dec 18, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants