Hacker News new | ask | show | jobs
by groestl 2869 days ago
> I've heard from many devs that Go was the reason that made them appreciate proper error handling.

I agree that in some way, this is actually a good reason to support Go's tedious way of handling errors.

Yet, it's akin to avoiding functions (because stackframes are magical), or "for" loops (because their condition block is magical), or threads (because: magic). There is only so much a non-toy programming language should compromise in order to accomodate beginners. People may draw different lines here, but Exceptions (in garbage collected languages) are so completely unmagical, that the line should definitely not be drawn here. In fact, they do exactly what return nil, err does, thousands of times, over and over. In Go you can enjoy writing that code yourself. Also, Go's language designers accepted defeat when they had to add panics. I bet that beginners now just make the mistake of ignoring them instead.

1 comments

My first (real world) exposure to exceptions was Python. I was a bit above novice. I would write some code, run it, and it would die of some horrible exception. I would catch that exception, try again, and die again. Lather, rinse, repeat. Eventually I would wrap everything in try-except blocks. Talk about verbose; tab indents everywhere. You can often end up handling exceptions somewhere not immediately close to the call that failed.

I liked when I started with Go (mostly due to concurrency primatives, but errors were nice too). In my day job, many of the errors have a need for custom handling and I get that for "free" in Go and I am never surprised by a program crash because I failed to read the docs on a function and what exceptions it may throw (or undocumented exceptions it may throw due to one of its dependencies). I can see right in the signature that I have an error to potentially handle.

Maybe you would like the concept of "checked exceptions" from Java? Exceptions are part of a method signature and not handling them is a compiler error, but they're still exceptions, not return values.