3 ms·
go generics are different from abstract classes. C++ requires you to think in advance about the kind of abstract operation your class provides, and if you are a
by ithkuil 14y ago
go generics are different from abstract classes.
C++ requires you to think in advance about the kind of abstract operation your class provides, and if you are adding "sort" operation later on, and you realize that in order to sort something you have to have the concept of ordering, you have to add it to all classes you want to be sortered.
Go allows you to create an interface and then to create implementations of this interface for any type that already exists.
Scala solves this problem by introducing implicit conversions, so it's core design is like C++/Java, but the net effect you get from that is like in golang.
- eropple 14y agoScala solves this problem better with structural typing, which is not that different from what Go does.
- blablabla123 14y agoYeah I totally agree, the Go interfaces are much more flexible than those of C++ or even Java. But please, don't call them "go generics", they are called "interfaces". ;-) http://golang.org/doc/go_faq.html#generics http://golang.org/doc/go_faq.html#generics
- joelthelion 14y agoGo doesn't have generics. It has cool interfaces, but they solve a different problem, and the lack of generics (or templates, if you prefer) is a real problem in Go.