Live data from Hacker News

Maybe adding generics to Go is about syntax after all

dave.cheney.net

51–60 of 92 posts

Re: Maybe adding generics to Go is about syntax after all

#51

Earlier quoted context omitted.

It's the number one reason I tried out but wouldn't return and do anything serious in the language. And I'm not the only one.

There are numerous successful "serious" projects written in Go!

Of course there are, but I wouldn't want to be the one to write them.

Re: Maybe adding generics to Go is about syntax after all

#52
post #39

Earlier quoted context omitted.

> However quite a few Go developers now use interfaces with an unexported method specifically to stop users from misusing their types in a context they didn't intend. I guess it's come full circle. What a horrible hack. Why bother with that? Either export your interface, your don't.

Well -- what if you have multiple implementations of an interface and you want users to be able to choose between them (or rather, you want them to be able to write functions around your interfaces)? I don't really like it much either, but it's a completely valid usecase for unexported methods. In fact I'm pretty sure this was an example from the language developers for why you can have unexported interface methods i…

> In fact I'm pretty sure this was an example from the language developers for why you can have unexported interface methods in Go.

Indeed. It's used in the standard library for describing Go's AST if I recall correctly.

Re: Maybe adding generics to Go is about syntax after all

#53

Earlier quoted context omitted.

There are numerous successful "serious" projects written in Go!

Of course there are, but I wouldn't want to be the one to write them.

OK - well, from my 4+ yrs of experience creating and maintaining a big Go project, take it from me that it's really a very pleasant and productive language. I am branching out and learning Rust as an intellectual exercise, but can't help but think about how obtuse its syntax is compared to Go. I will continue to choose Go in the future just because it's so quick to work with (while also providing solid safety and refactoring support). The `interface{}` thing rarely comes up as a problem.

Re: Maybe adding generics to Go is about syntax after all

#54
post #41

Earlier quoted context omitted.

This is overstating the case for syntax. Without any empirical evidence that syntax is important to anyone other than folks that draft up syntax rules, this is just an assertion. Put another way, do you have evidence that it is important? Has it let people write better programs? How would you prove that? This is akin to saying grammar is important. It is, to an extent; but over adherence to grammar is usually not an…

Well, empirically, syntax is important to a large number of programmers who complain about Lisp's (lack of) syntax. That's not a rigorous empirical study, but it's the best I can do at the moment...

Sure, but what's not known is whether that's primarily because the majority of programmers learn to program on languages inspired by C syntax.

Re: Maybe adding generics to Go is about syntax after all

#55
post #50

Earlier quoted context omitted.

Yes, the people who want generics are either people who don't use Go, or don't understand the purpose of Go and the implications of adding them to the language.

Great way here to completely discount the criticisms of people who've used the language and found it unacceptable how often you have to escape out of the type system of a "safe" language with `interface{}`.

I've written Go for three years, and I've successfully avoided using interface{}. It's a matter of architecting your application to fit the language and choosing a different language if your requirements grow beyond what Go can provide. Golang has made a tradeoff between simplicity and abstraction, which is a perfectly fine choice. Turning Go into Java is just going to ruin yet another language with complexity thanks to mob mentality.

Re: Maybe adding generics to Go is about syntax after all

#56

Earlier quoted context omitted.

Yes, the people who want generics are either people who don't use Go, or don't understand the purpose of Go and the implications of adding them to the language.

Exactly. Say goodbye to fast compiles and easy-to-read code. Not to mention the muddy waters that will result from having both interfaces and generics together.

Just imagine the peer-pressure strategies that must already be forming in community minds to deploy against Go 1.x loyalists :)

Re: Maybe adding generics to Go is about syntax after all

#57

I was at Gophercon and saw Russ's video where he spent 30 seconds explaining what generics were to the audience and showed a half-baked example of the syntax they are considering. I've been using Go for almost 5 years now and have no desire to see generics introduced. It would ruin what is currently a very simple and easy-to-use language. Am I the only one who is hoping this whole thing fizzles out?

Yes, the people who want generics are either people who don't use Go, or don't understand the purpose of Go and the implications of adding them to the language.

This is a rather elitist and blanket statement comment and is not at all fair. You do not know the mindset of "the people who want generics" but you're acting like you do to make a rhetorical point about how you feel about them. There are many more polite ways of making your case.

Re: Maybe adding generics to Go is about syntax after all

#58

I was at Gophercon and saw Russ's video where he spent 30 seconds explaining what generics were to the audience and showed a half-baked example of the syntax they are considering. I've been using Go for almost 5 years now and have no desire to see generics introduced. It would ruin what is currently a very simple and easy-to-use language. Am I the only one who is hoping this whole thing fizzles out?

Go already has generics for its built-in collection types, yet you can see nothing but downsides for user-defined generic types?

Incredible mental gymnastics you've got there.

Re: Maybe adding generics to Go is about syntax after all

#59
It's been three years since I started writing Go professionally and I think adding generics to Go is one of the worst ideas I've ever encountered. I love Haskell, and I much prefer hindley-milner type systems, type classes, and real sum types. I see the value of generics where appropriate. Golang, however, made the tradeoff to sacrifice anything near that level of abstraction, and it's success might largely be attributed to the approach-ability of the language as a result of that tradeoff. Retrofitting generics onto the language will be at it's best a death sentence for the principles and ergonomics of the language. One thing that has become clear to me as I have spent time with Erlang, Haskell, and Go is that it's much better to use the right tool for the job rather than trying to manipulate a tool to fit every use case, which is precisely what adding generics is all about.

Re: Maybe adding generics to Go is about syntax after all

#60
post #50

Earlier quoted context omitted.

Great way here to completely discount the criticisms of people who've used the language and found it unacceptable how often you have to escape out of the type system of a "safe" language with `interface{}`.

I've written Go for three years, and I've successfully avoided using interface{}. It's a matter of architecting your application to fit the language and choosing a different language if your requirements grow beyond what Go can provide. Golang has made a tradeoff between simplicity and abstraction, which is a perfectly fine choice. Turning Go into Java is just going to ruin yet another language with complexity thanks…

It's not always that simple. Sometimes you cannot avoid using interface{}. There is a reason why some SQL libraries use interface{}, why (un)marshallers use interface{}, and why I use it heavily in my scripting interpreter which is written in Go.
Post reply on HN