3 ms·
Apologies in advance for the terse response—I’m in a hurry and on mobile. First of all, I’m not asserting that there isn’t a problem with Go. I’m asserting tha
by throwaway894345 5y ago
Apologies in advance for the terse response—I’m in a hurry and on mobile.
First of all, I’m not asserting that there isn’t a problem with Go. I’m asserting that its interfaces aren’t some three-state beast per the OP.
Secondly, you don’t see the problem with the Python code because you’re not comparing it like for like with Go code. The equivalent Go code would look like this: `var x interface{} = (*int)(nil)` which is at least as conspicuous as the Python example.
> I assigned `nil` to `x` and yet `x` is not nil.
No, you put a nil pointer into an interface, thus the interface is not nil. We have to understand the semantics of the language we’re programming in—it’s not fair to criticize Go because it’s interfaces aren’t my exactly Python variables. I think there’s probably some valid criticism against Go with respect to the error-prone nature of its interfaces, but I don’t think it’s that they lack Python variable semantics.
> Implicit conversions aren't unusual in programming but in Go they stand out a bit.
This isn’t an implicit conversion, we’re explicitly putting an int pointer value (nil in this case) into an explicitly-typed interface{} variable.