Some time you want to have default values.
Sometimes you want to be relaxed about the order parameters are handed in.
Sometimes you just want to write readable code:
discount_rate() discount_rate(;risk_category = 'AA+', years = 3, amount=$3,000,000, starting_date=20190312, )
Of the two approaches available in Julia v1.x, each has drawbacks:
- Positional Arguments with default values:
- Extra function methods get defined automagically.
- They can get overwritten out of sight/silently, just as automagically.
- Result in a code base that is not understood (has behavior not covered by test cases while cov metrics might be green).
- Keyword arguments:
- Function methods don’t dispatch on keyword arguments.
- Result in dispatch behavior changing (issue #9489).
- Can also overwrite an existing default method silently.
Others have come this way before:
Using only Julia Base v1.x (i.e. not Parameters.jl):
What is the best practice or ‘habit’ to develop for using default values or writing readable code that will:
- preserve Julia’s performance
- avoid the other issues mentioned above
- likely cause the least pain between 1.0 and 2.0?
It might help to use an example(s) from the posts listed above.