Our great sponsors
- SonarLint - Clean code begins in your IDE with SonarLint
- ONLYOFFICE ONLYOFFICE Docs — document collaboration in your environment
- CodiumAI - TestGPT | Generating meaningful tests for busy devs
- InfluxDB - Access the most powerful time series database as a service
The Go programming language
Those are good points about some of them being nontrivial.
Though part of why they’re optimized and in the stdlib in the first place is because they’re such common patterns. So without them people would end up writing trivial, unperformant, custom versions. So now that more routines can be moved into the stdlib, they can benefit from optimization later.
(I’m not sure how much the maps routines specifically can be optimized, but stdlib routines routines can generally be more aggressive with unsafe or asm or being coupled to the runtime and its quirks, like bytes.Clone, strings.Builder, etc.)
And there are still plenty of ubiquitous patterns that have been worth including in the stdlib even if they’re usually just simple loops that aren’t very optimizable. Like strings.Index is an easy loop to write, but it comes up so often. Or strings.Cut is basically just an if-statement. But it makes code clearer about its intentions; and optimizations to these down the road benefit everyone.
It’s also true that maps.Keys and maps.Values allocate slices, and that you could avoid this with a loop, but strings.Split, bytes.Split, regexp.FindAll, os.ReadDir return slices and are still worthwhile as opposed to specialized iterators for each one. As with any code, you’re conscious of memory allocations where it counts, and optimize as needed.
In fact, now that generics make it possible, the Go team has discussed using iterators (https://github.com/golang/go/discussions/54245), which would benefit strings.Split even further in addition to all the other slice-returning functions.
So generally you have three options for those slice-returning functions:
- Custom inline loop for some of them. More verbose, will probably be naive and not benefit from stdlib optimizations.
VictoriaMetrics: fast, cost-effective monitoring solution and time series database
No. I suppose, maintainers of popular open source projects couldn't justify introducing generics into their code. This is exactly my story - I was actively seeking places in VictoriaMetrics codebase, which could benefit from switching to generics. Unfortunately, not a single place has been found yet. The was a promising place for generics , but it has been appeared that it is better from readability and maintainability PoV to use plain old interfaces instead.
Clean code begins in your IDE with SonarLint. Up your coding game and discover issues early. SonarLint is a free plugin that helps you find & fix bugs and security issues from the moment you start writing code. Install from your favorite IDE marketplace today.
A Golang lock-free thread-safe HashMap optimized for fastest read access.
Glad to see this make it into the core.
I've been using this library for ages now...
Always entertains me to see developers write all the lock/unlock code when they could just use that.
Get cryptographically random bytes on various operating systems.
To get cryptographically grade randomness you can use one of these C functions:
BSD, newer macOS, and GNU libc: int getentropy(void buffer, size_t length);
Linux 3.19+: ssize_t getrandom(void buf, size_t buflen, unsigned int flags);
iOS and macOS 10.7+: int SecRandomCopyBytes(SecRandomRef, size_t, uint8_t );
Fuchsia: void zx_cprng_draw(void* buffer, size_t buffer_size);
Any *nix: Read from "/dev/random" (or "/dev/urandom" under the assumption that your system has already enough entropy).
Windows: There are different functions/libraries depending on the Windows version and some of them are a complicated multi-step mess.
Some time ago I wrote a C library that abstracts that away just for fun: https://github.com/panzi/portable_get_random
A small library to handle CLI commands/subcommands (by cpuguy83)
Tacking on generics on a working code base is difficult.
I effectively used it in this little experimental CLI library: https://github.com/cpuguy83/go-cli/blob/main/command.go
It's pretty simple, but the nice thing is it can use any flag library you want (stdlib flag package, pflag, whatever).
The Prometheus monitoring system and time series database.
Well there’s this: https://github.com/prometheus/prometheus/pull/11054
Minimalistic configuration management (by holocm)
That's not the same. `go test -c` builds a binary that runs your tests, whereas (if I understand correctly) the new thing builds a binary that runs your main(). If it works as I understand, that would be fantastic because then I could get rid of this monstrosity: https://github.com/holocm/holo/blob/master/main_test.go
ONLYOFFICE Docs — document collaboration in your environment. Powerful document editing and collaboration in your app or environment. Ultimate security, API and 30+ ready connectors, SaaS or on-premises
Anyone had a success story of replacing C++ with Go?
6 projects | reddit.com/r/golang | 4 Dec 2022
How i can determine S3 Bucket size about Prometheus with Thanos Sidecar??
3 projects | reddit.com/r/kubernetes | 14 Jul 2022
Securing Google Managed Prometheus UI
2 projects | reddit.com/r/PrometheusMonitoring | 28 Apr 2022
Data replication in Prometheus
2 projects | reddit.com/r/PrometheusMonitoring | 24 Aug 2021
Searching for advanced resources about mmap-ing in Go! Any books/papers/docs?
2 projects | reddit.com/r/golang | 13 Jun 2021