Reputation: 2697
I'm writing a function that currently has already got 31 keyword parameters. Example:
function myfunc(a::Int, b::Real, c::String;
msize=12,
mcolor="black",
mtext="text",
mwidth="regular",
... and many more
)
One good thing about this is that you can just call the function with the few values you want to adjust, and you don't have to define and/or maintain things like Dictionaries beforehand. And they can be supplied in any order. So the UX is good. But...
Is this the best way to handle many default parameters? And am I going to get problems if I go higher?
Upvotes: 1
Views: 75
Reputation: 104
You can create a class or type (in julia) with those parameters as fields and pass that class as a parameter to myfunc
. You can set default values to these fields so you don't need to set it all the time. This will be better in terms of maintainability and readability.
Upvotes: 5