When is v2 draft design reality especially for error handling

Hi dear community,

So as many of you know, lots of situations gets you into verbose and reperative statements like

if err != nil { return err} 

for further propagation from your function that has some identical signature like:

func(...) error

When reading the draft Error Handling — Draft Design , there have been many efforts to introduce a keyword into the language that somehow simplifies and erases the repatativity and verboseness those situations can get.

For example Zig’s try is nice and Rust’s “The ? Operator Shortcut<Result>?.

Those are great examples, more than 5 years have passed since the initial of this draft, design and i get it, introducing new keywords and manners to the language is difficult I got it, I wouldn’t also be able to understand it as I have never build or designed any language, but can someone explain why this is taking so long?

Go is also generally designed for simplicity and teams, easy code base, but those situations can make if err ; return err very repetitive annoying and your code ugly. When comes this fix that solves this? It doesn’t look like crazy rocket science and it can be backward compatible so when will we see it?? The feature asked seems like it can be implemented with backward compatibility in mind, something the Go team strictly adheres to.

Go was a language I learnt to get more low-level although Go is a high-level language, situations can get you more into low-level stuff compared to Typescript. After Go I read the Rust book and after completing it, I went over to the Rust async book which generally gives teachings of how OS’s implement async behind the scenes and how it works. I then made some crates and been very comfortable with Rust too.

I really like Go and Rust alot, but Rust is multi-paradigmatic, making me wanting to have expressiveness in Go as well but sometimes I am limited be the lack of modern keywords or language patterns. However that is good, Go has to stay simple, but the lack of try or Rust’s ? for error handling or such amazes me…

I don’t believe this will ever be adopted. There have been many proposals over the years, but I don’t think anybody will ever agree on a new approach. See this recent issue created by Ian Lance Taylor:

Note the number of downvotes. And see subsequent discussion:

It is, more or less, because most gophers don’t want this change. I participated in the discussion on this and people are pretty set in their ways it would seem. For better or worse.

1 Like

Hi, thanks for your response.

Even if the majority doesn’t want it, it looks like a handy new keyword if it existed when it has backward compatibility. It’s up to the programmer whether they use for example the try keyword or verbose and repetitive returns statements.

Currently I am mostly using Rust cuz it is an amazing language and so expressive. I just only use Go when I wanna make something fast, Go has an amazing development speed and it’s still pretty performant on the runtime for most common cases

Propably final statement.

And I do say that I agree with them. :+1:

Furthermore I personally don’t have those

if err != nil { return err}

so much, because if you do this you have to decide what to do then?!
Do you have a condition switch in the parent function?

It is better to handle the error right in place. I mean at least you want to have a log on what failed?

2 Likes

I do partially agree, however if there is a language that really wants the developer to handle errors, then it’s called Rust.

Then the real question comes to the mind, why do they have the ? operator for error handling. Because sometimes it is needed to further propagate some error to the caller and leave it up to their handling. If the function body that propagated was too verbose it would’ve been annoying and that’s sometimes the case with Go.

I saw in the proposal they had a prototype and design for implementing the ? operator, too bad they dismissed it.

Let me say this is my personal opinion and I can make some bias as i like Rust alot and it’s multi paradigmatic language maybe I am looking too much from the top into the situation

Just my two cents, I agree it is verbose to write err := … all the time, but for teams without experience in programming language it is easy to understand what to do, and guide people to create something easy to maintain. It is easier to use Go to write sophisticated scripts than to write them in Bash.

1 Like

Wishing Rust would bake the (crosscompile supportive) linker into rustc, a la go.

Wishing Go could automatically loop over its available target platforms, without requiring external scripting.

Go error handling has many excellent qualities. Boilerplate is not one of them. That was a mistake in Go 1. A keyword would bridge the gap between insane people and reasonable people. You don’t have to use the keyword. I do, I like being able to find my own code among the hundreds of I/O error checks for basic standard library operations.

How consistent a language is across many code bases is a very important factor for a language. Sure nobody cares how a single developer writes their own little program at home, but as soon as you enter the world of collaboration like open source, libraries or the go standard library it is very important. In my Java Days there were a myriad of formatter options and style guidelines - tabs vs spaces, where the brace is and so on. With each new code base I needed time to adapt to the new style and become as fast in reading the new source code as before.

With go we have a single formatter which promotes a single style - is it perfect in all situations? No - but it is consistent. The same holds true for error handling. With go source code any source code looks immediately familiar - I see where if err != nil blocks stand and know on the line before some call happens, which can fail. It is boring and consistent (I personally would even forbid the ambiguity of calling and checking in the same if clause, just to make it more consistent)

It is a trade-off how much individuality your language wants to provide versus how consistent it wants to be. One can stand on each side of this compromise, but it is wrong to say there is no trade-off by including this feature.

1 Like