-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
featureNew feature or requestNew feature or requestwontfixThis will not be worked onThis will not be worked on
Description
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 havingAxis()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
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:
- When additional function calls are nested, like
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.
Metadata
Metadata
Assignees
Labels
featureNew feature or requestNew feature or requestwontfixThis will not be worked onThis will not be worked on