4 ms·
> Go not having exceptions is a definite plus for the language. Adding them would be a change for the worse, not an improvement. I disagree (I'm from the Elixi
by pmarreck 10y ago
> Go not having exceptions is a definite plus for the language. Adding them would be a change for the worse, not an improvement.
I disagree (I'm from the Elixir/Erlang "code the narrow happy path and accept failure as quickly as possible" camp) and want to see your empirical data that discarding exceptions was a good design decision. Because to me it seems like you would spend a lot of time writing unnecessary boilerplate code to check for errors everywhere (if you bother checking at all... and if you don't, you are begging to get into an inconsistent runtime state which could lead to extremely hard-to-trace bugs)
It is my informed opinion that all unexpected states are bad and should be logged and killed/restarted from a known state ASAP. (Basically, the Erlang philosophy.)
Here is my data: Here are the most-used words in Go https://anvaka.github.io/common-words/#?lang=go https://anvaka.github.io/common-words/#?lang=go ("if err != nil return err," anyone?) and here are the most-used words in Elixir https://anvaka.github.io/common-words/#?lang=ex https://anvaka.github.io/common-words/#?lang=ex . Sure seems like a lot of Go code is written to handle these "exceptions" they're not having! ;)
I didn't actually come here to debate Go, but statements like yours without any evidence to back them up are basically a religious belief and absolutely nothing more.
- azinman2 10y agoYou have errors, which functionally can be considered equivalent (yes small differences here and there but from a programming standpoint it's more like java forcing you to try/catch due to the multiple return values).
- pmarreck 10y agoExcept that I'm forced to try/catch on every line that can possibly produce a runtime error. If you were selling this language to me, how would you explain writing 33% more code to do the same business logic, just to handle errors, over something like Elixir with its rather astonishing uptime and response rate and almost no boilerplate error-handling code? For the backend of an API or webserver, hypothetically.
- azinman2 10y agoSo I don't know elixir, but but reading up on it the main different seems to be that you can silently ignore errors? You can do the same thing in Go, except it's demarkaed by assigning the error to _. Not sure what the main difference is otherwise?
- pmarreck 10y agoAny errors crash the node (they are NOT silent, that's the whole point!) and get logged and then restarted by the supervisor node in well under 1 ms. In the event of too many restarts in too short a time, the supervisor is restarted by ITS supervisor (supervision hierarchy). In this way you only have to code the happy path and walk the "known states" while noting frequent sad paths/"unknown states". You can then elect to handle them in your code.
- azinman2 10y agoYou can still have fatal paths that don't ever get solved, or some large % like that. Running the Go process under something like supervisord would give you the same effect.. it's not clear why this is so different, or why this needs to be at the language level. In either case, you should be handling errors.
- pmarreck 10y agoTrue, I guess. Just found this comparison which is at least interesting: https://www.slant.co/versus/126/1540/~golang_vs_elixir https://www.slant.co/versus/126/1540/~golang_vs_elixir
- HeyImAlex 10y agoRust uses error values and its error handling is pretty terse (and more type-safe), so this is more of an indictment against go than error values in general.
- pmarreck 10y agoWhy am I getting downvoted for empirical data? That's at least an informed opinion with evidence. If 33% of your code is error-handling in 1 language, and in another language it's 2%, and both languages are equally performant and have similar logic, then how is that not bad? That's 31% more code to do the same work!
- cdelsolar 10y ago"If you bother checking" - yes, you absolutely must check, and consider the repercussions of every error. This results in much better functioning, more stable, and easier to reason about code than blanket exceptions.