Earlier quoted context omitted.
Am I reading it correctly that `clear` does different things for maps and slices? Why doesn't it remove all the items from the slice like it does with the map, or set the values in the map to the zero value like it does for slices? That seems like an easy thing to get tripped up on
You can't "remove all items from the slice"; you can only change the length to 0: "slice[:0]".
Go 1.21 Release Candidate
121–130 of 236 posts
Re: Go 1.21 Release Candidate
#122Earlier quoted context omitted.
Indeed it's in "golang.org/x/exp/slog"
https://pkg.go.dev/golang.org/x/exp/slog#hdr-Levels seems to fall into the same trap that drives me _starkraving_ about the 18,000 different(!) golang logging packages: there doesn't seem to be a sane way of influencing the log level at runtime if the author doesn't have the foresight/compassion to add a command-line flag or env-var to influence it. A similar complaint about the "haha I log json except this other dep…
Re: Go 1.21 Release Candidate
#123I enjoy Go so much. It is almost perfect language for getting things done, but I still can't understand some design choices. Does someone knows why Go uses env variables (like GOOS and GOARCH) instead command line arguments?
Re: Go 1.21 Release Candidate
#124Earlier quoted context omitted.
That doesn't seem to be true, unless I'm misunderstanding something. https://go.dev/play/p/ymM0tD3aGYg?v=gotip Obviously these sample functions don't take into account all the intricacies of float min/max functions.
You can const x = min(a, b) assuming a and b are const.
Re: Go 1.21 Release Candidate
#125This is a big release. Lots of new packages. The language is changing
It is a big release, and the number of new stdlib packages (4) is relatively high for a Go release. That said, apart from the addition of some minor builtins (min, max, clear), the language isn't changing. That happened back in 1.18 with the introduction of generics.
Re: Go 1.21 Release Candidate
#126Huh, I'm glad to see generic Min/Max functions, but the fact that they're built-ins is a little odd to me. I would have expected them to put a generic math library into the stdlib instead. The fact the stdlib math package only works with float64s has always struck me as a poorly thought out decision.
What sort of use case do you see for non-float64 math operations in a Go application?
Personally I try to avoid using floats for calculations if I can (unless it's obviously warranted), I've encountered far too many foot guns from using them, though honestly the same can be said about integers in some situations too. I wish there was a package like math/big that was more accessible, I find the current interface for it pretty abysmal.
Re: Go 1.21 Release Candidate
#127Earlier quoted context omitted.
You can const x = min(a, b) assuming a and b are const.
I can't think of a use case for that. If all the inputs are consts, then you know the values and can just assign it to be the less of a or b. Am I missing something here?
It helps to document intent.
Probably not so useful for min, but it can be more useful for more complex functions.
Re: Go 1.21 Release Candidate
#128Earlier quoted context omitted.
As a non-developer who has only gone as far as "hello world" in Go, I'm baffled by the idea that the log/slog thing is new - that seems like an absolutely basic language feature. TBH I'd say the same about min/max, but could forgive those being absent since Go isn't known for being numerically-focused...
> that seems like an absolutely basic language feature Most languages have no logging "system" built in at all. Honestly it's really quite rare.
Re: Go 1.21 Release Candidate
#129Earlier quoted context omitted.
I don't think Multipath TCP has been tested in enough environments to become the default yet. It's compatible with TCP, yes, but it's mostly useful for e.g. mobile devices that have multiple links like Wi-Fi and 4G, and it lets users to maintain TCP connection to a certain service even when moving across networks. Go seems to be server-oriented first, and there are some potential downsides to multipath TCP in a datac…
"In a future Go release we may enable Multipath TCP by default on systems that support it." This could be five years from now. Or maybe never.
Re: Go 1.21 Release Candidate
#130Earlier quoted context omitted.
https://pkg.go.dev/golang.org/x/exp/slog#hdr-Levels seems to fall into the same trap that drives me _starkraving_ about the 18,000 different(!) golang logging packages: there doesn't seem to be a sane way of influencing the log level at runtime if the author doesn't have the foresight/compassion to add a command-line flag or env-var to influence it. A similar complaint about the "haha I log json except this other dep…
That bugs me too. I consider it a red flag for a library to log to anything except a ` log.Logger` passed in from the caller. Now I'll expand that to include a ` slog.Logger` as well. If the library is logging directly to stderr or stdout, that is a sign that it probably has other design issues as well.