3 ms·
You can distinguish between nulls which are errors and nulls that are just the actual return value. That is what err is for. The entire reason Go has multiple
by merijnv 15y ago
You can distinguish between nulls which are errors and nulls that are just the actual return value. That is what err is for.
The entire reason Go has multiple return values for functions (such as paths and err in this case) is to avoid having to encode errors in the "real" function result.
Now I agree, that this is less nice as say pattern matching and real sum types, but if you know how to appreciate those just switch to a functional language!
- masklinn 15y ago> The entire reason Go has multiple return values for functions (such as paths and err in this case) is to avoid having to encode errors in the "real" function result. That's nonsense, MRVs are tuples (conceptually, Go implemented them with special syntax because... well, it's Go so it could not go with the general principle now could it?), so Go very specifically encodes errors in the function result. And using a sum type would encode the error in the type, not in the result itself.
- 4ad 15y agoMultiple return values are not tuples, Go doesn't have tuples in the type system.
- masklinn 15y ago> Multiple return values are not tuples Multiple return values are a special case of tuples. Hence the "conceptually" part. > Go doesn't have tuples in the type system. Could you explain how you managed to completely miss the part where I say exactly that?