Go: Support for Generic Methods

(github.com)

41 points | by f311a 5 hours ago ago

29 comments

  • kardianos 33 minutes ago

    This is great. Will be useful for data access methods!

    As for the detractors, from the first generics proposal this was called out as a "not now", not never. There were questions of implementation. They aren't a super large team, and they try to do things incrementally and do them well.

    • dude250711 5 minutes ago

      Gophers are usually quite fast, perhaps an elderly turtle would be a better mascot?

  • reactordev 5 minutes ago

    [delayed]

  • nasretdinov 19 minutes ago

    Lack of generic methods was really surprising to me when I was first trying to use generics in Go. Nice to see it being actually implemented

  • h1fra an hour ago

    slowly implementing all the things they said we didn't need

    • TheChaplain an hour ago

      It's not a bad thing to realize that one can be wrong and then strive for change.

      • a-french-anon an hour ago

        Maybe, but personally I've become quite tired of programming languages "organically grown" as opposed to properly designed the first time. After a good decade of C then C++, I found ANSI CL (despite being a massive compromise and unfinished) much more coherent and complete than both.

        • bbkane 36 minutes ago

          I know Go is justly criticized for many of its design decisions, but it still feels well-designed and "small" to me in day to day usage when many other languages don't.

        • ndr 38 minutes ago

          "Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp."

          -- Greenspun's tenth rule

          He had some lack of conviction to scope it so narrowly.

        • rootnod3 18 minutes ago

          ANSI CL is such a breath of fresh air nowadays. Does what you need, doesn't get in your way, comes with batteries included. And conditions are just god-tier.

        • ramon156 42 minutes ago

          So which language had it right from the start? is there a language that has a very low rewrite status?

          • bbkane 35 minutes ago

            I'd particularly like examples of statically typed languages that "got it right" (since I love me my types)

            • galangalalgol a minute ago

              Ocaml maybe? Multi threading didn't seem necessary and introduced the possibility of data races.

          • maccard 29 minutes ago

            That’s whataboutism - no language is perfect, but given when go released it’s fair to hold them to a higher standard than languages what were designed 25 years earlier.

            As an aside - D, Zig, Rust, even typescript got most of the lessons learned from C right

        • xscott 23 minutes ago

          Scheme is (or at least was) coherent. You don't need to look any further than set/setf/setq to see that Common Lisp is "organically grown" from the fertilizer of a committee. CL does it's best to make every other lisp more attractive.

          • rootnod3 19 minutes ago

            Which Scheme are we talking about? R5RS? R7RS-small? R6RS? With SRFIs? Without? Which scheme? Is it `(library...)` or `(define-module...)`?

            • xscott 7 minutes ago

              Heh, I'd probably take R4RS with define-syntax :-)

      • layer8 7 minutes ago

        It’s still annoying ~20 years after Java did the same mistake of not including generics, which was already clear to many people with C++ experience back then.

      • tux3 39 minutes ago

        I don't think anyone admitted any wrong or had any big change in philosophy. It's always a good thing to learn something along the way. But the current message seems to be that this was the plan all along, and it just took some time to design properly.

        Of course adding generics is not something that every language needs to do. Scripting languages like Ruby don't really need this style of generics. It doesn't fit the design of the language, and it's not even clear what that would look like in Ruby.

        But static typing with generics does solve a recurring problem, and we've seen some real convergence towards type hints and type systems even in staunchly dynamic scripting languages. Modern Javascript is now mostly Typescript, and they've successfully retrofitted a very advanced type system in the last place I would have expected 20 years ago.

        • galangalalgol 28 minutes ago

          Type hinting seems like the worst of both. You pay the cost on refactor to go change them all, where dynamic typing or static type inference avoid that. You also don't have any of the benefits of static or dynamic typing. My strong preference is static typing with good inference and an ide that shows the inferred types everywhere when asked. Dynamic typing can make some tasks dramatically easier, I'm just not capable of using them without making hideous mistakes.

      • maccard 33 minutes ago

        There’s a fine line between being willing to change your mind and getting the basics wrong. Go has repeatedly gotten the basics wrong.

        • whoiskevin 18 minutes ago

          Declaring a highly successful language as having the basics wrong means that you are not correct about the basics that were needed.

          • maccard 2 minutes ago

            Something can be highly succesful in spite of having glaring design flaws. Nobody is claiming go isn't wildly succesful, but it's _in spite_ of these issues. It was clear over a decade ago that iota, gopath, and lack of generics were massive kneecaps to the language; go changing it's mind on those things isn't progress it's just getting the fundamentals wrong.

            A good example of where they're kind of stuck is date formatting - it's stupid, unclear, and likely a mistake, but it's not a fundamental flaw; it's just a quirk.

          • jeswin 2 minutes ago

            It's a highly successful language because (1) it was backed by Google, and (2) created by Robert Griesemer, Rob Pike, and Ken Thompson.

            If it came out of anywhere else, it might have struggled even to hit the homepage here.

            • amazingamazing a minute ago

              This logic is easily shown to not hold. Why isn't Carbon, Dart, etc. not really popular then?

          • 9rx 6 minutes ago

            An engineer, of course, understands that there is no such thing as "wrong", only different tradeoffs, but with the rise of "vibe coding" you don't need to be an engineer to play in the world of programming anymore.

        • Jleagle 30 minutes ago

          Sounds like you want this feature, and you just got it. Not sure how that's wrong. You don't add in every feature from the start.

          • maccard 28 minutes ago

            I wanted it 10 years ago.

    • 9rx 25 minutes ago

      Of course, if you go back and watch the original Go announcement it said that it would need generics once they figured out how to do it. And when the first version of generics landed it was said that generic methods would be added later, once they figured out how to do it. So that isn't applicable here. The need was always recognized.