Dysfunctional Options Pattern in Go
rednafi.com
rednafi.com
To solve this problem, a language have to disallow null/nil as a bottom type and provide nice syntax to initialize types with optional types.
[1]: https://geeklaunch.io/blog/make-invalid-states-unrepresentab...
Languages with both of these features like Python don't end up using the builder pattern or reinventing it like this author.
NewObject(
required1,
required2,
&ObjectOptions{
Option1: “foo”,
// Option2 skipped
Option3: “bar”,
})
I can see the merits of both (two structs is tedious, for sure), but I wanted to share in case others had thoughts or alternate ideas! func (c *Config) WithFizz(...) {...}
func (c *Config) WithBazz(...) {...}If you don't need the composition, you can just add the methods as above and call it a day.