4 ms·
In practice I've not found anonymous structs too useful. You end up being very verbose and then discover you'd have been better off with a named type anyway. I
by XorNot 11y ago
In practice I've not found anonymous structs too useful. You end up being very verbose and then discover you'd have been better off with a named type anyway.
It'd be nice to have a shorthand which mixed the type definition and assignment into a single line so you could do something like:
S := { x int : 1, y int : 2 }
Or even
S:= { x := 1, y := 2 }
- PuerkitoBio 11y agoI use them extensively for test cases (`cases := []struct{...} { ... }`) as mentioned in the slides. Also sometimes to marshal/unmarshal one-off json or xml payloads.