6 ms·
...But does it have generics?
by natural219 12y ago
...But does it have generics?
- duaneb 12y agoI think it's pretty clear by now Go is not aligning itself with type parameters. If you need generics, don't use Go. Most programs probably don't need generics.
- seanmcdirmid 12y agoMost programs don't need generics like most programs don't need static typing. Just use "any" and downcast.
- gohrt 12y agoThat's entirely different. Generics can be replaced by code-generation (C++-style templates) in a preprocessor with no loss of safety, or by boring copy-paste (with some loss of safety :-(). non-static typing is a massive loss of safety.
- pcwalton 12y agoStatic typing can be replicated in a dynamically typed language with a preprocessor too. (For example, see TypeScript.)
- seanmcdirmid 12y agoTemplates/macros/preprocessing do sacrifice separate compilation and separate type checking; so your error messages might not be comprehensible, your compile times can be much slower, and...you need source for your generic container. Rob Pike probably knows the drawbacks of that approach well and I doubt he would go there.
- collinvandyck76 12y agoMost programs don't need generics, but a lot of programs benefit from having them. This, along with exceptions, are the two things that keep me from considering Go for future service development. We've stood up a couple of successful Go services, but the maintenance overhead from not having these two things has been substantial.
- seanmcdirmid 12y agoGo has something that is functionally equivalent to exceptions; they just don't call them exceptions and make them look a lot different from what we are used to.
- mwsherman 12y agoYes and no, errors are just return values. They’re not special, they are conventional. So you get the whole type system to express errors – they’re just values. And you don’t have a different control flow. It’s not without warts. You can bail with panic(), which is essentially a throw. It’s tedious to handle errors, but that’s because actually handling errors is tedious.
- eropple 12y ago"Actually handling errors" isn't tedious at all in Scala. Chain flatMap() across methods that use Try[A], handle the Failure[_] at the other end, and you're done. I'm not joking when I say it really is that easy. Go makes it (and, really, many other things) very difficult for reasons that are at best murky.
- NateDad 12y agoSo you call say 3 methods, and at the end you have a "file not found" error... which call resulted in that failure? I don't know Scala specifically, but from what I know of most languages that support this kind of chaining, you can't tell. And that's the problem. Did your initialization fail to find it's config file in step 1? Did you fail to find the target file you were going to transform in step 2? Was there some other failure in step 3? You can't tell, so you can't actually handle the error. This is effectively like doing this in Java: try { DoX() DoY() DoZ() } catch( Exception ) { // The code has no idea what failed here. } Whereas, the go code looks like this: if err := DoX(); err != nil { // handle error from DoX } if err := DoY(); err != nil { // handle error from Doy } if err := DoZ(); err != nil { // handle error from DoZ } This is what Go programmers means when they say "actually handle the errors". At each step you handle the specific failure from the specific call. It's somewhat more verbose, but it's a LOT more robust against real life failures.
- Touche 12y agoMost programs do list manipulation and list manipulation in Go is a pain. Generics are one solution for that.
- nonuby 12y agoI agree generic would be a serious win for Golang. However in the meantime we have this workaround/hack which alleviates some of the pain http://clipperhouse.github.io/gen/ http://clipperhouse.github.io/gen/
- mwsherman 12y agoAppreciate the mention! Also gen is getting more, um, generic with the notion of custom ‘typewriters’, out on this branch: https://github.com/clipperhouse/gen/tree/3.0 https://github.com/clipperhouse/gen/tree/3.0
- logicchains 12y agoLisp manipulation? Do you mean linked lists, or arraylists? The only common use of linked lists I've encountered is writing custom allocators, and most programs don't need custom allocators.
- deleted 12y ago[deleted]
- _ak 12y agololwhat? How exactly would list manipulations in Go be made easier because of generics?
- TheCoelacanth 12y agoHow many of these[1] functions can I write in Go without doing a bunch of casting? Probably less than half. [1] https://hackage.haskell.org/package/base-4.7.0.0/docs/Data-List.html https://hackage.haskell.org/package/base-4.7.0.0/docs/Data-L...
- joncooper 12y agoMy understanding is that the Go team isn't opposed to generics, and in fact is quite aware of their value, but that: - it isn't a priority - it is a tricky thing to get right in the context of Go - there haven't been any satisfactory proposals thus far If this isn't quite right I'd love to be corrected.
- duaneb 12y agoI'd like to add that generics can add a lot of complexity to a compiler, and the compiler's simplicity is IMHO of great benefit to the language. I'm happy they're taking their time with it; it's better than ending up with a half-assed implementation like Java.
- coldtea 12y agoThat was the common understanding from 2-3 years ago, when they left the question hanging and said that "we'll do it when we find the proper way etc". In the meantime there have been several satisfactory proposals (in the lists and elsewhere), and it's not like 200 other languages implementing Generics have had many issues with them. So, it boils down to the Go core team putting up the solution to an impossible tradeoff as the holdback (and a little exagerrated one at that, with relation to the costs involved). And then, they said "the language won't change" etc recently.
- lbruder 12y agoSo it's more like Guido refusing to add TCO to Python because that would be oh so hard to do. And look, the stack trace! The horror, the horror. /s
- deleted 12y ago[deleted]
- mrgriscom 12y agothat is basically the "please go away and stop asking" response
- coldtea 12y agoNo programs really needs anything above assembly. It's the "nice to have" things that make programming easier/more correct/better.
- drdaeman 12y agoA single instruction is sufficient. Anything more just complicates things and is completely unnecessary.
- Dewie 12y agoGreat, downvoted 'to oblivion' for asking a question that would have no doubt come up in the thread, anyway.
- MBCook 12y agoIf they add generics, I would expect it would be in a 2.0 or some other release where they're willing to make possibly backwards-incompatible changes, not a point release.
- natural219 12y agoI'm really sorry, everybody who replied seriously. I just couldn't help myself. I...actually, I don't regret it. Edit: I'm kind of hoping "But does it have generics?" will become the new "Will it blend?" for golang discussion.
- reitanqild 12y agoTo anyone that wonders: "Will it blend" was never a karma magnet on HN. One of the reasons I like HN.