Golang proposal: container/: generic collection types

(github.com)

49 points | by jabits 1 hour ago

3 comments

  • athorax 23 minutes ago
    On one hand I'm glad to see this being added, but its becoming obvious building generics into the language as-is just isn't a good fit. Hopefully Go v2 can solve this at a more foundational level while still allowing interop or easy porting form current go code.
  • troupo 1 hour ago
    Go is rediscovering Guy Steele's Growing a Language from first principles, at a much slower pace: https://youtu.be/_ahvzDzKdB0?is=qZdfiT3792XyHxSJ
    • silverwind 41 minutes ago
      It's sad that such basic stuff took this long. If we're lucky we might even see a `Map` function in our lifetimes.
      • PrimalPower 7 minutes ago
        The beauty of go is YAGNI. Language design makes it much harder for people so do stupid and cute things.

        During my design process if I start realizing that I’m missing maps, More expressive Types, Or more complex polymorphism. I ask myself if I really need those things.

        If I really do. I move off of go.

        That’s the beauty of the language. Go does not need more complicated language features because it’s can handle the majority of trivial software work without unnecessary complexity.

        The language does not need to solve complicated problems.

      • wannabe44 23 minutes ago
        Map function leads to poor code in Go. Function literals are verbose and inlining is far less agressive. It simply isn't the way of the language. Even python shuns map and filter in favor of comprehensions. A for loop is more readable than the lambda soup.
    • pstuart 49 minutes ago
      Sounds like a win to me. I'd assume that many PL decisions come with with costs of either implementation or readability, and Go's conservative evolution takes that into account. Disclaimer: not a PL designer, just a codemonkey.

      It's not a perfect language, and the process has not been without its pain points, but work like this makes the language more powerful and I feel like I get my money's worth when I use it.

      Yes, I'm a Go fanboy but I'm not interested in language wars (e.g., yes Rust is more performant and correct but sometimes "good enough" is good enough).

      • tikhonj 1 minute ago
        "Everything is a trade-off" assumes you're on the Pareto frontier.

        Go is... very much not on the Pareto frontier of programming language design.

      • cyphar 23 minutes ago
        On the other hand, design decisions made under one set of constraints can become problematic when you add new features that don't play as well with earlier design decisions.

        For a concrete example, the fact you cannot define custom methods for external types in Go (a pre-1.0 design decision) means that you cannot write proper compile-time generic code to deal with some generic wrapping type (dumb example -- getting a sum of the perimeters of a generic set of shapes in an externally-defined collection type) -- you are forced to work around it with runtime type-switching. There are all sorts of arguments you can make about simplicity but this is an objective shortcoming of Go that is directly caused by generics being added to Go long post 1.0.

        My take on this is that despite selfishly wanting more from Go for many years myself, adding more stuff to Go at this late stage is just slowly chipping away at Go's uniqueness with features that make a large number of people using them unhappy. (For example, while they make some APIs nicer, iterators turn a basic logic bug that is impossible with for loops -- forgetting to stop iterating when the loop has a "break" -- into a runtime panic. And they really suck to compose.)

        • pstuart 5 minutes ago
          Fair enough. Primeagen did a video recently renouncing his love of Go over the concerns you've raised.

          That said, I'm assuming much of this "wobbly" functionality will live in libraries and will not be common in day to day coding (much as I've seen with generics so far). It's all optional after all.

          I use Go because it's simple, capable, and been my prime language for over a decade and that skill enables me to be valuable enough for a decently paying job.

          If I were younger with more energy and time on my hands I'd likely be a rustacean but I think I can ride out my career on this. YMMV.