Currently in many places the API looks like:
foo {
param1 = 2
param2 = "hello"
...
}
For example:
xaxis {
name = "x axis name"
mode = Mode.lines
}
The api would be easier to use if it was in this form:
xaxis = Axis(
title = "sin"
type= Type.`-`
)
There are a couple of upsides to this:
- By looking at the function signature of
xaxis{} you don't know what kind of configuration is available. Sometimes the available variables are not even in the same file as the builder.
When having Axis() accept the parameters directly, they are available immediately in the call site with their default values, and will be shown by IntelliJ when you type the constructor.
- With named parameters IntelliJ will nicely autocomplete all of the available parameters, unlike when using lambdas.
- Having a function body implies you can do something other than assign variables, which is not true in many cases.
- Calling the constructor of
Foo is the natural way to create an object of type Foo, instead of some Foo.build{} function.
Places where passing parameters in receiver lambdas is still appropriate:
- When additional function calls are nested, like
plot in Plotly.Page{} (title should still be a named parameter though), or trace in plot.
@altavir If you agree I would like to submit a PR to start improving the API in this direction.
Currently in many places the API looks like:
For example:
The api would be easier to use if it was in this form:
There are a couple of upsides to this:
xaxis{}you don't know what kind of configuration is available. Sometimes the available variables are not even in the same file as the builder.When having
Axis()accept the parameters directly, they are available immediately in the call site with their default values, and will be shown by IntelliJ when you type the constructor.Foois the natural way to create an object of typeFoo, instead of someFoo.build{}function.Places where passing parameters in receiver lambdas is still appropriate:
plotinPlotly.Page{}(titleshould still be a named parameter though), ortraceinplot.@altavir If you agree I would like to submit a PR to start improving the API in this direction.