On Monday, 3 February 2020 23:10:01 UTC, Jon Conradt wrote: > > While names arguments like foo(x= 1.0, y = 23) may look like syntactic > sugar, I think you are right that they improve readability, especially of > long argument lists. The counter argument I suppose if that you could pass > structs around, but that gets ugly fast. > > There are some open proposals which would make this less ugly: e.g. https://github.com/golang/go/issues/12854 https://github.com/golang/go/issues/35304
> Thinking about how this would be implemented in Go, I wonder if it would > be better for unnamed arguments (assuming they are allowed) to adopt the > default values, or whether the function definition should include default > values like Python. I find the default values in the function definition to > be hard to discover, but that is mostly because I find Python docs hard to > read. > I think the natural approach would be to default to zero values, just like structs do. In a similar vein, I observe that Protobuf v2 included the ability to specify default values for missing fields, but these were removed in Protobuf v3. Now all fields are optional, and all default to the zero value. Python-style kwargs have the advantage over passing a struct that you can mark some arguments as mandatory (checked at compile time). You could of course pass regular arguments followed by a struct of optional arguments, but that's rather messy. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/56557a43-d0d3-4487-a76f-cf890d25343c%40googlegroups.com.