> No Optional Arguments: Go only has variadic functions which are similar to Python’s keyword arguments, but less useful, since the arguments need to be of the same type.
What I like to do is to make the last arg take a struct such that you indirectly have named (and optional) arguments:
type DownloadOpts struct {
UserAgent string
TimeoutSeconds int
//...
}
func Download(url string, opts DownloadOpts) (io.Reader, error) {
...
}
//use like:
contents, err := Download("https://news.ycombinator.com", DownloadOpts {
UserAgent: "example-snippet/1.0",
})
> Never needing to pause for garbage collection could also be a factor [in Rust's greater speed compared to Go].Would be nice if the author had checked
var ms runtime.MemStats
runtime.ReadMemStats(&ms)
print(ms.NumGC)
to see if there was actually any garbage collection performed.