I am a bit unhappy with how I currently document keyword arguments in functions that I consider a bit more high-level.
Such a function should be usable easily also for people using a package for the first time.
Similar to example plots, my functions often come with several keyword arguments.
With this topic I would like to shortly document my current way of writing documentation for keywords, but ask for feedback and other ideas, see also questions at the end, to get an overview of other approaches as well.
Background / Artificial Example
Currently I do the following â illustrated on an artificial example in a doc string
c = fun_name(a; kwargs... )
c = fun_name(a, b; kwargs... )
fun_name!(c, a, b; kwargs...)
This is a function that does this and that. It explains the function in a few â or a few more lines.
# Input
* `a` is the first parameter and explained here
* `b` is the second parameter and optional, defaults to a random call
# Keyword arguments
* `keyword_one` : (`"default"`) does something
* `another_keyword` : (`200`) does something else
all further keywords are passed to the inner call of `second_function`.
# Output
thins function computes and returns `c`.
So I usually also try to mention the in-place variant here as well, the in-place itself will have a shorter documentation, mainly referring to the one above.
Pros & Cons
What I do like on this form is that all function signatures are in a good few lines.
In REPL the above string even prints relatively nice, the spaces before the :
and default values, align everything nice and give a good overview.
But for example in the docs the multiple spaces are of course (in HTML) shortened to one. That usually looks a bit crowded. See the above markdown rendered in the following
keyword_one
: ("default"
) does somethinganother_keyword
: (200
) does something else
This gets a bit crowded for a reasonable amount of keywords. I was thinking maybe about a 3-column table, but have not yet tried this would render nice in REPL and HTML.
Concrete Example
Besides a missing kwargs...
an example is Trust-Regions Solver ¡ Manopt.jl
where the doc string itself is Manopt.jl/src/solvers/trust_regions.jl at 342004e69427cfc859fe0ae0d32c4689db0ddee2 ¡ JuliaManifolds/Manopt.jl ¡ GitHub
Questions
- How do you usually document keyword arguments?
- How do you usually document default values of the keyword arguments?
- Is there maybe an even better way to document when passing on the remaining keywords to another function?