-
Given I have the following struct:
I think the API for building should be something like: let builder = parser.struct_def("Foo").builder();
let object = builder
.set("bar", 42)
.set("baz", 43)
.set("qux", 44)
.build(); The question is what should happen if we don't set a field and try to build? It's sometimes a programming error, where panicing makes sense. Possibly there are cases where the programmer can't prevent it from failing (like building from a UI or from JSON)? That would make me want it as a Result, and just have most places unwrap it. We could also fill out all the unspecified fields with default values. Maybe the best option is 3 different build methods that each do one of the different approaches. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'm a fan of the Elixir & Ruby way of using a different method (usually ending with Thinking from the perspective of the data host, I would rather control my logic by checking if it errored, rather than implementing control flow through exceptions. I recognise the value of having a panic, though, as it removes any overhead code handling the return of an error. My take is then to have different |
Beta Was this translation helpful? Give feedback.
I'm a fan of the Elixir & Ruby way of using a different method (usually ending with
!
) to indicate it panics.Thinking from the perspective of the data host, I would rather control my logic by checking if it errored, rather than implementing control flow through exceptions.
I recognise the value of having a panic, though, as it removes any overhead code handling the return of an error. My take is then to have different
build
methods and suit the potential use cases.