5 ms·
Exceptions are only better than C style error return numbers but worse than pretty much every other model of error handling we have today.
by packetlost 3y ago
Exceptions are only better than C style error return numbers but worse than pretty much every other model of error handling we have today.
- riku_iki 3y agoThere is an opposite opinion on this
- mordechai9000 3y agoI just picked up Go and thought I might use it for Advent of Code, to help gain some familiarity. The error handling kind of threw me off, though. I am coming from typescript most recently, and I think crashing on unhandled errors is a good thing. I have bad memories of perl doing unintended things after failing to catch an error. But I am willing to go out of my comfort zone. I think I'll probably have to find some linter configuration that will squawk when an error is ignored, though. Just for my own sanity.
- jerf 3y agoThe "standard linter" in Go is https://golangci-lint.run/ https://golangci-lint.run/ , which includes [1] the absolutely-vital errcheck which will do that for you. For an Advent of Code challenge you may want to turn off a lot of other things, since the linter is broadly tuned for production, public code by default and you're creating burner code and don't care whether or not you have godoc comments for your functions, for instance. But I suggest using golangci-lint rather than errcheck directly because there's some other things you may find useful, like ineffassign, exportloopref, etc. I highly recommend using Go with linters... but then, I highly recommend using any language with all the lint-like support you can get from the very beginning of any project, so I wouldn't read too much into that. [1]: https://golangci-lint.run/usage/linters/ https://golangci-lint.run/usage/linters/
- kaba0 3y agoBased on what exactly? I do think that e.g. rust’s error handling is quite okay with proper algebraic data types, but (checked) exceptions are similarly safe and ergonomic to use. The worst is without doubt the C style, whose legacy Go happily lengthens by doing the exact same thing, but natively in the language.
- mrkeen 3y agoChecked exceptions are not ergonomic. Whatever other benefits they might have are lost when every Java developer rethrows every checked exception as a more ergonomic RuntimeException.
- kaba0 3y agoStill better than losing an error case. But java’s solution is not the most ergonomic, no one was talking about that implementation.
- packetlost 3y agoWhat checked exception implementation do you have in mind then?
- riku_iki 3y ago> Checked exceptions are not ergonomic. its about the same ergonomics as rust error handling. Its just many people don't like to check exceptions, similarly many people write python code without explicit types.