Go 1.26 interactive tour
88 points by makishimu
88 points by makishimu
Anton, if you're listening, thank you for this series and for new Accepted! series. (Go team, if you are listening, we need an equivalent of the Ruby Hero award. I nominate Anton.)
Now, most crypto APIs will just ignore the random io.Reader parameter and always use the system random source (crypto/internal/sysrand.Read).
This seems like a poor decision to me. Replacing a function parameter with a global means that tests cannot run concurrently (note: ‘Because SetGlobalRandom affects the whole process, it cannot be used in parallel tests or tests with parallel ancestors.’).
I think that I understand the motivation, but this is just ugly. I could be wrong!
It's crazy how often I've run into the lack of new(expr) over the years. Since Go 1.18+ you usually have the option of dancing around it with a helper like
func GimmePointer[T any](val T)*T {
return &val
}
prior to that, I would often resort to something like &[]int{42}[0] in test code, where I needed it the most. I considered that too ugly for non-test code, though, and would write it out the long way — which is fine, but there are times when brevity harms readability, and times when brevity enhances readability, and this is the latter.
x := SomeBigStruct{
// 10 lines
Foo: new(int(42)),
// another 10 lines
}
will be superior to
var fortyTwo int = 42
x := SomeBigStruct{
// and then 10 lines later...
Foo: fortyTwo,
// etc.
}
It's crazy how often I've run into the lack of new(expr) over the years.
We've got an entire common/pointer package just for handling pointers to basic types (written pre-generics, obvs.)
Passing thought: I wonder if runtime/secret is going to be useful for malware dev + evasion. Then there's this:
The runtime/secret package is mainly for developers who work on cryptographic libraries. Most apps should use higher-level libraries that use secret.Do behind the scenes.
So I'm wondering if this kinda feature has been possible for a while just not wrapped up in a nice way to do it?
Very well written.
Looking at https://go.dev/cl/722500, it reads:
append([]byte(nil), make([]byte, next)...)[:0]
Why not make([]byte, 0, next) ?
My guess is so that it has the full capacity of the next size class, not just next.
Whoa, thank you so much for the explanation and the code example!
I guess it makes sense for highly optimized code.
Anton asked thepudds and he answered here: https://bsky.app/profile/thepudds.bsky.social/post/3mbrq7p4p4k2k
For errors.As, it's deemed type safe, but there are a few errors in the std library, and then some in popular packages, that don't implement Error as pointer receiver. You're left up to inspect the source code of the error to know if you need to call errors.As[*syscall.Error](err) like the vast majority, or errors.As[syscall.Error](err). The latter is correct, but the former produces no compiler error.