interface{} is basically stringly typed programming
-
-
interface{} is a joke. Probably one of the biggest things keeping me away from golang.
-
Don’t use it. I rarely have to (<1% of code). Also, what Go lacks in type system it makes up for in operational simplicity (deployment, tooling, ecosystem, performance, learning curve, etc) which are generally more important anyway.
-
So instead of type checked enum/variant for messages, well, they could be sending you ANYTHING. At that point its just C with green threads ;).
-
A couple important caveats: Go has interfaces and closures, so you're not reaching for `interface{}` nearly as soon as you would reach for `void*` in C. Secondly, Go interfaces (incl interface{}) have a type tag associated, so you can always do runtime checks, unlike void*.
-
You can always just wrap an interface{} in another type and protect against its use. But the point stands: exposing it is roughly the same as storing everything in a string.
-
Agreed; I was responding to the notion that the mere existence of the type should put people off of the language altogether. Type systems are helpful but people tend to exaggerate their importance.
-
More expressive type systems tend to yield important insights into solutions. I tend to lean toward them for this reason.
-
I agree in general. I didn't mean "expressive type systems are suboptimal"; I meant "expressive type systems don't compensate for impoverished tooling/ecosystem/documentation/etc". The only functional language that doesn't force this choice is Rust, but it forces other choices.
- 1 more reply
New conversation -
-
-
It’s so weird how you would react about that but not `interface{}` being painted as stringly-typed programming.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.