News for hackers. Stuff that matters.
Re:50 Algorithms Every Programmer Should Know (Second Edition) by vitus on Wednesday January 03, 2024 @08:13AM (#38853650)
> This is funny to me, because Go is often touted as a language that has "everything you need" in the stdlib.

My usual example of something missing from the standard library is

    func max(a, b int) int {
      if a > b {
        return a
      } else {
        return b
      }
    }
math.Max only operates on two float64s (due to the absence of function overloads; many standard library functions such as this predated generics), so if you want to avoid casting (and/or potential loss of precision if you're working with int64), you need to reinvent the wheel.
Re:50 Algorithms Every Programmer Should Know (Second Edition) by pyth0 on Wednesday January 03, 2024 @08:25AM (#38853771)
Go has had generic forms of the `min` and `max` functions as builtins since 1.21. https://pkg.go.dev/builtin#max
Re:50 Algorithms Every Programmer Should Know (Second Edition) by j1elo on Wednesday January 03, 2024 @01:03PM (#38857332)
Go 1.21 is the version from which it is noticeable that they are pushing towards (re)implementing things that were lacking before due to missing support for generics.

Like the new slices package, meant to do common operations on slices, that is brand new on 1.21.

I wouldn't be surprised to see more and more new additions leveraging generics in next releases.

Re:50 Algorithms Every Programmer Should Know (Second Edition) by vitus on Wednesday January 03, 2024 @06:23PM (#38861186)
Good to know! I admittedly haven't written much Go in the past year, and while min / max were some of the most egregious examples, I'm sure there are plenty more that still exist.