Why on Earth should a user of a high-level language have to care about language implementation details?
> What the actual fuck ???
Exactly.
Okay, but what was the rationale for designing the language like that?
When a nil value is converted to an interface, it carries type information. When an interface carries type information, it isn't nil.
Just because a language supports exceptions does not mean you always have to use them. You can always use a helper function to catch any error and return it as a value.
You could argue that Go can use Exceptions in the same manner as X lang too, by using panic and recover... but most people seem to not like that.
With Go and Rust, return value error handling is just simply nice. There's no question about if a function might error out, just look at the signature.
This would not be "replicating" anything, exceptions already are values in most languages. The only thing to do is wrap your call with a function, like "err = catch-all(expr)".
> ou could argue that Go can use Exceptions in the same manner as X lang too, by using panic and recover...
Except that it would be cumbersome ;-) because panic/recover works only in combination with defer[0].
> With Go and Rust, return value error handling is just simply nice.
Using non-exceptional control flow for errors can be useful depending on the circumstances. Using exceptions is simply nice in many other cases.
> There's no question about if a function might error out, just look at the signature.
Just look at the documentation. Code defensively.
var m map[T]T
you're basically writing var m *runtime.hmap
which is a nil pointer. Go has sane zero values, so it makes sense that reading from a nil map returns the zero value for whatever type its values are.However, there's a trade-off: either Go's maps allow nil assignment (in a similar fashion to slice's `append') _or_ it retains its "reference" (forgive me for using that term) semantics.
Go's designers decided that maps should differ from slices in that regard, and I tend to agree. I think it'd be a mistake to have to always return a map _just_ in it's newly allocated.
A man orders coffee in a restaurant.
"Would you like it with or without cream?"
"Without"
A few minutes later the waiter returns.
"I'm sorry sir, we've run out of cream. Would you like it without milk instead?"
[1] github.com/joeshaw/multierror