3 ms·
are you saying you’re against the functional options approach? can you provide an example of a testing difficulty you’ve had?
by jonahx 7y ago
are you saying you’re against the functional options approach?
can you provide an example of a testing difficulty you’ve had?
- Groxx 7y agoI mean that this: func MyOption(arg int) Option { return myoption(func(opts type) { opts.thing = arg }) } will result in this: MyOption(5) == MyOption(5) // false Which makes it a pain in 1) testing, since you can't see the options that were passed, and 2) middleware, since you can't see the options that were passed, to validate or extend them safely. And 3) debuggers or Printf since you can't see the value in the closure until it's executed. Instead do: type myOption int func MyOption(arg int) Option { return myOption(arg) } since it has none of those problems. Whether you use the "loop and opt.apply(arg)" pattern or not doesn't really matter - that's a purely internal detail (personally I find it over-simplifies things and causes problems). Just "avoid passing values through func closures".