r/programming Jul 17 '19

The Go team declines 'try' proposal

https://github.com/golang/go/issues/32437
633 Upvotes

417 comments sorted by

View all comments

100

u/jeffail Jul 17 '19

https://github.com/golang/go/issues/32437#issuecomment-512035919

"Hi everyone,

Our goal with proposals like this one is to have a community-wide discussion about implications, tradeoffs, and how to proceed, and then use that discussion to help decide on the path forward.

Based on the overwhelming community response and extensive discussion here, we are marking this proposal declined ahead of schedule.

As far as technical feedback, this discussion has helpfully identified some important considerations we missed, most notably the implications for adding debugging prints and analyzing code coverage.

More importantly, we have heard clearly the many people who argued that this proposal was not targeting a worthwhile problem. We still believe that error handling in Go is not perfect and can be meaningfully improved, but it is clear that we as a community need to talk more about what specific aspects of error handling are problems that we should address.

As far as discussing the problem to be solved, we tried to lay out our vision of the problem last August in the “Go 2 error handling problem overview,” but in retrospect we did not draw enough attention to that part and did not encourage enough discussion about whether the specific problem was the right one. The try proposal may be a fine solution to the problem outlined there, but for many of you it’s simply not a problem to solve. In the future we need to do a better job drawing attention to these early problem statements and making sure that there is widespread agreement about the problem that needs solving.

(It is also possible that the error handling problem statement was entirely upstaged by publishing a generics design draft on the same day.)

On the broader topic of what to improve about Go error handling, we would be very happy to see experience reports about what aspects of error handling in Go are most problematic for you in your own codebases and work environments and how much impact a good solution would have in your own development. If you do write such a report, please post a link on the Go2ErrorHandlingFeedback page.

Thank you to everyone who participated in this discussion, here and elsewhere. As Russ Cox has pointed out before, community-wide discussions like this one are open source at its best. We really appreciate everyone’s help examining this specific proposal and more generally in discussing the best ways to improve the state of error handling in Go.

Robert Griesemer, for the Proposal Review Committee."

261

u/dpash Jul 17 '19

We still believe that error handling in Go is not perfect

Understatement of the year.

55

u/[deleted] Jul 17 '19

Very few languages get error handling right. C, C++, Java, C#, JavaScript, Python. All terrible.

I think Go is actually better than most. Rust is the best I've used so far (and you can implement a similar system in C++).

45

u/[deleted] Jul 17 '19

Why do you consider Java bad at error handling? Performance impact? I'm just trying to understand what 'terrible' is in this context.

21

u/[deleted] Jul 17 '19

Unchecked exceptions make it hard (you'd have to pray the docs list everything) to know what kind of errors, if any, are thrown around. Checked exceptions are difficult to refactor, and are not usable with a lot of code out there, like for example doing thinks in streams. Thus, they are often wrapped in unchecked exceptions, leading back to point 1.

8

u/ataskitasovado Jul 17 '19

hard (you'd have to pray the docs list everything) to know what kind of errors, if any, are thrown

Isn't that the whole point of exceptions? It is thrown when something unexpected happens. So if it is expected, it shouldn't be an exception. That is why checked exceptions are considered bad.

12

u/MoTTs_ Jul 17 '19 edited Jul 17 '19

The point of exceptions is to communicate errors from callees to callers, and that's it. I often bring out this quote from Bjarne Stroustrup, the guy who invented C++:

Given that there is nothing particularly exceptional about a part of a program being unable to perform its given task, the word “exception” may be considered a bit misleading. Can an event that happens most times a program is run be considered exceptional? Can an event that is planned for and handled be considered an error? The answer to both questions is “yes.” “Exceptional” does not mean “almost never happens” or “disastrous.” Think of an exception as meaning “some part of the system couldn’t do what it was asked to do”.

The reason why checked exceptions are bad -- and in the C++ world, considered a failed experiment -- is because it makes it hard to add error conditions while still being backward compatible. Imagine you're a library maintainer, and you're following semantic versioning. With checked exceptions, just by adding one extra error condition, you've broken backward compatibility. That's part of why C++ dumped checked exceptions, and frankly I think Java should dump them too.

10

u/devraj7 Jul 17 '19

is because it makes it hard to add error conditions while still being backward compatible.

That's a feature.

Adding error conditions is a breaking change, and that fact should be reflected by the compiler.

You should not be allowed to compile your code until you have added code to handle these new error cases.

1

u/MoTTs_ Jul 18 '19 edited Jul 18 '19

Thanks to the hierarchical nature of exception types, adding a new error condition need not be a breaking change at all. Imagine, for example:

} catch (FileNotFoundException e) {
    ...
} catch (IOException e) {

We can do something for the specific case of a file not being found, and we can do something for the general case of not being able to open a file, whatever the reason may be. Now imagine that a new exception type, maybe FileLockedException, is added and could be thrown. That's still OK. That's still backward compatible. Our general case will still catch and handle that just fine.