by zaptheimpaler · 2y ago · 0 comments
Just one huge problem is that they REPEATED Java's million/billion dollar mistake with nulls. The usual way to get HTTP Headers using Go cannot distinguish between an empty header value and no header at all because the method returns "nil" for both these cases. They could've adopted option types but instead we are back to this 90s bullshit of conflating error types with valid values. If you're programming defensively, every single object reference anywhere has to be checked for nil or risk panicking now.. like why, after we literally named this a billion dollar mistake in Java, why would anyone fucking do this again?
We have helper methods in our codebase just do to this:
fn checkThingIsA(ctx) {
thing := ctx.get(thing)
if thing == nil || thing != Thing.A {
return false
}
return true
}
In any sane language this is one line: ctx.get(thing).map(|x| x == Thing.A).unwrap_or(false)
In Go, we have to make helper methods for the simplest things because the simplest 1-liner becomes 4 lines with the nil/error check after. We have 100 helpers that do some variation of that because everything is so verbose that could would become unreadable without it.I hate that they made and popularized this backwards dumpster fire of a language when we should know much better by now.
HTTP headers in Go are maps, which have a built-in mechanism for checking key existence, which distinguishes b/t empty and missing. No nils involved.
if vals, ok := headers["Content-Length"]; !ok {
// no content-length header was passed
}Like this doesn't work:
nonexist, ok := req.Header.Get("X-Custom-Header")I don't think it's fair though to characterize different points on a tradeoff curve as "stupid". If you're mad that you're forced to use a language with inappropriate tradeoffs for your context, then the right person to blame would be whoever picked it for your project to begin with.
I read the Go book by Donovan and Kernighan and I have been working full-time in Go for the last year (my work is otherwise interesting so this is tolerable). It is painfully obvious that the authors are stuck in 1986 in terms of language design. Go is C with modernized tooling (in some ways it's worse...).
It's a horrible idea that has been extremely well executed. And the idea is essentially to make a language as easy as possible for people with imperative language brain damage to learn, make it as simple as possible and then make it simpler than that.
A good example is that despite taking almost everything verbatim from C, the authors decided that the ability to specify that some variable is read-only (i.e. `const`) is "not useful", so one of the few redeeming qualities of C is simply absent from Go.
Perhaps this attitude is why function languages are not as popular as they could be.
Go as a runtime is outstanding.
Go's tooling, stability and governance are very good.
Nothing is perfect. Enter into your compromise.
As an example Rust has its flaws but it does have all the modern language niceties with great tooling, build system and a solid platform.
Please read Effective Go https://go.dev/doc/effective_go before making production software.
Well I think you should hate the fact that other language authors despite using better programming paradigm and using advancement in last 2 decades have not been able popularize their efforts enough to wipe out Go.
Go devs did what they did and made it open source. And from what I see they did not do any relentless marketing to make it popular.