2 ms·
Method chaining, while possible, isn’t something I’d say is really encouraged in Go. Returned values should be handled explicitly. There are plenty of cases whe
by robotastronaut 4y ago
Method chaining, while possible, isn’t something I’d say is really encouraged in Go. Returned values should be handled explicitly. There are plenty of cases where it could be fine, but if a function can error, you wouldn’t want to chain anyways.
- closeparen 4y agoYes, you would. “Chain all these methods and stop when you get to the first error” is an extremely common idiom. People write it all the time in lots of different languages. Go is unusual in that you have to spell it out.
- robotastronaut 4y agoRight, I know. You’re not wrong. I was meaning you wouldn’t want to do it in Go because it’s not idiomatic (and likely impossible as discussed). I use it all the time in other languages and don’t mind exception patterns, but method chaining feels very out of place when reading Go code.