|
|
|
|
|
by discoursism
3024 days ago
|
|
My biggest object to the functional options argument is the step where NewServer(..., Config{})
is considered bad for some reason. As far as I can tell, the entire purported utility of the thing is based on avoiding this obvious approach. |
|
It means that sometimes you'll have to use dummy values (-1 for "no value", for example) or pointers (nil means optional). It means that any boolean has to be phrased in such a way that false is the default (so if it feels natural to call the option UseKeychain and it should default to true, you have to invert it and call it DontUseKeychain).
Config structs also means it's easier for a caller to construct invalid configs:
The semantics cannot be guaranteed by the type system, so won't be caught until runtime. Neither will this, of course: ...but in this case we can quite sensibly mandate that the following option overrides the previous one, flipping the internal switch over to the setting you specify. With the Config struct, there's no way for pipelines.New() to know which one should have precedence.(In this particular case, you can work around it by having a single Output field that uses an interface, but there are other situations where mutually incompatible fields can occur.)