Live data from Hacker News

Why Generics?

blog.golang.org

171–180 of 261 posts

Re: Why Generics?

#171

Earlier quoted context omitted.

If you're writing loops that build up some accumulator, you could use generics. Even if you don't see that.

You could use generics for that kind of code, but that doesn’t necessarily mean you need them. If you’re thinking of functional stream operators, many people think plain imperative iteration is easier to write (and easier to read).

By that logic, there's nothing you _need_ generics for.

Re: Why Generics?

#172

Earlier quoted context omitted.

Huh. Yeah, that's exactly it. Funny coincidence :)

Your presentation seems less directional than the original Blub article, FWIW.

Indeed. I remembered some aspect of directionality, but couldn't remember how to present it in as compelling a way.

(Also, I don't really agree with some objective single value gradient for programming languages. As for anything with multiple dimensions of value, it's not sortable)

Re: Why Generics?

#173

Earlier quoted context omitted.

It comes up in Scala. The solution is to have notation to specify the variance of types.

Yes, though Scala can hardly be an example of simplicity.

I don't think it's the simplest language out there but its parametric polymorphism is quite straightforward

Re: Why Generics?

#174
"This article is about what it would mean to add generics to Go, and why I think we should do it. I'll also touch on an update to a possible design for adding generics to Go...."

This is a situation where who is making the proposal is more important than the proposal.

"By Ian Lance Taylor"

Oh. Ok. I guess it's worth reading then...

Re: Why Generics?

#175

Maybe this is unfair, but it’d be great if the Go devs could just say “generics will work similarly to [C# / Java / Swift / D / whatever], except that we’ll address [problems] with [adjustments]”. Rather than going through this whole rigmarole of resisting adding generics too early because all existing implementations are bad, then slowly reinventing the wheel from scratch, then finally ending up with something prett…

> because all existing implementations are bad I'm also not sure why in OOP-land, generics are this crazy experimental weird feature, when in functional languages, people figured out how to implement parametric polymorphism (the original term for generics) in quite reasonable ways. I get that subtyping adds some complexity, but overall I don't understand why such a basic way to build abstractions is so controversial…

If go ever showed people the awesomeness of StandardML or Ocaml/ReasonML (and their amazing type systems), I think the language would lose a lot of users.

Re: Why Generics?

#176
post #26
post #2

Personally, I prefer the current interfaces-based solution to generics. It's a little verbose, but keeps the language simple. However, I think that the people we should be listening most are the ones developing huge projects in Go, like Kubernetes. Would having generics with this new contracts thing make it easier to develop and maintain e.g. Kubernetes? I'm truly curious.

Generics and Interfaces solve different problems

Yes - but don't they get contangled?

How would you re-orthoganize the problem statement? (Statements, actually)

Re: Why Generics?

#177

Earlier quoted context omitted.

I’d compare it to e.g. the work on async/await in Rust, where the discussion seems more directly “we like this feature that C# pioneered and JS has adopted, here’s how we plan to adapt it to make it work well with Rust.” Admittedly, the Rust async/await RFC and the Go contracts proposal both discuss prior art in sections towards the end, so they are actually similar in that respect. Maybe it’s really just a question…

Fair point, however I think that you're mistaking language design discussion in a closed group of PLT invested people, and a blog post targeted at general audience. Visiting https://rust-lang.github.io/async-book/ I don't see any mentions of neither C# nor JS. The key difference here is the audience.

The async book is in the process of being re-written; I wouldn't be surprised if a comparison to JS ends up in there, given that we have some significant differences and it really trips up a lot of people who come from JS.

Re: Why Generics?

#178

It might be fun to share my viewpoint from an angle that's probably fairly unique. I've started a number of large, highly deployed Go projects: Terraform, Vault, Packer, Consul, Nomad, and numerous libraries and other things. I started a company that employs hundreds of full time Go developers. Go has been one of our primary languages since Go 1.0 (and I used it prior to that). Let me start by saying that there are _…

I see the use for generics all the time . I came from Ruby, where we have enumerable so you get standard constructs like map, find, first, last, each_cons, etc. Because Go lacks them, people constantly reimplement these things with less intention-revealed code using ad hoc for loops. Ugh. Thus you see very little use of collection pipelining in Go. https://martinfowler.com/articles/collection-pipeline/ Generics are s…

Your parent is quite familiar with Ruby. :)

Re: Why Generics?

#179

Earlier quoted context omitted.

Inheritance makes generics difficult. For instance, if A If you are just reading the array, you would want Array[A] This problem doesn't come up in ML style languages because they do not make use of inheritence.

Why in the case of writing to the array would you want Array[B] < Array[A]?

  def writeFirst: (xs: Array[B], x:B): xs[0]=x;

  var as: Array[A] = ???
  var b:B = ???
  var a:A = ???

  a=b;        //This is fine, since B extends A.
  as[0]=a   //Obviously fine, since a:A
  as[0]=b   //This better be fine, otherwise the above 2 lines just punched a hole in our type system.
  writeFirst(as,b); //If I am allowed to do the above, I should be allowed to do this.
For completeness, the opposite example:

  def getFirst(xs: Array[B]):B = xs[0];

  var as:Array[A]
  var b:B = as[0] //This shouldn't work. Not all A's are B's
  var b:B = getFirst(as) //Simmilarly, this shouldn't work.

Re: Why Generics?

#180

Earlier quoted context omitted.

Inheritance makes generics difficult. For instance, if A If you are just reading the array, you would want Array[A] This problem doesn't come up in ML style languages because they do not make use of inheritence.

Why in the case of writing to the array would you want Array[B] < Array[A]?

[deleted]
Post reply on HN