top | item 7086655

What Go Might Be Like With Generics

39 points| sentiental | 12 years ago |play.golang.org | reply

48 comments

order
[+] Sir_Cmpwn|12 years ago|reply
Is the only argument that Go users can come up with against generics is that they don't like the syntax? The pretentious nature of the Go community really puts me off from the language, especially when combined with some of the pretentious designs of Go itself.
[+] vectorpush|12 years ago|reply
The pretentious nature of the Go community really puts me off from the language

I have had the exact opposite experience with the Go community. In particular, I've found community hubs like #go-nuts and the mailing list to be professional at worst and friendly at best, and always helpful.

some of the pretentious designs of Go itself.

How can a design be pretentious? Either you favor the design or you don't, but calling it pretentious is simply projecting your own emotions onto the language.

[+] skybrian|12 years ago|reply
No, the argument is that it's unclear how to fit it into the language.

Typically, generics are implemented using either code generation (causing code bloat) or type erasure (which requires boxing the type). They're not satisfied with either.

[+] marcus_holmes|12 years ago|reply
Is the only argument that Go users can come up with against generics is that they don't like the syntax?

Surely that's the best argument?

[+] f2f|12 years ago|reply
is this trying to solve a particular problem or just pandering to the "... but generics!" crowd of trolls?

because it doesn't look like it's solving anything, it feels positively ugly, and there's no way we'll every shut those people up no matter how hard we try. there's no generics solution that will do that.

thankfully go's authors don't usually favour the internet's opinion on these matters, or we'd be dealing with something even uglier now.

[+] girvo|12 years ago|reply
People who want generics, to solve real problems, in Go are trolls?

Gosh that word has lost all meaning at this point.

[+] rollo|12 years ago|reply
Eventually those who need static typing and parametric polymorphism will switch to Haskell anyway, where both are done in a much better way, both syntactically and implementation wise.
[+] bvaldivielso|12 years ago|reply
It is undeniable that generics are a quite demanded feature for golang.

We'll see how the language evolves, but I can't see them coming for a "long" time.

[+] MetaCosm|12 years ago|reply
I fully support language specialization -- that is kinda the point, it all ends up bits in the end. Rust is a completely different animal than Go yet I think both are awesome!

The idea that all languages have to cater to all people is silly. Generics are ALWAYS a trade-off. None is hard for developers, C++ style is terrible for compile (tons of code-gen, macro crap, duplication, de-duplication stages), and Java style (box-box-box-box) is slow at runtime.

The misunderstanding that generics are free and there lack of inclusion was an oversight rather than a choice is misguided. The Go team aren't fresh faced neophytes, they move with purpose.

Additionally -- if you want lots of features, there are LOTS of ways great languages for you! Leave the small, crazy cadre of people who don't mind C, think Lua is awesome and think Go is great to their (own) devices, we will be OK.

[+] chimeracoder|12 years ago|reply
I have been writing Go daily at work for about a year and a half. It is now my primary language, and my default choice for any new projects, the way Python used to be. Before that, I come from a background in functional programming (and still find functional programming to be my favorite paradigm).

It seems to me that there are two disjoint sets of people: those who write Go regularly, and those who complain about generics in Go.

Of course, you can interpret this either way you wish!

1) Perhaps those latter people would like Go despite its lack of generics if they only bothered to get familiar with idiomatic Go.

2) Perhaps the lack of generics is precisely what prevents them from writing Go on a daily basis.

But as someone who actually does write Go on a daily basis, and has for a year and a half, I can honestly say that I've only ever missed them a handful of times. And I say this as a functional programmer who is used to being able to call "map" everywhere.

In fact, if I had to prioritize the things that I wish I could change about Go, generics would not be in the top three - not even in the top five[0]. They're just really something that I don't miss anymore.

[0] I could tell you what they are, but that'd be making it too easy - give Go a shot, long enough to realize you really don't need generics as much as you think you do, and then you'll probably have a good idea of the good, bad, and ugly when it comes to Go.

[+] ekidd|12 years ago|reply
I've written several non-trivial Go programs, the most recent of which was a server that solved substitution ciphers (for use in subtitle OCR).

I tried to write nice idiomatic Go code. And I'm usually pretty good at adapting my brain to strange languages—I've positively enjoyed Haskell, constraint programming in Mozart, distributed functional programming in Elixir, and quite a few other strange things. (To be fair, I never did get comfortable in Prolog.)

And try as I might, every time I write a couple thousand lines of Go, I walk away in frustration. I love so much about the language, but my actual code keeps disappearing under the weight of error handlers, and stupid little iteration/transformation functions that I have to write over and over again thanks to the lack of generics. (Sometimes I get lucky, and an interface fits well.)

This means that every time I wander down a wrong path (and it's possible to wander down quite a few when messing with OCR algorithms), I end up having to tear up more code than I'd like. It's not fun.

Every time I say this, Go programmers say something like, give Go a shot, long enough to realize you really don't need generics as much as you think you do. But after three serious attempts, it's clear that the programs in my head were never meant to be implemented in Go. Which is too bad: It's a nice language in so many ways.

[+] burntsushi|12 years ago|reply
Just wanted to chime in and affirm your experience. I also love functional programming and have used Haskell for several projects (and will continue to do so). But I also use and love Go.

Like you, I've bumped up against areas where some form of generics beyond structural subtyping would have helped me solve a problem more elegantly. But it's never been a huge issue.

I think the primary reason why I'm drawn to Go is that I perceive it to be incredibly simple (like, Lua simple). Not just the language design, but the entire ecosystem---from idioms to tooling.

[+] MetaCosm|12 years ago|reply
Agreed (Gopher 1+ years)! My heart still leans towards Erlang, but Go is my current daily driver. The vicious pragmatism at every turn is whats keeps me (and the team) loving it.

It isn't the most elegant, not even close. It isn't the most succinct, not even in the running. It isn't the most flexible -- people would mock you for claiming it is. It isn't interesting in the least, remarkably unremarkable as they say.

But when it comes to just simply getting shit done, and quickly understanding and being able to work in other peoples code, it is second to none. It just doesn't get in your way, and out of the box it gives you simple syntax, great tools and easy deploys.

[+] cgislason|12 years ago|reply
How would you recommend becoming familiar with idiomatic Go?

I've read various articles including (but not limited to) tutorials, made a point of exploring a few open source projects and I've written a few thousand lines of Go. I enjoy writing Go, but I have a hard time so far figuring out if what I write is idiomatic.

[+] fiorix|12 years ago|reply
<T>errible to my eyes.
[+] embwbam|12 years ago|reply
I use generics every day in typescript. I'm waiting to use go until it has them.
[+] reality_czech|12 years ago|reply
I'm more interested in what Go might be like without whiners.