Hacker News new | ask | show | jobs
by hedora 486 days ago
Exceptions are a terrible idea.

However, I strongly prefer rust error handling to Go.

go:

   (res, err) := foo()
   if err != nil
       return err
   (res, err) := bar(res)
   if err != …
Equivalent rust:

   let res = bar(foo)?)?;
I think go should add the ? sigil or something equivalently terse.

Ignoring all the extra keystrokes, I write “if err == nil” about 1% of the time, and then spend 30 minutes debugging it. That typo is not possible in idiomatic rust.

5 comments

I don't want ")?)?;" in Go. I prefer readable syntax rather than symbol soup.

In Rust, there are cases where I have seen at least 8 consecutive symbols. Not a fan of that.

99% of people who never written go will know what the go version does
Then... look it up?

If someone saw "go funcName()" for the first time, would they know how it worked without looking it up?

Prob not but I would still argue go is way easier to read than Rust for someone who does not know either.
and 99% of the people will learn the ? shortcut in fraction second. it's just like every other operator ffs. are you dumbfounded everytime you see the channel operators (->) ? noone takes a second thought to them after the first couple of seconds when they encounter them the first time.
This would drive me nuts to write as a Scala dev, but I can see merit to the philosophy. Go basically lowers the ceiling to raise the floor. Meanwhile Scala can let you glimpse the heavens but has no problem showing you the deepest, darkest pits of hell.
> Exceptions are a terrible idea.

I hear people say this frequently, but don't ever hear people actually state the case.

My experience is that particularly for web back-end exceptions have been incredibly useful, but I'm interested in the counter view.

equivalent exceptions:

    let res = bar(foo());
(I think you meant: let res = bar(foo()?)?;