3 ms·
> Instead of named arguments, use the functional optional pattern. Options pattern is an alternative, I use it frequently, but still miss named arguments and d
by xyse53 2y ago
> Instead of named arguments, use the functional optional pattern.
Options pattern is an alternative, I use it frequently, but still miss named arguments and default arguments if I'm going back and forth with Python.
- The options pattern is much more verbose to implement.
- The defaults aren't as easily clear, they need to be documented and kept consistent.
- You can't, or it's not as easy to, make some arguments required.
- And, as a caller, if the API I'm using doesn't support them, I sometimes have to rely on comments to clarify what each arg is. For example, if a function takes a bools like `func MyFunc(dryrun, inverse bool, items ...string) error { ... }`
- mariusor 2y agoAlso the functional options pattern usually implies that there is an object on which the functions operate. Default values for parameters is something that can apply to any function, not just initializers. I wonder if parent could give us an alternative for strings.Replace using functional options.