4 ms·
Same here with go, then Again go doesn't throw!
by what_hn 20d ago
Same here with go, then Again go doesn't throw!
- xdavidliu 20d agosurely 'throw a npe' means something very similar to something that Go does
- mahboi 20d agoIt's a panic in Go, not an exception. In practice that's usually a whole process crash. You can catch panics and kinda use them like exceptions, but it's not conventional.
- samus 20d agoSo the whole webserver dies instead of just a worker thread unwinding its stack?
- mahboi 19d agoOh, net/http recovers from a panic inside a handler and sends error 500. I don't know if that was always the default. Where I worked before, our own Go servers didn't recover, and it did cause outages. This is kinda bad practice. Go and Rust panics are similar, they aren't exceptions that you can safely recover from. Say there's a panic in the middle of modifying some global state like a database connection. Hence complaints about the net/http recover like https://github.com/golang/go/issues/25245 https://github.com/golang/go/issues/25245 . But I guess they decided it's worse to let servers crash from trivial mistakes.
- samus 19d agoI mean, it's a smaller issue in a K8s environment as it will just spin up a fresh pod.
- za3faran 20d agoGolang doesn't have solutions like these: * https://jspecify.dev/docs/user-guide/ https://jspecify.dev/docs/user-guide/ * https://openjdk.org/jeps/8303099 https://openjdk.org/jeps/8303099
- unscaled 20d agoSure it does: https://github.com/uber-go/nilaway https://github.com/uber-go/nilaway Not exactly the same solution as JSpecify, since it doesn't rely on annotations, but it's also more ergonomic. I'm not comparing this to "null-restricted types", since that's a draft JEP that hasn't made it even into a preview feature. Go also had multiple proposals for explicit nilability in types, and while they probably have less prospect of ever seeing the light of day compared to Project Valhalla, as things currently stand, Go is in the same position as Java: They are both extremely prone to NEPs out-of-the-box and they both have external tooling that can help you avoid them. Java null checkers have more comprehensive coverage potential compared to Go, but Go is the more ergonomic one here. You don't need a single extra annotation on your code.
- samus 20d agoThat one works pretty much the same way as NullAway, which is kinda unsurprising because of the name and because of who made it.
- unscaled 20d agoGo panics.
- gf000 20d agoIt just swallows errors, so you don't even know about it!
- mahboi 19d agoI don't get why they didn't just do !/? syntax like in Rust. Or at least make it a compiler error to ignore err returns.