On Friday, June 28, 2019 at 5:44:01 PM UTC-7, Tyler Compton wrote:
>
> If anyone hasn't seen it, an issue with the "proposal" tag was created 
> earlier on the Go issue tracker titled "Proposal: leave "if err != nil" 
> alone?" (here <https://golang.org/issues/32825>). This issue seems to 
> have resonated with a lot of people, which may be an important data point 
> when considering the try proposal <https://golang.org/issues/32437>, but 
> I was surprised to see how poorly the discussion has gone. There are quite 
> a few "me too" comments, a few image-only posts, some less than stellar 
> personal conduct, and overall not a lot of nuanced discussion. I feel that 
> perhaps these kinds of anti-proposals should be discouraged because they're 
> inherently reactionary, which seems to get the discussion off on the wrong 
> foot.
>
> That said, this anti-proposal attracted a whole new group of Go users that 
> I don't remember from the original try proposal discussion, which was 
> mostly dominated by ten or twenty participants. The discussion was better, 
> but the number of active users was much smaller. I wonder if there's a way 
> to better engage a larger portion of the Go user base while still 
> encouraging healthy, technical discussion.
>

I've noticed that `go fmt` generally format funcs into multiple lines, but 
does allow one-liners. That is, it will leave a function like this as just 
one line:

func statusUpdate() string { return "" }
 
(For more examples, grep "{ return" in the standard library.)

While I know that "one line if statements" have been discussed and 
over-discussed, I'll go out on a limb and suggest maybe `go fmt` should 
allow a "one line if" in one circumstance...are you ready for it?.... when 
the then clause contains only a `return ...`.

This means the following would be allowed by `go fmt`...

    if err != nil { return err }

or

    if err != nil { return fmt.Errorf("I like to wrap my errors: %s", err) }

This makes error handling more concise, by some lines, in those cases 
handled by the `try` proposal.  And also more concise while allowing 
wrapping or testing for error values other than nil.

It's a modest proposal in that it only saves lines of code.  It requires no 
language changes, just `go fmt` changes. This would be analogous to what 
`go fmt` already allows in one line funcs, and in my opinion would not 
negatively affect readability.  If enough folks here reach out to me 
supporting this idea, I'd submit a proper proposal.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/42b8fc5d-2f0a-4951-8ca5-0476e23fd4a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to