-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bring Formatters and their options closer together #124
Comments
Ok, just throwing out all the options I can think of here. Maybe they can serve as further inspiration for something, or maybe they're just bad ideas. Couldn't hurt to mention them, though. A map!We could use a map with either functions or module as the key, and then the values could be a kwlist of configuration options. So, something like this: formatters: %{
HTML => [file: "file.html", awesome: true],
&CSV.output/2 => [file: "file.csv"]
fn(suite) -> Mod.thing_to_do(suite) end => []
} Pros
Cons
Configurable Formatter Structs/maps!I found myself kind of wishing for some state here, since that's the issue we're having - keeping relevant state together. How about if we could do something like the following: html = Benchee.Formatters.HTML.new
|> Benchee.Formatters.HTML.output_file("file.html")
|> Benchee.Formatters.HTML.awesome(true)
user_formatter = %{
function: fn(suite, options) -> do_a_thing(suite, options) end
}
formatters: [html, Benchee.Formatters.CSV.new, user_formatter] We could ensure that the map/struct that we got has a key for pros
cons
Other thoughtsFor some reason, the anonymous function/closure idea seems really odd to me. As a new user that would seem weird to me. The thing that kind of irks me about the tuple example are all the various different types of things in that list. The typespec for that list is basically I think that it might make sense to tackle #53 first so we can at least remove those functions from the conversation and only deal with modules. Assuming that's done, how about this sort of structure: formatters: [
{HTML, file: "file.html", awesome: true},
CSV,
UserDefinedModule
] That way the only things that we accept are In general, I think the list of modules or tuples will probably be best, but maybe you have some good ideas after seeing my rough ideas above! |
👋 Thanks for the input 😁 I'm sort of enthralled by the "OOP" idea, didn't think of that, it's pretty neat imo but might also be the OOP speaking ;P I think in the end the list with tuple/no tuple might be best indeed. Although, while the typespec variations get bigger I wanna keep functions in there at least for now. I don't want to have a breaking change if I can avoid it and elixir pattern matching/basic type checks have often provided for a relatively easy way to support these. Depending on how that shapes up I think we might or might not deprecate pure functions in 1.0 (or 0.99 or whenever). I sort of like the idea though that people can just pass in a simple function and do whatever they want with the final suite without implementing a whole module :) |
Trying to tackle this now with our tuple variant |
Right now, there is a disconnect between defining the formatters and their respective arguments/configuration options. Formatters are defined in a list as
formatters: [&function1, &function2]
while their eventual arguments end up informatter_options: [namespace: [actual: "option"]]
. I define the formatters in one place, but I configure them in another. This seems suboptimal to me.Possible solution
( I am very open to other suggestions, this is the "best" I came up with by myself so far)
The tuple
Instead of just a function (or a module ideally after #53) allow a tuple of a function/module and options. When calling the formatters the options are passed as a second argument after the suite.
If implemented, formatter_options should still work (for now and potentially the future if not too hard to handle).
Fun question would be that if
formatter_options
are kept around, how to deal with conflicting values in those/merging. Easy options are when "local" options are supplied formatter_options are ignored, or they are merged with a preference for local.The option scope captured in a function
Basically needs the API adjustment in the formatters as well, but people could also do this then:
Feedback gladly welcome, before I go off an implement the wrong thing :D
The text was updated successfully, but these errors were encountered: