29 comments

  • YesThatTom23 hours ago
    &quot;The best way to teach something new is to compare it to something the audience already understands.&quot;<p>Could someone take the example, reduce it to a non-generic version for two types I DO understand, then show that with the new feature I can collapse them into the Box&#x2F;Map example in the doc?<p>I have 10+ years of Go experience and I can&#x27;t make heads or tails of &quot;(b Box[T]) Map[U any](f func(T) U) Box[U]&quot;
    • LukeShu2 hours ago
      <p><pre><code> type IntBox struct { v int } type StrBox struct { v string } func (b IntBox) MapToStr(f func(int) string) StrBox { return StrBox{v: f(b.v)} } </code></pre> (Please forgive any typos I made on mobile.)<p>It wasn&#x27;t a great example because &quot;Box&quot; isn&#x27;t really a useful type. But the point is that you no longer need to define a separate &quot;MapToXXX&quot; method for every type you might want to map to; now you can have just one type-generic &quot;Map&quot; method.
    • typical1822 hours ago
      It&#x27;s not a great example.<p>I think it&#x27;s trying to show a mapping operation for a generic container where the container values are of one type and the mapping function is allowed to return a container with values of a different type.<p>Without generics, something along the lines of the following (with runnable example at <a href="https:&#x2F;&#x2F;go.dev&#x2F;play&#x2F;p&#x2F;KHBI1uAhbO0" rel="nofollow">https:&#x2F;&#x2F;go.dev&#x2F;play&#x2F;p&#x2F;KHBI1uAhbO0</a>):<p><pre><code> type MySlice []int &#x2F;&#x2F; Map maps from a slice of ints to a slice of float64s. func (s MySlice) Map(f func(int) float64) []float64 { var out []float64 for i := range s { out = append(out, f(s[i])) } return out } </code></pre> From a quick search, this seems to be better explanation of this new 1.27 feature:<p><a href="https:&#x2F;&#x2F;www.gopherguides.com&#x2F;articles&#x2F;golang-generic-methods" rel="nofollow">https:&#x2F;&#x2F;www.gopherguides.com&#x2F;articles&#x2F;golang-generic-methods</a><p>(That uses an example that seems similar in spirit to the Interactive Tour&#x27;s example, but with a more useful type of a Stack[T] and corresponding explanation seem clearer.)
      • typical1821 hour ago
        And to answer the second half of your request, here is that exact same code as above, but now using the 1.27 generic methods feature (with a runnable example using tip at <a href="https:&#x2F;&#x2F;go.dev&#x2F;play&#x2F;p&#x2F;1YK62tGetsm?v=gotip" rel="nofollow">https:&#x2F;&#x2F;go.dev&#x2F;play&#x2F;p&#x2F;1YK62tGetsm?v=gotip</a>):<p><pre><code> &#x2F;&#x2F; Map maps from a slice containing type In to a slice containing type Out. func (s MySlice[In]) Map[Out any](f func(In) Out) []Out { var out []Out for i := range s { out = append(out, f(s[i])) } return out } </code></pre> In short, you could always have methods on a generic type since Go first introduced generics in Go 1.18, but with 1.27, the methods on the generic type can also introduce their own additional type parameters.<p>(Previously, you could achieve the same net effect with a top-level generic function, but then the code would not be grouped as nicely as hanging it off of the type, and arguably it now can have slightly better ergonomics in some cases. You can see more of the rationale from Robert Griesemer at <a href="https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;77273" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;77273</a>.)
    • pkal1 hour ago
      If you instantiate it with concrete types, does &quot;(b IntBox) Map(f func(int) string) StringBox&quot; make more sense? You have a collection (in this case Box) containing values of type T, a function that maps values of type T to type U, and if you apply that function to all elements in that collection you get a collection of type U.
    • torginus33 minutes ago
      This is the kind of shit why they probably didn&#x27;t want generics in the language.<p>This is like building a very crude general-ish DSL inside the language. Because the tools are intentionally limited (as to limit the scope of the feature), the result looks ugly. Also, like with C++ templates, people find exploits to do what the designers didn&#x27;t want them to, with even more elaborate workarounds.<p>I liked Go before generics. It had a clear identity. If you wanted to get cute, you could use <i>go generate</i> and generate code. They should&#x27;ve made that much more convenient and ergonomic, if they wanted to make the language more powerful (and the nice thing is that it still sits outside of the language).<p>I think the point Go was making is that these complex things generally have little use in application code, and 99% of the time they&#x27;re there for people who want to show how smart they are, at the expense of code readability, and accessibility.
  • baalimago11 hours ago
    This: &quot;(b Box[T]) Map[U any](f func(T) U) Box[U]&quot; is the type of cognitive weight I was happy that Go avoided.
    • teh648 hours ago
      I think naming conventions might help:<p><pre><code> (b Box[InType]) Map[OutType any](transformFunction func(InType) OutType) Box[OutType] </code></pre> Same in Python:<p><pre><code> def map[U](self, f: Callable[[T], U]) -&gt; Box[U] </code></pre> vs<p><pre><code> def map[OutType](self, transform_function: Callable[[InType], OutType]) -&gt; Box[OutType] </code></pre> and Java:<p><pre><code> public &lt;OutType&gt; Box&lt;OutType&gt; map(Function&lt;InType, OutType&gt; transformFunction) </code></pre> vs.<p><pre><code> public &lt;U&gt; Box&lt;U&gt; map(Function&lt;T, U&gt; f)</code></pre>
    • fauigerzigerk9 hours ago
      It&#x27;s hard to avoid, because (naming aside) the cognitive load is caused by higher order functions, which are hard avoid without causing massive code duplication.<p>I understand the desire to keep things concrete and avoid high level abstractions, but it&#x27;s a decision not to automate stuff that can easily be automated. It runs counter to the basic instincts and purpose of our field&#x2F;industry. That&#x27;s why it never sticks.
      • hnlmorg8 hours ago
        Honestly, I’ve written some applications that, on paper, should be the perfect candidate for generics. And yet I can still count on one hand the number of times generics have saved me from massive code duplication.<p>Most of the time generics might be useful, I’ve ended up needing reflection too anyway. And at that point, I’m really no better off for generics.
        • fauigerzigerk7 hours ago
          I understand that this is true for a lot of application code. It&#x27;s not true for library authors though, and every language needs libraries.
          • hnlmorg6 hours ago
            I’ve written a lot of libraries too.<p>The problem is generics only solve a very small part of the equation: compile time checks for composite types. But to use composite types in anything non-trivial in Go, you then need reflection. Which is slow. And if you then need reflection, you’re already passing interface types anyway plus you’re back to having to handle type-handling errors in the runtime.<p>So if you’re writing a library that’s expected to have any kind of performance, you’re back to code duplication and having a DoSomethingType() function signatures again.<p>Or you stick with reflection and take that performance hit PLUS the risk of compile time constraints being runtime errors; which is the a lose-lose scenario. And let’s also not forget that reflection can be just as verbose as code duplication, and harder to get right too.<p>Don’t get me wrong, I’m glad we have generics. But people on HN <i>massively</i> overstate the value of them in a AOT non-dynamic, strictly typed language like Go.<p>I guess you could argue that Go has other shortcomings that directly result in generics having limited value. But then you’re basically just arguing that you prefer coding in a different language paradigm, and at that point, you’re much better off using that other paradigm instead of complaining that Go isn’t JavaScript or Haskell.
            • theptip3 hours ago
              Interesting, thanks - is the problem you’re describing solved by Rust’s macros (eg derive) or are there further issues you see even there?
            • pezo19193 hours ago
              Thanks for that, nicely put, interesting angle.
      • Pay089 hours ago
        Lisp manages it. Even if you do use type annotations.
        • fauigerzigerk9 hours ago
          No. This cognitive load is conceptual. You can&#x27;t avoid it by using slightly different syntax.
          • stingraycharles3 hours ago
            I think the problem is that the Box &#x2F; Map &#x2F; any stuff and all the explicit declarations that Go requires makes it harder.<p>In Haskell as well, you can let the compiler infer a lot of things but that doesn’t appear to be the case with this example.<p>I’d want the compiler to infer things, but that - I think - is at odds with Go desiring a fast compiler, which I also understand.
            • Pay082 hours ago
              I was about to mention Haskell as well, I feel like it also avoids this sort of cognitive load. Maybe it&#x27;s something to do with the languages being designed as functional languages instead of languages with functional components.
    • zerr4 hours ago
      We often forget that our profession (computer programming) belongs to STEM. Some (like Go 1.0 :)) wish to think it is Arts &amp; Humanities. The sooner we realize that yes, it is OK and actually expected to bear a cognitive weight of &quot;(b Box[T]) Map[U any](f func(T) U) Box[U]&quot; the sooner we get back to reality... :)
      • snsjjsjjs0 minutes ago
        I wish it was arts &amp; humanities.. those are some actually clever folks.
      • red_admiral4 hours ago
        Just because we can, doesn&#x27;t mean we have to. I&#x27;d prefer to have some more brain-cache free to concentrate on the problem I&#x27;m trying to debug rather than doing type resolution in my head.
        • yladiz3 hours ago
          Please. I’m sorry, but you kind of can’t avoid needing to think about types unless you use a language like JavaScript which is super loose with its type conversions, and you especially can’t avoid in a language like Go. With generics in Go you don’t even need to prefill the types like you go with a lot of other cases, so I’m dubious about the cognitive overhead.
          • kfuse24 minutes ago
            No need to insult JavaScript. In two out of three times the &quot;JavaScript&quot; written will be something like:<p><pre><code> interface Box&lt;T&gt; { value: T } function map&lt;T, U&gt;(input: Box&lt;T&gt;, func: (value: T) =&gt; U): Box&lt;U&gt; { return { value: func(input.value) } }</code></pre>
      • wannabe441 hour ago
        In terms of tooling, Go is one of the few languages which remembers that we are in STEM.
      • thebytefairy4 hours ago
        People should stop using these simplified high level programming languages with low cognitive weight, like Go. I only write assembly. ;)
      • 4ndrewl3 hours ago
        (b Box[T]) Map[U any](f func(T) U) Box[U] _is_ for the Arts and Humanities.<p>Unless you&#x27;re writing assembler in vim you&#x27;re not STEM.
      • fragmede3 hours ago
        Why should I, as fallible human of limited short and long term memory, bear that cognitive weight when I have a perfectly good compiler on a computer to offload that particular cognitive weight to?
    • adrianmsmith10 hours ago
      I never understood the convention of using single letter names for generic parameters. I guess this started in C++ and every language has copied that convention.<p>I think that code would be a lot easier to read if the types were called IN and OUT or In and Out or TIn and TOut or something like that.
      • jiehong10 hours ago
        We all know letters are expensive ^^
      • toinebeg8 hours ago
        I often use whole word for type annotation, when I can find meaningfull ones. I just type them in all caps to stay close to the convention.<p>I guess the single letter thing is laziness for a part. It&#x27;s not simple to find words that represent the abstract idea behind the generic type without narrowing the possibilities. For array function, the Key Value from the sibling comment work but for more complex use case, it get complicated.
      • wwalexander7 hours ago
        Swift generics tend to idiomatically use longer names, like Element or View or Content.
        • girvo6 hours ago
          I’ve always done that in my typescript code bases too, and I’ve never regretted it
          • fooooor3 hours ago
            Lambdas usually have short variable names because the scope is small, typically half a line. And that is fine, even optimal.
      • spockz10 hours ago
        Completely agree and I personally name generic type parameters as I would name types and parameters. It helps a lot.
      • Someone9 hours ago
        For maps, a convention is to use K and V for key, respectively Value.<p>I think that’s best as you’ll soon learn the “single-character capital letter ⇒ generic parameter” convention
      • fooooor3 hours ago
        What could be more idiomatic than:<p>for (int i=0; i&lt;10; i++) { printf(”%d\n”, i); }<p>(Or the very similar Go equivalent)<p>If you having a hard time parsing that, due to the short variable name, i.e. if it’s a huge cognitive load for you, I suggest you switch career, b&#x2F;c the IT industry is obviously not a good fit.<p>With that said, Go is explicit with suggesting short variable names for small scopes, and long variable names for bigger scopes. This a good practice in all languages.
      • Laurel12349 hours ago
        In C# this is the convention.
        • eterm4 hours ago
          It&#x27;s a mix, because some stuff tends to just use `T`, but there&#x27;s better descriptors elsewhere.<p>There&#x27;s IList&lt;T&gt; but Task&lt;TResult&gt;<p>There&#x27;s Action&lt;T1, T2, T3, T4, T5, T6&gt; but also Dictionary&lt;TKey, TValue&gt; and Map&lt;TIn, TOut&gt;<p>This stuff kind of &quot;makes sense&quot; once you&#x27;re used to it, because it&#x27;s difficult to say what IList&lt;T&gt; ought to have been called otherwise, IList&lt;TContainee&gt; is a mouthful, and Action&lt;T1,...&gt; simply suffers from the inability to specify an unknown number of generic parameters.<p><a href="https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;api&#x2F;system.collections.generic.ilist-1?view=net-10.0" rel="nofollow">https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;api&#x2F;system.collecti...</a><p><a href="https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;api&#x2F;system.action-2?view=net-10.0" rel="nofollow">https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;api&#x2F;system.action-2...</a><p><a href="https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;api&#x2F;system.collections.generic.dictionary-2?view=net-10.0" rel="nofollow">https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;dotnet&#x2F;api&#x2F;system.collecti...</a>
      • phplovesong10 hours ago
        Im pretty sure it came from the MLs, where you usually have a&#x2F;b&#x2F;c instrad of the T,U etc combo.<p>I dont find it confusing, as its pretty clear that it only an placeholder.<p>In generics the name usually does not matter or is REALLY hard to name so that it makes sense.<p>More specifically in Go where you have interfaces, concrete types and generics.
        • asQuirreL9 hours ago
          Fairly sure it would predate even that, and go all the way to lambda calculus, and predicate logic before that, and that&#x27;s where my knowledge stops and somebody else can tell us where the current conventions around variables in logic and mathematics come from.
        • teh647 hours ago
          In ocaml (and I assume SML) it helps that the generic types have a `&#x27;` before them, so<p><pre><code> val map : (&#x27;a Box) -&gt; (&#x27;a -&gt; &#x27;b) -&gt; &#x27;b Box</code></pre>
      • setopt9 hours ago
        I believe Haskell did that for decades before C++.
        • logicchains8 hours ago
          Haskell was created in 1990, five years after C++.
          • hnlmorg8 hours ago
            Haskell had generics from the beginning. Whereas C++ only added templates to its specification in 1998.
            • zerr3 hours ago
              Miranda had it since its release in 1985.
            • jahnu4 hours ago
              I was using the STL in 1994 with Zortech C++
    • dvdkon9 hours ago
      Maybe it&#x27;s just familiarity, but I think it would look a lot more comprehensible with some punctuation. Just because a syntax is formally unambiguous doesn&#x27;t mean it looks that way to humans.<p><pre><code> func (b: Box[T]).Map[U: any](f: func(T) -&gt; U) -&gt; Box[U]</code></pre>
    • mseepgood6 hours ago
      It&#x27;s not good Go code anyway. In Go you would use a for loop. Just because Go has generics nowadays doesn&#x27;t mean you should abandon good taste and write ML&#x2F;Haskell&#x2F;Rust&#x2F;C# in it.
      • wannabe441 hour ago
        Sure it&#x27;s a bad example. But you can&#x27;t simplify something like this without losing type safety:<p><pre><code> SortBy[T, K comparable](slice: []T, key: func (T) K)</code></pre>
    • red_admiral4 hours ago
      Indeed, we&#x27;re now one step away from monads. I know <a href="https:&#x2F;&#x2F;go.dev&#x2F;doc&#x2F;effective_go" rel="nofollow">https:&#x2F;&#x2F;go.dev&#x2F;doc&#x2F;effective_go</a> hasn&#x27;t been updated for while, but it also seems to have been forgotten. &quot;Go is an open-source programming language that focuses on simplicity ...&quot; the page begins.
      • treyd4 hours ago
        You&#x27;ve already been able to badly implement monads in Go for 10+ years. Why wouldn&#x27;t you be able to implement them in a way that the compiler can enforce correctness of?<p>If you don&#x27;t want it don&#x27;t use it. It&#x27;s that simple.
        • fooooor3 hours ago
          No it’s definitely not that simple. Code are read more often than written, no one works in a vacuum, especially not in open source. Also, when in Rome...
          • golem143 hours ago
            If a project&#x27;s owner feels that strongly about not using generics, that&#x27;s a choice. No dependencies using generics, no generics allowed in PRs etc. Perfectly doable.<p>Also, screw those Romans ;)
      • inigyou4 hours ago
        Apparently the people responsible for the simplicity retired. Since it&#x27;s Google, some new people want to be promoted for adding features to Go.
    • twsted10 hours ago
      I really understand your feeling, I escaped from C++ years ago when I was overwhelmed by meta programming (initially i loved it).<p>But anyway I find this in Go much more bearable.
      • zerr3 hours ago
        As a C++ (including modern) developer for more than 20 years, I had written a &quot;template&quot; keyword only for a handful of times. Maybe once in every 5 years on average... :)<p>Unless you are a compiler&#x2F;stdlib vendor or contributing to Boost, there are features that you just don&#x27;t use it daily.
    • kitd10 hours ago
      It looks more reasonable (literally lol) with syntax highlighting though.
      • fooooor3 hours ago
        Luddites don’t use syntax highlighting though.
    • HumblyTossed5 hours ago
      Right? Sigh. I really dislike this.<p>There are 37000 programming languages, stop forcing every single one that gets popular to look like this.
    • skywhopper3 hours ago
      Is it worse than having to create endless functions for each type pair?<p><pre><code> (b IntBox) MapToStringBox(f func(int) string) StringBox (b IntBox) MapToBoolBox(f func(int) bool) BoolBox (b StringBox) MapToIntBox(f func(string) int) IntBox </code></pre> Etc etc etc?<p>The T, U, and f names are the cognitive load here, because they are meaningless variables. For a specific solution, those would have meaningful names that would make it easier to understand.
    • scotty798 hours ago
      &gt; (b Box[T]) Map[U any](f func(T) U) Box[U]<p><pre><code> Map method of b (of type Box[T]) that takes f (of type function that takes value of type T and returns value of type U (which could be any type)) and returns value of type Box[U] is defined as follows return Box[U]{v: f(b.v)} func[U any] b:Box[T].Map(f:func(T)-&gt;U)-&gt;Box[U]: return {v: f(b.v)} func[U any] Box[T].Map(f:func(T)-&gt;U)-&gt;Box[U]: return {v: f(this.v)} &#x2F;&#x2F; maybe all of the types could be inferred from usage? func Box[].Map(f): return Box[]{v: f(this.v)} </code></pre> Eh... I think you&#x27;d need to avoid generics altogether.
      • wannabe441 hour ago
        Map&#x2F;Filter&#x2F;Reduce is a bad example for an imperative language. But look at slices and maps packages, or the new proposal for container types. There are many good examples how generics are like salt to food. Another example is errors.AsType.
      • inigyou4 hours ago
        that&#x27;s literally what Go was supposed to do! If I want a language like C++, I know where to find a language like C++ (it&#x27;s C++).
  • chenxiaolong16 hours ago
    This release also fixes runtime.findnull() to be compatible with MTE on Android ([1] and [2]). This was the only thing preventing MTE from being enabled for apps that use gomobile on MTE-compatible Android OS&#x27;s like GrapheneOS.<p>[1] <a href="https:&#x2F;&#x2F;go-review.googlesource.com&#x2F;c&#x2F;go&#x2F;+&#x2F;749062" rel="nofollow">https:&#x2F;&#x2F;go-review.googlesource.com&#x2F;c&#x2F;go&#x2F;+&#x2F;749062</a><p>[2] <a href="https:&#x2F;&#x2F;go-review.googlesource.com&#x2F;c&#x2F;go&#x2F;+&#x2F;751020" rel="nofollow">https:&#x2F;&#x2F;go-review.googlesource.com&#x2F;c&#x2F;go&#x2F;+&#x2F;751020</a>
    • fooooor3 hours ago
      I still don’t understand why Go isn’t the primary supported language for android.
  • mappu15 hours ago
    Automatically draining http response bodies is a risky silent behaviour change. I think it will be an improvement for most applications, but it&#x27;s very subtle if you were relying on the old behaviour
    • kune10 hours ago
      The Go team is addressing that in the release notes: <a href="https:&#x2F;&#x2F;go.dev&#x2F;doc&#x2F;go1.27" rel="nofollow">https:&#x2F;&#x2F;go.dev&#x2F;doc&#x2F;go1.27</a> They think it will only affect use cases where a high number of idle connections were allowed to linger, for instance by setting MaxIdleConns in Transport to 0. They recommend to disable keep alives in that case.
    • gigatexal11 hours ago
      Can you go more into this? I don’t quite follow
      • mappu11 hours ago
        Go&#x27;s http.Client will keepalive a TCP&#x2F;TLS connection to save you handshake latency on second requests. But it can only do this if you completely finish reading the last request.<p>Now in 1.27:<p>&gt; http.Response.Body drains itself on Close. For HTTP&#x2F;1, closing the body now reads and discards any unread content (up to a conservative limit) so the connection can be reused. For most programs this is a transparent win [...]<p>Great, so i no longer have to io.Copy(io.Discard, resp.Body) in the err case, one less thing to worry about; but<p>&gt; if you were leaning on an early Close to abort a large download, set Transport.DisableKeepAlives to opt out.<p>That&#x27;s a subtle behaviour change. Any previous Go program which used Close in this way - say for an infinite event stream - now hangs, soaking up bandwidth.<p>In the past, the Go team have searched the entire Github corpus for misuse before making changes like this. I don&#x27;t have a reference but I assume an appropriate level of consideration went into this decision.<p>EDIT: &quot;&quot;up to a conservative limit&quot;&quot; so this is not so bad after all.
        • spockz10 hours ago
          Is “a conservative limit” a high limit or a low limit? If it is high such that many responses will still be drained it would keep reading those infinite streams for a long time. If it is low it might still not drain all normal sized messages.<p>Anyway, this is why it pays off to read release notes closely and have a decent test suite.
          • mxey7 hours ago
            The drain is asynchronous, so it won’t block. The limit is 256 KB and 50 ms.
        • gigatexal47 minutes ago
          This sounds like a breaking change. Like a go 2.0 thing idk.
      • MartinodF10 hours ago
        Say you have some code that does a request to an HTTP&#x2F;1 dependency, and if it get an error response, just closes the connection without reading the response body.<p>Go 1.26 in practice never re-used that connection, it always established a new one because you can&#x27;t reuse a connection which has a pending response ready to be read.<p>Go 1.27 will now consume the body for you, causing your application to re-use connections much more aggressively, bringing in potential edge cases (e.g. dependency is broken, connection is now permanently unusable, your app no longer recovers automatically).<p>To be clear, I&#x27;m very glad for the change and I had equivalent code in our in-house framework to do just that, but yeah it does change the behavior in a way that it could expose undetected issues.
  • sbstp13 hours ago
    Go&#x27;s standard library has always been it&#x27;s strength, especially the crypto package! Lovely stuff.
  • my-next-account11 hours ago
    &gt;The quieter but bigger change<p>I really wish they didn&#x27;t use such stupid LLM-isms.
    • neilprosser10 hours ago
      I do wonder whether, as a group of people being regularly exposed to text written by LLMs, we&#x27;ll gradually end up writing and talking like that in our normal language. At that point perhaps text written by LLM and human will be indistinguishable. I already find myself using terms like &#x27;footgun&#x27; in jest more than I ever did before!<p>&quot;The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.&quot; ― George Orwell, Animal Farm
      • yladiz6 hours ago
        The percentage of people that use LLMs so much that their language would change based on its responses is small enough that I’d doubt it would happen. Maybe for technical groups that use it more, but not for the general population.
      • zer00eyz4 hours ago
        &gt; I do wonder whether, as a group of people being regularly exposed to text written by LLMs, we&#x27;ll gradually end up writing and talking like that in our normal language.<p>We were doing this before LLM&#x27;s. All sorts of trendy business speak would spread - the term &quot;synergy&quot; springs to mind as one people beat to death.<p>This is the concept of &quot;memetics&quot; (as in meme) in action. Hank Green recently talked about using AI and he went &quot;off script&quot; and threw &quot;I appreciate the pushback&quot; into his speech on the fly...<p>LLM&#x27;s generating large volumes of content means that we&#x27;re going to see all of its &quot;isms&quot; creep into other peoples speech much faster.
    • abtinf8 hours ago
      The entire thing is obviously LLM generated. Much better off just reading the release notes.
    • jonathrg8 hours ago
      Worth flagging, real gap, transparent win, center of gravity... I&#x27;m tired boss
    • aaa_aaa8 hours ago
      This post seems to be mostly llm generated
  • nu2ycombinator15 hours ago
    Those Generics syntax in Golang seems so hard to read.
    • trueno5 hours ago
      stared at it for a bit and im mostly certain i prefer it to java. at least writing other go = its not bad for me to break apart the signature line on a generic<p>java feels kinda unhinged the more that i look at it<p><pre><code> public static &lt;T extends Comparable&lt;? super T&gt;&gt; T max(Collection&lt;? extends T&gt; c) </code></pre> :x i wonder if anyones done something like this, would be super unhinged<p><pre><code> Map&lt;String, List&lt;Map&lt;Integer, Optional&lt;Pair&lt;String, Function&lt;? super List&lt;? extends Comparable&lt;?&gt;&gt;, ? extends Map&lt;String, ?&gt;&gt;&gt;&gt;&gt;&gt;&gt; config; </code></pre> go seems to get a lot of flack around these parts. i kinda lurv it though, just getting compiled binaries out of not much code and not needing a runtime to do shtuff. once i got a wrangle on goroutines i dunno i feel like its pretty solid for webapp backend which is mostly what i use it for
    • theplumber14 hours ago
      It is verbose but inference helps a lot to keep it “tidy”. I always find myself increasing my focus a notch when I start dealing with generics. It’s one of the things I use only if I really “need”.
      • xmprt12 hours ago
        One of the reasons it took so long to implement generics in Go was because there was a lot of stuff you could do that didn&#x27;t need it. Now that generics are there, a lot of that stuff is still the best way to solve the problem and many of the methods that require generics are in the standard library so it&#x27;s rare that you absolutely need it.
      • bessel-dysfunct13 hours ago
        Yeah, I agree with that.<p>Back when Go&#x27;s generics came out, I was working with about 20% Go and 80% Python. I looked at the syntax, went &quot;not today, Satan&quot; and never bothered to learn it. For the past half year I&#x27;ve been in a mode where most of my coding time is spent with Go and I&#x27;ve been completely indoctrinated. I unironically like thinking about how generics and interfaces interact now.<p>I also need to slow down when I need to use them for non-trivial stuff. Not just relative to Go code but relative to how much I needed to think about them back when I was using OCaml. I think part of it is that I save them for hard issues and use interfaces for easy stuff.
    • Cthulhu_9 hours ago
      It does, but at the same time it&#x27;s not &quot;normal&quot; code; I see it much like Typescript&#x27;s advanced types, ultimately it&#x27;s something that mainly lives in libraries.
    • twsted10 hours ago
      imho it is much better that C++ equivalent
  • ewy13 hours ago
    fascinating how many people are displeased with the expansion of generics! i love go and this is some functionality i always missed.
  • mayama14 hours ago
    Adding simd in std and even being used in map is nice. Would have to look for places to experiment with it in hot loops in code I have.
  • Hixon1016 hours ago
    Some examples for the upcoming release <a href="https:&#x2F;&#x2F;go.dev&#x2F;doc&#x2F;go1.27" rel="nofollow">https:&#x2F;&#x2F;go.dev&#x2F;doc&#x2F;go1.27</a>
  • fweimer10 hours ago
    &gt; interfaces still can’t declare type-parameterized methods<p>What would an implementation look like? Wouldn&#x27;t it be quite different from the existing one because it has to rely heavily on indirection because (limited) monomorphimization is not possible?
    • cherryteastain6 hours ago
      Probably won&#x27;t&#x2F;cannot be ımplemented. C++ and Rust disallow the analogues of this (templated virtual methods&#x2F;dyn with a trait containing methods taking type parameters) as well.
  • lilbigdoot15 hours ago
    This level of generics actually has me interested a bit in Go now.
    • bilinguliar6 hours ago
      You can take my place, as the same changes make me want to leave.
      • melodyogonna56 minutes ago
        To what? What would you use instead, things like this seem common place in languages made in the last decade.
  • KolmogorovComp4 hours ago
    Instead of having each language bring progress in a different and&#x2F;or novel, we get this, old java features that comes 20 years-in after the making.<p>They&#x27;re probably useful, but clearly not sexy (as golang in general).
  • neild1 hour ago
    Many comments on generic methods. Perhaps this example will help understand a hopefully not-too-objectionable case of using them in practice.<p>The math&#x2F;rand&#x2F;v2 package has a number of functions which return random numbers of a certain type:<p><pre><code> i := rand.Int32() &#x2F;&#x2F; a random signed 32-bit integer (type int32) j := rand.Uint64() &#x2F;&#x2F; a random unsigned 64-bit integer (type uint64) </code></pre> It has functions which return a number within a range:<p><pre><code> in := rand.Int32N(10) &#x2F;&#x2F; a random int32 in the range [0,10) jn := rand.Uint64N(100) &#x2F;&#x2F; a random uint64 in the range [0,100) </code></pre> It also has a generic function, rand.N, where the return type is set by a type parameter. The definition of rand.Int32N (for comparison) and rand.N are:<p><pre><code> func Int32N(n int32) int32 func N[Int intType] (n Int) Int </code></pre> Adding some spaces to make the common elements align (apologies if my formatting gets mangled), that&#x27;s:<p><pre><code> func Int32N (n int32) int32 func N [Int intType] (n Int ) Int </code></pre> As you can see, the generic function N has the same signature as the non-generic Int32N, except the type it operates on is set by a type parameter (named &quot;Int&quot;). The type parameter has a <i>constraint</i>, intType, which is a private type defined in the math&#x2F;rand package. (There&#x27;s nothing magic about this constraint, it&#x27;s just a list of all the integer types in the language, and you can write it yourself if you want to. It&#x27;s a separate type to keep the function signature of N from becoming too large, and it&#x27;s internal to math&#x2F;rand because it doesn&#x27;t need to be part of the public package API.)<p>The nice thing about rand.N is that it lets you write something like this:<p><pre><code> &#x2F;&#x2F; d is a random time.Duration in the range [0, 10 minutes) d := rand.N(10 * time.Minute) </code></pre> Without generics, you&#x27;d instead write this as the following, which is a lot more noise:<p><pre><code> d := time.Duration(rand.Int64N(int64(10 * time.Minute))) </code></pre> The generic rand.N has a more confusing type signature and a lot more language complexity behind it, but the code using it is simpler and easier to read. We think that&#x27;s a good tradeoff, but of course not everyone will agree.<p>All the functions I&#x27;ve mentioned so far use a default random number source. Each of them also exists as a method of the rand.Rand type, which generates numbers from a user-provided randomness source. For example:<p><pre><code> rng := rand.New(rand.NewChaCha8(seed)) a := rng.Uint64() b := rng.Uint64N(100) </code></pre> There is one exception, though: Until Go 1.27, there was no Rand.N method, because we did not support generic methods. (A generic <i>type</i> could have methods, but those methods could not be further type parameterized.)<p>In Go 1.27, there is now a Rand.N method:<p><pre><code> &#x2F;&#x2F; Using a ChaCha8-based source with a defined seed, &#x2F;&#x2F; generate a duration in the range [0, 10 minutes). rng := rand.New(rand.NewChaCha8(seed)) d := rng.Duration(10 * time.Minute) </code></pre> This method&#x27;s signature is:<p><pre><code> func (r *Rand) N[Int intType](n Int) Int </code></pre> Comparing function vs. method and generic vs. concrete:<p><pre><code> func Int32N (n int32) int32 &#x2F;&#x2F; function func N [Int intType] (n Int ) Int &#x2F;&#x2F; generic function func (r *Rand) Int32N (n int32) int32 &#x2F;&#x2F; method func (r *Rand) N [Int intType] (n Int) Int &#x2F;&#x2F; generic method </code></pre> In this case, generic methods permit us to fix a small wart in the package API. This example isn&#x27;t the motivating reason for adding generic methods, but I think it serves as an example of how adding them makes the language a bit simpler and more consistent. In Go, methods are just a type of function. Previously, you could write a type-parameterized function, but you couldn&#x27;t write a type-parameterized method. That&#x27;s an inconsistency that you need to remember. Now you can write type-parameterized functions or methods, using a consistent syntax for either.<p>Type-parameterized methods don&#x27;t participate in interface satisfaction, so this change isn&#x27;t without its own subtleties. Discussing the tradeoffs there would double the length of this post, and weighing them is why it took so long for us to decide to add generic methods.<p>Another possibility is that people will use generic methods to write unreadably complex code. My personal opinion is that nothing will stop people from writing unreadably complex code if they want to; the fix to complexity is to not do that.
  • drivebyhooting15 hours ago
    Can generics be used to improve error handling and eliminate the if err pattern?
    • ad_hockey10 hours ago
      As of June last year[1] the Go team have pretty much drawn a line under this issue, with a very small amount of wiggle room to possibly reopen it at some point:<p>&quot;For the foreseeable future, the Go team will stop pursuing syntactic language changes for error handling. We will also close all open and incoming proposals that concern themselves primarily with the syntax of error handling, without further investigation.”<p>Personally I&#x27;m OK with this, I didn&#x27;t see any of the (many) proposals as a definite improvement. They all had trade-offs.<p>[1] <a href="https:&#x2F;&#x2F;go.dev&#x2F;blog&#x2F;error-syntax" rel="nofollow">https:&#x2F;&#x2F;go.dev&#x2F;blog&#x2F;error-syntax</a>
      • Cthulhu_9 hours ago
        Yeah a few years ago there was a lot of buzz around it, but ultimately when presenting and polling all the options to the community, the general consensus was that existing error handling was actually fine. The other options added complexity and were harder to read.
        • fooooor3 hours ago
          Rust solved this, but the Go language developers are having too much prestige to be able to embrace Rust’s solution. Sad.
    • jerf14 hours ago
      No.<p>I kind of want to leave it there. But that will probably be looked on disfavorably.<p>I&#x27;ve seen at least a dozen attempts. It&#x27;s not like it&#x27;s hard to write it out. There&#x27;s maybe a couple of variants but they&#x27;re all just a handful of lines. The problem is, once you have an Option in hand, you end up trading:<p><pre><code> val, err := whatever(...) if err != nil { &#x2F;&#x2F; handle error } &#x2F;&#x2F; use val </code></pre> for<p><pre><code> val := whatever(...) if err, isErr := val.Error(); isErr { &#x2F;&#x2F; handle error } realVal := val.Value() &#x2F;&#x2F; use realVal </code></pre> What you win in nominal safety, you&#x27;re definitely losing in convenience.<p>There&#x27;s also no win in trying to offer a monadic interface like<p><pre><code> finalVal := whatever(...).OnVal(func (val Value) opt.Option[Result] { &#x2F;&#x2F; use val }) </code></pre> because that&#x27;s the minimal specification of an anonymous function in Go, so it&#x27;s very inconvenient. Even if that was trimmed down, nested functions are still problematic in other ways. And you still have to unpack finalVal anyhow.<p>Really the solution is, install golangci-lint, turn on errcheck [1], use a pre-commit hook to make it a commit failure if golangci-lint fires, and that pretty much covers the problem in practice.<p>One of the problems with Option&#x2F;Result&#x2F;etc. advocacy... not the pattern itself, the <i>advocacy</i>... is that it is generally are presented, implicitly or explicitly, as if the alternative is C, with its errno and the need to not just check an error value, but remember to go actively seeking out errors constantly, making it easy to forget. But by modern standards, that&#x27;s completely pathological.<p>If we rate error handling techniques on a scale from 1 to 10 (best), C here is a 1, and standard Option is maybe an 8 or a 9. The way Go does it is maybe a 6; it is completely true that you can neglect to handle an error (see errcheck comment in previous paragraph), but it <i>is</i> in your face that an error is possible, and that&#x27;s really most of the problem. Putting Option&#x2F;Result&#x2F;etc. is not always a &quot;go from 1 to 9&quot; result. &quot;Go from 6 to 8&quot; is a much less impressive proposition, and the other inconveniences that come with it in Go tend to overwhelm the gain. I use errcheck all the time, and even in the Before Times when I was writing it all by hand it really didn&#x27;t fire all that often. Especially if I exclude test code. In an AI era this hardly rates at all. AI never neglects the error.<p>Whether it does the right thing with it, now... that&#x27;s another story entirely.<p>Read those error handling clauses if you&#x27;re writing Go with AI. I really don&#x27;t like what I&#x27;ve seen AIs do with them by default. What I&#x27;ve seen out of AI has been very thoughtless. Nominally correct in some weak sense, but thoughtless.<p>[1]: <a href="https:&#x2F;&#x2F;golangci-lint.run&#x2F;docs&#x2F;linters&#x2F;configuration&#x2F;#errcheck" rel="nofollow">https:&#x2F;&#x2F;golangci-lint.run&#x2F;docs&#x2F;linters&#x2F;configuration&#x2F;#errche...</a>
      • drivebyhooting14 hours ago
        I think my opinion will be even more maligned: I like Java-style checked exceptions. It forces awareness of the error and a clean way to propagate it.
        • adrianmsmith10 hours ago
          People advocate for Go&#x27;s error handling because it forces you to deal with errors.<p>But in the cases I do want to catch a specific error, the signature only tells me <i>that</i> a function returns an error, not which type. So I do feel that returning (int, error) is strictly worse than Java&#x27;s checked exceptions if you care about errors.
          • spockz10 hours ago
            This is elegantly solved with sum types. (And arguably needs sub typing.)<p>If instead of just returning (int, error) the function would return (int, parseError | outOfBoundsError) you would know that the parser function can fail on reading a number at all and on the number being to big&#x2F;small to fit the type and handle then accordingly.<p>Saliently, Java in a sense has supported sum types in the throws declaration and the subsequent catch statements forever. Unfortunately it has not landed in other places where you can use types so you cannot use it for returning errors. Scala 3 supports this but has tiny adoption it seems.
          • kitd10 hours ago
            That&#x27;s helped by errors.Unwrap() and errors.Is(), though you do need to build and structure your errors appropriately.
            • adrianmsmith9 hours ago
              It&#x27;s helped, but that&#x27;s runtime behaviour. The compiler can&#x27;t help you with questions like &quot;you didn&#x27;t handle certain errors&quot; or &quot;the error you&#x27;re trying to check can never occur&quot;.<p>Nor does that help with documentation, I&#x27;m guessing if I read a file then it might raise the error that the file does not exist. But what exactly is the technical type of that error? You have to search through the function&#x27;s implementation, and functions that function calls, etc., to find out.<p>And it doesn&#x27;t help with refactoring. If you create new.FileNotFoundError and change your function to return it, existing code which checks for old.FileNotFoundError will start to silently fail.
        • mook10 hours ago
          I agree; in practice, probably only the public error types, though. If it can return fmt.Errorf(&quot;…%w…&quot;) I probably only need the type of the wrapped error, not whatever type the implementation uses.
        • girvo6 hours ago
          I liked Nim’s take on checked exceptions personally, was quite lovely
        • Nursie13 hours ago
          The thing that most annoys me in Java in that area is when a dependency throws an unchecked error that wasn’t even documented.<p>Thanks so much for that! Now I have no choice but to be reactive when something fails…
      • bajsejohannes6 hours ago
        If you get the ? from rust in addition to the option, then it’s suddenly a lot more convenient. It will do `if err != nil { return err; }` in a single symbol.<p>There’s also convenience at the returning side. You can always just return the error, and not have to care about dummy values for the other return values (which is especially annoying when changing the returned types).<p>That said, it might still not be worth the added complexity.
      • nitrix11 hours ago
        Error handling is as important as the happy path of an application. It’s not something you sweep under the rug.<p>The err != nil quickly turns into metrics, logs, fallback strategies, retry mechanisms, flight recording, rate limiting, updating caches, so on.<p>Anyone who’s trying to shorten this hasn’t maintained any actual real software.
  • theplumber14 hours ago
    This is quite of a big release and I like the new methods on generics.
    • Hendrikto7 hours ago
      Methods on generic types were already a thing. What is new is that methods can now define their own generic parameters, independent of the type they are defined on.
  • Altern4tiveAcc7 hours ago
    &gt;func (b Box[T]) Map[U any](f func(T) U) Box[U] {}<p>That&#x27;s completely unreadable.
    • asdf889906 hours ago
      Yes, thinking in higher order abstractions is hard for most people.
      • cpuguy835 hours ago
        I&#x27;m pretty sure the issue is not &quot;higher order abstractions&quot;. It is using multiple single letter references with no real grounding or relationship that the reader has to track.<p>For example, looping over a map with &quot;k&quot; and &quot;v&quot; vars is not that bad because the reader understands k=key and v=value, and that makes since for a map. If you do this same thing with different single letter vars, e.g. &quot;a&quot; and &quot;b&quot;, it instantly becomes more difficult to read.<p>When writing a generic function and using these single character type references it can make sense, especially because the function&#x2F;method doesn&#x27;t care what those references are, however to someone trying to understand what&#x27;s going on it can be extremely difficult simply because of the names.<p>Sure, if all you are going to do is call that method or function those type references go away and the call site may be relatively clean, but you still have to read the thing to understand what it is and how to use it.
      • fooooor3 hours ago
        On the contrary, linq in C# is a killer function that other languages still fail to replicate.<p>How many sloc are required for this?<p>var max = mycollection.Max();<p>Probably 5-10 if you’re missing higher order functions. And the risk of bugs will be 10x.
  • rednafi7 hours ago
    I am all for using LLMs to generate value but a little more editorial review can&#x27;t hurt.<p>&gt; The quieter but bigger change: the classic encoding&#x2F;json (v1) package is now backed by the v2 implementation under the hood.<p>This is fantastic content nevertheless.
  • nothrows14 hours ago
    generics were a slippery slope. give it a decade and Go will be indistinguishable from c++
    • EdiX13 hours ago
      Generics themselves maybe not. Generic methods probably yes. What people want generic methods for is to do deeply nested call chains that were never typical of Go. And if you have deeply nested calls you&#x27;ll need some way to deal with errors in deeply nested calls, and then a short function syntax to pass to behavior inside those deeply nested calls. Give it a few years and everyone will be writing the same functional slop in Go that they are writing in every other language.
      • adrianmsmith10 hours ago
        &gt; What people want generic methods for is to do deeply nested call chains<p>I don&#x27;t see that as the only use of generic methods.<p>The example in the article is a &quot;Map&quot; method that transforms e.g. a List[A] to a List[B], by taking a function that takes an A and returns a B. To be able to transform a list like that is a useful operation.<p>It was possible to do the same with a global function like MapList but the syntax is nicer if you use methods. You don&#x27;t need the type in the name (function MapList vs method Map) and it is an operation on the List after all so list.Map(..) is nicer than MapList(list, ..).
      • foldr11 hours ago
        The generic methods that have been added are essentially just syntax sugar. You can now use method syntax in cases where you could equivalently define a function. They’re not the fundamental extension to the type system that some people have been asking for (and probably will never get, because there’d be no reasonable way to implement it).
    • nirui13 hours ago
      Not here against Generic methods, but I feel the Go team is in a mid-age crisis where they lack of new things to do to prove themselves. See their iterators mini-drama not long ago?<p>I feel the sumtype&#x2F;emum&#x2F;routine demanders should yell a little harder so Go team can find their purpose again.
    • cookiengineer13 hours ago
      &gt; generics were a slippery slope. give it a decade and Go will be indistinguishable from c++<p>Lib boost will have conquered every language by then!!! :D<p>Jokes aside, generics are unusable in a lot of languages due to their syntax choices. In Go we kinda have the problem that there&#x27;s no real templating and no real macros, so they&#x27;re even harder to use.<p>But I agree somewhat, generics feels to me like an anti pattern in Go.<p>Also, the way the Go core&#x2F;stdlib is written, it makes generics so unnecessarily painful to debug. Why they decided to have definitions like &quot;~C&quot; or &quot;~[]S&quot; is beyond me. No human knows what the resulting compile time error means. They should have named these things &quot;Comparable&quot; or &quot;Slicable&quot; or whatever is more expressive. Just stop with this stupid single letter shit.
  • stingraycharles16 hours ago
    Am I the only one who’s absolutely shocked that Go finally is embracing generics?<p>Does anyone have a bit of an inside view into what changed in the perspectives of the language maintainers?<p>I’m not buying the “it took us 20 years to understand how to do it correctly” argument, as this is something you explicitly take into consideration when designing the language or not. And it was specifically not a part of language design, and is much harder to retrofit (backwards compatibility).<p>So what changed?
    • bradfitz15 hours ago
      (I was on the Go team for ages)<p>Seriously, that&#x27;s all it was. Just Ian alone proposed and rejected a half dozen of his own different approaches to generics. Finally a language + implementation plan came together that people all liked.<p>Nobody was ever opposed to generics that I saw.
    • amtamt14 hours ago
      If bug free binary search implementation can take 16 years, I am ready to buy generics implementation could take 20 years.<p>&gt; In his landmark book The Art of Computer Programming, legendary computer scientist Donald Knuth noted that although the first binary search algorithm was published by John Mauchly in 1946, the first bug-free version was not published until 1962—taking a staggering 16 years to get right.
      • ckcheng14 hours ago
        Took a few more years to get really bug free.<p>&gt; Fast forward to 2006. I was shocked to learn that the binary search program that Bentley proved correct and subsequently tested in Chapter 5 of Programming Pearls contains a bug. ... Lest you think I&#x27;m picking on Bentley, let me tell you how I discovered the bug: The version of binary search that I wrote for the JDK contained the same bug. It was reported to Sun recently when it broke someone&#x27;s program, after lying in wait for nine years or so.<p><a href="https:&#x2F;&#x2F;research.google&#x2F;blog&#x2F;extra-extra-read-all-about-it-nearly-all-binary-searches-and-mergesorts-are-broken&#x2F;" rel="nofollow">https:&#x2F;&#x2F;research.google&#x2F;blog&#x2F;extra-extra-read-all-about-it-n...</a>
        • inigyou4 hours ago
          403 error. What was the bug?
          • fragmede3 hours ago
            Load in an incognito window?<p>Loads fine for me:<p>&gt; The bug is in this line:<p>6: int mid =(low + high) &#x2F; 2;
          • _dain_3 hours ago
            IIRC it was overflow when you do (a + b) &#x2F; 2 for the midpoint. It took so long to find because you need a &gt;billion item array to overflow the 32-bit integer, and that much RAM wasn&#x27;t common until the 00s.<p>The right way is a + (b - a)&#x2F;2.
            • inigyou25 minutes ago
              64KiB was common in the 16-bit era, however
    • fooster15 hours ago
      It’s also not true that because it wasn’t part of the initial design that it was harder to retrofit. I just don’t understand all this go bashing that happens on this site especially when so much is badly informed speculation. I guess it’s easier to tear something down.
      • stingraycharles11 hours ago
        my post was never intended as Go bashing, I use Go a lot and appreciate its simplicity.<p>am I tearing something down in my comment?
        • foldr10 hours ago
          HN threads on Go are boring because they always get derailed by someone grousing about the fact that it took a long time to add generics. The history of this has been gone over a thousand times already and it’s really quite undramatic. The Go team couldn’t figure out a good design for generics for a long time. Eventually, they got some help from Phil Wadler and other type system experts and figured it out. The end. Anyone who feels that the Go team should have done it faster owes us at the very least their own design together with a soundness proof for a plausible fragment of Go. Conspicuously, no-one provided such a thing before the Go team did.<p>The details of Go generics, their advantages and disadvantages compared to other languages, etc., are absolutely interesting to discuss. But there is nothing hiding behind the “official” story.
    • HumblyTossed5 hours ago
      Surely it was pressure from devs to make Go look like every other language they begged to change then abandoned for the new hotness.
    • abtinf14 hours ago
      Unfortunately nothing changed. They wanted generics all along.<p>The Go ecosystem was a delicate, special thing. It was a wholesale rejection of the malignant consultancy takeover of programming that had festered and spread for the previous 15 years. Introducing generics was a grievous error, and they just keep making it worse.<p>It used to be you could look at any Go code from any author and pretty much instantly understand it <i>completely</i>. That’s no longer the case.<p>It used to be you would work on a problem, just writing the code from top to bottom. No time wasted fiddling with abstractions you’ll never use. You’d grumble about it, but succumbing to the temptation was impossible. That’s no longer the case.
      • tacitusarc13 hours ago
        I have written Go for the past decade and completely, fundamentally disagree with this take. Go has always had a tendency towards limited exressivity, which created a strong dependence on interface{}, type assertions, and runtime bug’s that should have been compiler errors.<p>When I read these grumbling takes about how Go use to be so simple etc I imagine devs who would revel in all the features they were unable to implement because it would be too difficult in the language. Or devs who love typing and re-typing the same code over and over again, littering their code with switch cases and conditional logic while passing themselves on the back for avoiding “abstraction”.
    • whateveracct14 hours ago
      and they&#x27;re still worse than the 1970s state of the art lol
      • eager_learner12 hours ago
        you mean like in Oberon?
        • whateveracct5 hours ago
          ML&#x27;s parametric polymorphism
          • foldr5 hours ago
            Go lets you constrain type parameters with interfaces. To do anything analagous in SML you have to use functors, which is substantially less convenient. I think people who refer to ML&#x27;s parametric polymorphism in this context must really be thinking of parametric polymorphism in OCaml or Haskell.
            • whateveracct2 hours ago
              You just do dictionary passing.
              • foldr2 hours ago
                Like this, you mean? <a href="https:&#x2F;&#x2F;haskellforall.com&#x2F;2012&#x2F;05&#x2F;scrap-your-type-classes" rel="nofollow">https:&#x2F;&#x2F;haskellforall.com&#x2F;2012&#x2F;05&#x2F;scrap-your-type-classes</a><p>Fine in principle, but AFAIK it never really caught on because the ergonomics suck. Interfaces&#x2F;traits&#x2F;type classes do seem to be a popular feature across languages, for what it&#x27;s worth.
    • throw2ih02015 hours ago
      &gt; what changed in the perspectives of the language maintainers?<p>The original maintainers moved on to other projects and the new community maintainers came to a consensus through the proposal and governance process.
      • bradfitz15 hours ago
        No, that&#x27;s not accurate. The same core people were involved.
  • cat-whisperer12 hours ago
    does go have enums?
    • adrianmsmith10 hours ago
      No
      • pkal10 hours ago
        One reason that Go doesn&#x27;t have sum&#x2F;union types, from <a href="https:&#x2F;&#x2F;groups.google.com&#x2F;g&#x2F;golang-nuts&#x2F;c&#x2F;0bcyZaL3T8E&#x2F;m&#x2F;eL4r3VFKkR8J" rel="nofollow">https:&#x2F;&#x2F;groups.google.com&#x2F;g&#x2F;golang-nuts&#x2F;c&#x2F;0bcyZaL3T8E&#x2F;m&#x2F;eL4r...</a>, is that it is not apparent how this would mesh with Go&#x27;s &quot;meaningful zero value&quot; stance.
  • kansm13 hours ago
    Tried running a couple of examples in the tour, but ran into a few errors.
    • wredcoll13 hours ago
      Tried reading your comment but ran into a lack of usable information.
      • wccrawford8 hours ago
        If you try a new thing and run into 1 (or maybe 2 errors), maybe it&#x27;s worth the time to report them.<p>If you run into <i>a few</i> errors, it&#x27;s into &quot;this isn&#x27;t ready&quot; or &quot;they didn&#x27;t try hard enough&quot; territory, and it&#x27;s not worth reporting the problems.
  • smalljelly20189 hours ago
    [flagged]
  • mangudai3 hours ago
    [flagged]
  • fang2hou14 hours ago
    [dead]
  • okzgn15 hours ago
    [dead]
  • vladsiu11 hours ago
    [dead]
  • pixxxel12 hours ago
    Let&#x27;s GO
  • adrianmsmith8 hours ago
    One thing I think generics in Go is missing is the &lt;?&gt; concept in Java.<p>If you&#x27;re taking a List[T] and all you want to do is to call list.size() then you don&#x27;t care what type of list it is. In Java you can write a function which takes a List&lt;?&gt; but in Go you have to write List[T] so then the question becomes what is T? You have to make the function (or type you&#x27;re a method on) generic. If you make the type generic then every user of your type also needs to specify T, etc.<p>I don&#x27;t think it would be impossible to add that to Go. Allow List[?], which matches a List with any type parameter. Calling functions which don&#x27;t involve the type parameter like list.size() would be fine, calling a method returning the type parameter like list.get(n) would return &quot;any&quot;, and methods taking the type parameter like list.set(n, obj) would probably not be callable.
    • kbolino2 hours ago
      You need this in Java because interfaces are explicitly implemented. You don&#x27;t need this in Go because interfaces are structurally implemented. The way you spell &quot;anything that has a method named Size which returns int&quot; is interface{Size() int}.
    • Hendrikto7 hours ago
      Go Generics work differently than those in Java. They are specialized, meaning that they are not generic at runtime anymore. Instead, the compiler creates a different implementation for each type.<p>At runtime, there are only List[int], List[string], etc. List[T] is not a thing anymore.