3 ms·
I've arrived at the opinion that any use of reflect is a red flag that the author is trying to do something that Go wasn't designed to do and the code will prob
by marcus_holmes 6y ago
I've arrived at the opinion that any use of reflect is a red flag that the author is trying to do something that Go wasn't designed to do and the code will probably be extremely flaky.
It's not a 100% match, but it's a good heuristic in most cases.
As my experience with Go has increased, the number of times I need to touch reflect has decreased.
- christophilus 6y agoHow do you marshal/unmarshal JSON?
- nvarsj 6y agoYou write a custom marshal/unmarshal method for every type, of course.
- kstenerud 6y agoThat's what it does already. But you can't dynamically create a value of a decoded type without reflection, nor can you examine an arbitrary object for encoding without reflection.
- christophilus 6y agoWait. Is that what the built in utility does? I thought it was reflection based. How does it do this without generators?
- kstenerud 6y agoIt's a mix of cached builders and reflection. It uses reflection to build an appropriate builder object for that specific type. Note that it is still using reflection in the builder though.
- marcus_holmes 6y agoI wasn't really referring to the std lib. Though, to be honest, given the amount of hassles I've had marshaling and unmarshaling json in Go, I could well include it ;)