You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing a function that sends a lot of keyword arguments to another function, say sending keyword arguments to a differential equation solver, use a named tuple keyword argument instead of splatting the keyword arguments. For example, use diffeq_solver_kwargs = (; abstol=1e-6, reltol=1e-6,) as the API and use solve(prob, alg; diffeq_solver_kwargs...) instead of splatting all keyword arguments.
In my understanding of terminology, ... is the splatting operator and I would say that ; diffeq_solver_kwargs... is splatting the keyword arguments, but as that doesn't make sense here I assume something else is meant by splatting. Could this be clarified?
The text was updated successfully, but these errors were encountered:
I mean "full splats". For example, if you're someone writing a code do_analysis(x,y;my_kwarg = 2, kwargs...), and then you just do sol = solve(prob::LinearProblem,alg,kwargs...); sol = solve(prob::NonlinearProblem,alg,kwargs...) in your package, because SciML has common keyword arguments this thing can work but it can confuse the keyword arguments, or easily pass extra keyword arguments. The better thing to do would be to have in the API some do_analysis(x,y;my_kwarg = 2, linear_solve_kwargs = (;), nonlinear_solve_kwargs = (;)) and then do sol = solve(prob::LinearProblem,alg,linear_solve_kwargs ...); sol = solve(prob::NonlinearProblem,alg,nonlinear_solve_kwargs...) in your package so that you can distinguish between the keyword arguments and make sure kwargs don't overlap. If you just have a bunch of kwargs being splatted around, it can be easy for them to mix, accidentally accumulate kwargs which have undefined or no meaning (with no warnings/errors thrown when someone makes a typo), and ultimately just hidden bugs.
I'm confused by this advice:
In my understanding of terminology,
...
is the splatting operator and I would say that; diffeq_solver_kwargs...
is splatting the keyword arguments, but as that doesn't make sense here I assume something else is meant by splatting. Could this be clarified?The text was updated successfully, but these errors were encountered: