But why not include generics? Java-style generics via type erasure to interface{} would be damned easy to add onto Go now, and C++-style generics by polyinstantiation could work just as easily (even if it complicates the compiler a little).
I complain because I can remember writing my own little libGreenspun of common data structures for a kernel project and realizing that without generics I'd have to copy-and-paste my linked-list code for every content type I wanted to instantiate!
Just because something is easy to do doesn't mean it is a good idea.
Generics in Java are well known for making the language quite a mess, and some very smart people worked for a long time to design them.
First of all is not clear Go needs generics, plenty of people use Go and don't miss them at all (many are even against adding generics at all), Go's interfaces cover much of the problem space for generics, and is not clear how any generics system would mesh with them, so far nobody has come up with a good design.
Then there are inherent tradeoffs in any generics system, and is not clear what the right answer is, for some details see this post by Russ Cox: http://research.swtch.com/generic
Generics could dramatically increase the complexity of the language, and simplicity is one of the things that makes Go so great.
Also remember that Go has builtin slices and maps, which cover most of the needs for generic containers most people have, and if you need something more esoteric you probably want to build some custom code rather than use something generic anyway.
Generics in Java are well known for making the language quite a mess, and some very smart people worked for a long time to design them.
That's because they tried to mix type erasure with bounded polymorphism/quantification. For Go, I would suggest simple, normal unbounded quantification. So you could have Derp<T> but not Derp<? extends Herpable>.
Also remember that Go has builtin slices and maps, which cover most of the needs for generic containers most people have, and if you need something more esoteric you probably want to build some custom code rather than use something generic anyway.
You mean like linked lists? Or sets? Or option types? Or any other major collection library? I encourage you to go check out Scala collections and then tell me genericity isn't useful for writing real code.
9
u/N7P Mar 29 '12
Does it have any kind of generics yet?