3 ms·
> Look at almost any big Go project; the abundance of {}interface typed variables is alarming This statement seems weird to me, so I checked Camlistore (the b
by enneff 12y ago
> Look at almost any big Go project; the abundance of {}interface typed variables is alarming
This statement seems weird to me, so I checked Camlistore (the biggest Go project on my machine). In 65621 LoC there are 306 mentions of interface{}. And Brad does tend to do "clever" things that I probably wouldn't do, so I honestly expected the number to be a lot higher.
- wyager 12y ago>there are 306 mentions of {}interface Would you be happy with a Java project with 306 mentions of Object?
- enneff 12y agoI wouldn't be happy with a Java project with 306 mentions of anything. Go's interface{} and Java's Object not the same thing, nor are they used for the same ends. Eyeballing the Camlistore code I am not distressed by its use of interface{}. It's fine.
- wyager 12y ago>I wouldn't be happy with a Java project with 306 mentions of anything. Please expand on this. >Go's interface{} and Java's Object not the same thing, Yes, they are. They are both the top type. >nor are they used for the same ends. Yes, they are. Did you ever use Java before they added Generics?
- dsymonds 12y agoGo does not have type inheritance, so there's no such thing as "the top type".
- friendly_chap 12y agowyager is right, empty interfaces in Go are exactly that - a type (set) which every value is a member of, search for Go/interface{}: http://en.wikipedia.org/wiki/Top_type http://en.wikipedia.org/wiki/Top_type Edit: the downvoter cares to explain?
- overcyn 12y ago"However, several languages have types in the second regard above (e.g. void * in C++, id in Objective-C, interface{} in Go), static types whose variables can accept any object value, but which do not reflect real runtime types that an object can have in the type system, so are not top types in the first regard." Do you consider void* the same as Java's Object?
- coldtea 12y agoWell, the "all encompassing" type. Or the "variant" type.
- coldtea 12y ago306 mentions sound a lot.