Make error handling less verbose with Zig %% operator and %return expression?

110 views
Skip to first unread message

Nicolas Grilly

unread,
Oct 17, 2017, 5:09:33 PM10/17/17
to golang-nuts
I just read about Zig, a new programming language designed to replace C.

The error handling philosophy is very similar to Go: control flow in general and error handling in particular is explicit. Zig has even a defer statement inspired by Go ;-)

I noticed that Zig provides a %% operator and %return expression meant to make error handling less verbose:


I'd be curious to know if something similar would be possible in a future version of Go?

Bryan Mills

unread,
Oct 17, 2017, 10:50:32 PM10/17/17
to golang-nuts
There are lots of similar proposals in the issue tracker.
Of those, https://golang.org/issue/21161 seems to have the most traffic.

prade...@gmail.com

unread,
Oct 17, 2017, 11:39:15 PM10/17/17
to golang-nuts
Personally it's not a verbosity issue but a readability issue 99% of the time.

if go fmt would just keep the whole if statement on a single line it would already alleviate some of the pain of having to read 
a codebase ridden with error handling code.

    if foo,err = DoIO();err!=nil{return err }


if less painful to read than having to deal with 3 * errorHandlingCode lines

    if foo,err = DoIO();err!=nil{
       
return err
     
}



which is annoying noise. when it's 5 to 10 lines of that stuff in a function.

Nicolas Grilly

unread,
Oct 18, 2017, 5:34:07 AM10/18/17
to golang-nuts
On Wednesday, October 18, 2017 at 4:50:32 AM UTC+2, Bryan Mills wrote:
There are lots of similar proposals in the issue tracker.
Of those, https://golang.org/issue/21161 seems to have the most traffic.

Bryan, thanks for the link. I wasn't aware of Ian's proposal.
Reply all
Reply to author
Forward
0 new messages