views:

149

answers:

1

Disclaimer: I've only played with GO for one day now, so there's a good chance I've missed a lot.

Does anybody know why there is no real support for generics/templates/whatsInAName in GO? So there is a generic map, but that's supplied by the compiler, while a GO programmer can't write her own implementation. With all the talk about making GO as orthogonal as possible, why can I USE a generic type but not CREATE a new one?

Especially when it comes to functional programming, there are lambdas, even closures, but with a static type system lacking generics, how do I write, well, generic higher order functions like filter(predicate, list)? OK, Linked lists and the like can be done with interface{} sacrificing type safety.

Sorry if this comes over like a random rant, but when compared with Scheme, to me GO looks less orthogonal, less simple, while providing about the same library functions (when including the more popular SRFIs) and speed.

As a quick search on SO / Google did not reveal any insights, it looks like generics, if at all, will be added to GO as an afterthought. I do trust Thompson to do way better than the Java guys, but why keep generics out? Or are they planned and just not implemented yet?

+7  A: 

Hi, this answer you will find here: http://golang.org/doc/go_faq.html#generics

Why does Go not have generic types?

Generics may well be added at some point. We don't feel an urgency for them, although we understand some programmers do.

Generics are convenient but they come at a cost in complexity in the type system and run-time. We haven't yet found a design that gives value proportionate to the complexity, although we continue to think about it. Meanwhile, Go's built-in maps and slices, plus the ability to use the empty interface to construct containers (with explicit unboxing) mean in many cases it is possible to write code that does what generics would enable, if less smoothly.

This remains an open issue.

Vinzenz