Hacker News new | ask | show | jobs
by codr4 2810 days ago
Go's resistance to exceptions looks like Steve Jobs and his one button mouse from here. It's not like renaming them to panic/recover fooled anyone outside of the Pike reality distortion field. Sometimes unwinding the stack is exactly what you want. Optional types are nice too, but that's more for things that are intentionally missing. I have yet to see anything here that's an improvement over just doing the obvious thing.
5 comments

I'm not sure about that. Rust's use of a Result type instead of exceptions is one of my favourite things about Rust. Before I'd used it, I'd not realised how many reliability issues in other languages were caused by overlooked exception cases.

Exceptions are great when you don't want to handle errors properly, but when you do want robust error handling I find the "return a value" pattern much better. Notably even C++ is looking into implementing this!

> I'm not sure about that. Rust's use of a Result type instead of exceptions is one of my favourite things about Rust.

It works because Rust has pattern matching and generics as well. Just having a Result type isn't going to help with error handling much, and Go is not getting generics Rust style nor pattern matching any time soon.

Let us be reminded that Go errors as values are purely a convention, nothing in the language mandates their use. On the other hand panic/defer/recover are language constructs.

Exactly the same with Scala.

Option types demand pattern matching and similar techniques for working with those types. Otherwise you just have "if (x.isDefined) a else b" blocks of code everywhere.

They are not overlooked, they are better handled further up the call stack. And not having the option to forward them implicitly is a step back, not forward. There's no way to make a programming language better by forcing users to do anything, in many cases the user will have more experience than the person implementing the language. A programming language is a tool, predicting and dictating how the tool is to be used is missing the point.
I don't think forcing is the right word.. I've noticed that languages where the "right way" is the path of least resistance the code quality stays high even if a lot of people with varying levels of expertise contribute
Well in my experience golang Is a long ways from this anyway ... It's a very prescriptive language
Forwarding errors upwards is one character in Rust (?). IMO that is pretty much the perfect balance between forwarding errors easily and explicitness.
> There's no way to make a programming language better by forcing users to do anything

Sure there is, many important language features boil down to forcing users to do the right thing (not necessarily the easy thing).

In highly concurrent languages like Go, there’s not always a meaningful stack to unwind, and you end up having to pass error values around anyway. So I can easily sympathize with the decision to stick with one mechanism for error handling.

> many important language features boil down to forcing users to do the right thing

this just causes the users to use another language for their projects instead

And fixing the output of that is where the rest of us often profit from.

A language that provides a lot of freedom when it comes to expressiveness without offering much in the way of constraints (to truly convey the purpose of a given piece of code with the least amount of ambiguity possible) will almost definitely turn into utter crap in contact with junior developers, and will often be a source of pain for more experienced ones once the project is nontrivial, whether they realize it or not.

Do you see any problems with optimizing everything we do for junior developers? I mean, most of us aren't, and it would be really nice if someone gave a crap about wasting our lives as well.
I don't think that Go will move to exceptions. Sure, panic/recover are renamed exceptions (very similar to Rust panics, btw), but standard library and community libraries uses errors, so you'll use them anyway (unless you want to rewrite or wrap the world which is possible, I guess, in automated way and that's a provoking thought!).
The standard library uses panic/recover to sort of implement exceptions here and there. It's a pretty serious case of do as I say, not as I do.
Those instances are being fixed.
Exceptions are like cancer. You never know when you're going to get one, you have no idea how to handle them or if you should handle them, and they produce fatal bugs at unexpected places.
They are used for exceptional problems, expecting one doesn't really make any sense.

Of course you do, that's the point; to unwind the stack until you reach code that knows how to handle the error.

Cancer, really; is that you Gordon?

Errors are not exceptional problems.
I didn't say that, I said that exceptions are used for exceptional problems. Expected errors like missing values are better handled using optional types. I find the one ring to rule them all attitude less than constructive.
I'll annonance my bias towards go. But from what I understand, allowing exceptions allow for more complex code parhs. Whereas explicit error handling forces you to handle it in the moment.
Yep yep, sounds good.

Problem is you're not handling errors, you're wasting precious energy shuffling errors to code that knows how to handle it; which is exactly what exceptions could do for you. The end result is the same, except it takes more effort and the code looks like crap.

Exceptions are really no less complex than return values, and they do not (easily) play nice with asynchronous and lambda/functional programming models. Witness their near abandonment in JavaScript for example.

I like Go mostly the way it is. Its simplicity is genius. Anything added should be considered with great care.