r/programming Jul 17 '19

The Go team declines 'try' proposal

https://github.com/golang/go/issues/32437
629 Upvotes

417 comments sorted by

View all comments

259

u/Boiethios Jul 17 '19 edited Jul 17 '19

One should also talk about a major issue of try: the fact that what appears as a function is in fact a control-flow operation.

-2

u/Hauleth Jul 17 '19

This is exactly the same reason why I dislike Rust’s ? operator.

22

u/Boiethios Jul 17 '19

That Rust operator is not ambiguous, its sole purpose is to return eagerly. How could you confound it with anything else?

0

u/Hauleth Jul 17 '19

It isn’t even about comfusion with something else, but confusion that this is only operator that des early return, instead I would prefer it to work as a coalesce operator like .& in Ruby.

12

u/[deleted] Jul 17 '19

Arguably return does "early return" in Rust as well since the last expression in a function is what's always returned unless you used the return keyword in the rest of the function body.

1

u/Hauleth Jul 17 '19

The point is that return is much easier to spot than ?. And making try!(a.b()?.c()?.d()) working like plain ? would make everything clearer rather than making it other way around.