4 ms·
Go developers came up with this pattern to deal with the language's limitations. Go's core team would probably advocate for a mutable configuration struct with
by mixedCase 4y ago
Go developers came up with this pattern to deal with the language's limitations. Go's core team would probably advocate for a mutable configuration struct with a magical interpretation of zero values, and/or a constructor-by-convention and advise users to "just not make mistakes".
If we had non-zero default values or named arguments, this pattern wouldn't exist.
- tptacek 4y agoThere would still be reasons to have configuration structs if we had named arguments.
- skrtskrt 4y agoAs a former Python dev, default arguments are nice but they get abused to hell. Need to add functionality to something? Don't think! Just add an argument with a default to the current behavior, all the way up and down the stack. Now you have just one API that does everything! Just set 20-40 parameters to decide the behavior.
- codedokode 4y agoPython just gives you a choice, use named arguments or refactor your API and use objects for options. It is up to you how you are going to use it. What I don't like though is when all those options are hidden behind two-stars keyword argument and it is difficult to understand what options are allowed, what they mean, what type they have and so on: def example(**options): ...