[HN Gopher] Three Minor Features in Go 1.18
       ___________________________________________________________________
        
       Three Minor Features in Go 1.18
        
       Author : throwaway894345
       Score  : 124 points
       Date   : 2021-12-22 18:54 UTC (4 hours ago)
        
 (HTM) web link (blog.carlmjohnson.net)
 (TXT) w3m dump (blog.carlmjohnson.net)
        
       | Laremere wrote:
       | The investigation to justify the introduction of the Cut function
       | was an interesting read. Really solid numbers on those data to
       | show that the function, while redundant with other functionality
       | provided, is an extremely common operation and worth special
       | casing.
        
       | klodolph wrote:
       | I've been copy-pasting or re-writing a function much like
       | strings.Cut, probably dozens of times, in different Go packages.
       | It's nice to see this function make it into the standard library!
        
         | [deleted]
        
       | yagizdegirmenci wrote:
       | Go 1.18 also includes the new net/netip package which is huge,
       | now the Addr type holds less memory, it is comparable and
       | immutable.
       | 
       | There is also a great post(See:
       | https://tailscale.com/blog/netaddr-new-ip-type-for-go/) in
       | Tailscale's blog which deep dives into why we needed a new IP
       | type/library in Go.
        
         | onphonenow wrote:
         | I'm far more excited by Addr / netip then generics :)
        
         | sabellito wrote:
         | I haven't done any Go in my life, but this bit about
         | immutability interests me. Is there a general movement in the
         | Go community towards immutable data structures?
        
           | lbhdc wrote:
           | I don't think there is a movement towards immutable data
           | structures. The const keyword only works on basic types
           | (bool, num, str). Objects can have private member variables,
           | but those are only private on the module level. You can also
           | pass by copy instead of passing a pointer.
        
         | lifty wrote:
         | Is this Tailscale's library imported into Go's stdlib?
        
           | pphysch wrote:
           | Yep
        
           | benhoyt wrote:
           | Yes, after some discussion and minor modifications (and
           | removal of a few features):
           | https://github.com/golang/go/discussions/47323 ... I
           | understand the motivation for this new package, but it does
           | seem like a large API surface to have imported into the
           | stdlib.
        
             | pstuart wrote:
             | Being that this is coming from a (former) core maintainer
             | of the stdlib I think it's worthy.
        
             | na85 wrote:
             | Isn't that one of Go's main value propositions? A
             | batteries-and-kitchen-sink-included stdlib?
        
         | naikrovek wrote:
         | where does one find a comprehensive list of new things for each
         | version? the release notes never seem to know everything that
         | people in here know.
        
           | lbhdc wrote:
           | I normally look at the go blog. Their post about 1.18 linked
           | the detailed release notes.
           | 
           | https://tip.golang.org/doc/go1.18
        
         | ccakes wrote:
         | Hadn't seen this but yeah, a much needed improvement!
        
         | jaytaylor wrote:
         | Also see past HN thread about it:
         | 
         | https://news.ycombinator.com/item?id=26416553
        
       | howdydoo wrote:
       | strings.Cut is otherwise known in Rust as str::split_once. It's
       | something I've always missed when writing Go. Nice to see it
       | added to the stdlib
        
         | tialaramex wrote:
         | Yes, I use this much more often than the more powerful general
         | split feature, it feels very "right-sized".
         | 
         | split_once() and similar split features in Rust are interesting
         | because Rust doesn't have overloading, yet you can split on a
         | string, or a character. This relies on a Trait, Pattern, that
         | is Nightly, so you can't Implement it yourself in stable Rust
         | today, but eventually this factors out the commonality which is
         | cleverer than overloading (because it applies everywhere
         | automatically)
        
       | jaytaylor wrote:
       | I subscribed to GH activity for the Author's friendliness-
       | enhancing utility library. It's for parsing build information
       | from the debug pkg:
       | 
       | https://github.com/carlmjohnson/versioninfo/
       | 
       | The primary motivation curiousity to learn if this becomes "the
       | [best/default] way" folks reach for when leveraging BuildInfo to
       | implement binary versioning in Golang.
       | 
       | It could be a nice benefit to the entire go ecosystem if there
       | becomes a widely-used, de-facto, and consistent automatic
       | versioning scheme (for the common cases, e.g. minor point release
       | lineage).
        
       | Scarbutt wrote:
       | For those that have switched to Go from nodejs to serve json for
       | a web app, how did it go? (excluding the possibility of needing
       | something like react ssr which can be a big one for many apps).
        
         | randomdata wrote:
         | _> excluding the possibility of needing something like react
         | ssr_
         | 
         | No need to exclude that possibility. I once worked on a Go app
         | that rendered React (in Typescript) server-side. The Javascript
         | could call Go API functions directly when rendering server-side
         | and those calls would turn into gRPC-web calls after it was
         | loaded in the client. It worked really well.
        
       ___________________________________________________________________
       (page generated 2021-12-22 23:00 UTC)