8 ms·
Any plans to add templates/a form of generic programming? Does the community care about that? How have people been working around that? And congrats! EDIT: Ye
by minamea 13y ago
Any plans to add templates/a form of generic programming? Does the community care about that? How have people been working around that?
And congrats!
EDIT: Yes I know what the faq says [1]. I was wondering if someone working on that can shed light on how the development of a satisfactory proposal has been going. Also, what's exactly wrong with template instantion like in C++ from the perspective of Go devs?
[1] http://golang.org/doc/faq#generics http://golang.org/doc/faq#generics
- cjh_ 13y agohttp://golang.org/doc/faq#generics http://golang.org/doc/faq#generics
- voidlogic 13y ago>>Any plans to add templates/a form of generic programming? The Go team is open to generics as soon as there is a proposal they feel fits right without performance penalties. Read: http://golang.org/doc/faq#generics http://golang.org/doc/faq#generics >>Does the community care about that? Yes, but most people in the Go community are OK waiting for the "right" solution. >>How have people been working around that? Generics are nice and convenient, but you can write anything/everything without generics. Just look at everything written in C. And C doesn't have interfaces like Go.
- coldtea 13y ago>The Go team is open to generics as soon as there is a proposal they feel fits right without performance penalties. Because using interface{} for the same tasks fits so much better and has so much better performance right? Tons of languages have implemented Generics -- it's not rocket science since at least 2 decades. If the Go team is not interesting in working on the thing, then I doubt they would be really evaluating any "proposal".
- voidlogic 13y agoI think Generics are just low priority for the Go team. Maybe we will see them in Go 2.0 >>tons of languages have implemented Generics -- it's not rocket science since at least 2 decades. Sure, but that doesn't mean there are not concerns about the way it is often implemented: http://research.swtch.com/generic http://research.swtch.com/generic
- jff 13y agoIt gets brought up continually on the mailing list. The Go authors have repeatedly stated that they will not be implementing generics. They don't seem to miss them, I don't miss them, and indeed most people who write much Go don't seem to miss them. The people who continually whine about generics seem to be the type who say, "Oh boy, I'd sure LOVE to write a bunch of kickass code in Go, but I just couldn't do ANYTHING without generics! Why don't you put them in, then I'll try the tutorial" It's not something we feel the need to work around, we just sit down and write concise programs that do the job, in fewer lines than C++. Edit: as others have mentioned, it seems the authors would be willing to put them in if they find a way to do it without crapping up the language. If they do, I'll try writing Go code with generics, but they have a bad taste for me after dealing with code containing GenericType.cpp, GenericType.hpp, AbstractType.cpp, AbstractType.hpp, AbstractGenericType.cpp, and AbstractGenericType.hpp all in one place.
- enneff 13y ago> The Go authors have repeatedly stated that they will not be implementing generics. That's not true. We just don't have a way of doing them that works well in the language. http://golang.org/doc/faq#generics http://golang.org/doc/faq#generics
- voidlogic 13y ago>>The Go authors have repeatedly stated that they will not be implementing generics. Not so http://golang.org/doc/faq#generics http://golang.org/doc/faq#generics; "This remains an open issue." In the discussions I have read, if an implementation of generics is proposed that doesn't sacrifice performance and it truly generic, they are open to it. What I have seen said is that implementing generics was not on the table for 1.1 or maybe even 1.x
- stonemetal 13y agoI haven't looked at go beyond doing the tutorial, so what follows isn't a learned opinion. The interface system in Go covers most of what you would do with generics, if you use interfaces your code is generic. The only friction over a generics implementation is the way you wire up types to interfaces.
- minamea 13y agoSomeone correct me if I'm wrong, but I think that's true only if you use methods and not operators, because Go doesn't support operator overloading.
- 4ad 13y agoThat's correct, which means stonemetal's comment is true only for non-math code, but 99% of the code out there is not math.
- stonemetal 13y agoThe other place you really feel the lack of generics is in the collections. They are built around the empty interface so that they can hold any type. Then you have to cast back to what you want. Exactly like Java pre generics. ugh.