3 ms·
Maybe/Option/Result types don't work without generics, because you significantly reduce the type checking.
by richardwhiuk 10y ago
Maybe/Option/Result types don't work without generics, because you significantly reduce the type checking.
- stouset 10y agoAnd this is why people have been begging the golang developers to add generics practically since it was conceived. Yes, generics make compiler-writers' lives more difficult. But they can dramatically simplify the lives of everyone else.
- saghm 10y agoI'm not a Go programmer, but from what I understand, things like Go's map implementation in the standard library are usable as if they're generic. Couldn't they add a few more types like this (e.g. Option and Result) in the same way without exposing generics as a language feature?
- jimsmart 10y agoI program some Go - I believe you are talking about the 'empty interface', e.g. map[string]interface{} The problem with that is that you instantly lose compile-time type checking, and have to check/assert the types yourself at runtime after accessing the map. In a strongly-typed language this kinda goes against the grain, and is a PITA. (Although it still can be useful at times). My 2p.
- sbov 10y agoThe point is that a map can be type safe because it's built into the language, and that the designers could do exactly the same with a maybe/option/result feature.
- kasey_junk 10y agoYou are absolutely correct. Go has generics. It just doesn't have user defined ones. If the language designers thought an Option/Result/Try was valuable they could add it. Just like they could add Futures/Promises and concurrent safe maps if they wanted to.