Re:Proposal: A built-in Go error check function, try
by umurgdk on Wednesday June 05, 2019 @01:09AM
(#20101650)
I am strongly against this. `try` seems exactly like a function yet it is not acting like a function at all. People wouldn't expecting calling a function may return from the caller. And there is a reason why golang doesn't have macros. With macros all kind of craziness would be possible, and would really difficult to read different kind of projects' code.
[ Parent
| on HN ]
Re:Proposal: A built-in Go error check function, try
by gnud on Wednesday June 05, 2019 @03:31AM
(#20102229)
Agreed - I thought this looked pretty reasonable, if a bit parenthesis-heavy, until I saw this example:
func printSum(a, b string) error {
fmt.Println(
"result:",
try(strconv.Atoi(a)) + try(strconv.Atoi(b)),
)
return nil
}
When you nest the calls to try inside another method call, like this, the control flow really becomes obscured.
Re:Proposal: A built-in Go error check function, try
by lifty on Wednesday June 05, 2019 @02:46AM
(#20102057)
I dislike this proposal for the same reason. Looks like a function but does not behave like a normal one. I personally don't mind the verbose error handling in go and I think it's clear and easy to follow.
Re:Proposal: A built-in Go error check function, try
by 0815test on Wednesday June 05, 2019 @09:06AM
(#20103926)
> People wouldn't expecting calling a function may return from the caller.
Why? This is essentially the same as the reset/shift pattern in e.g. Scheme - when you call shift from within a reset call, that might cause you to return directly from that. And that is a rather well-behaved pattern which composes quite well, it's nothing like the inherent weirdness of, e.g. call/cc.
Re:Proposal: A built-in Go error check function, try
by pjmlp on Wednesday June 05, 2019 @02:06AM
(#20101887)
Go kind of has macros, like everything else, Go's solution to first level features in other languages is called //go:generate.
Re:Proposal: A built-in Go error check function, try
by thisgoodlife on Wednesday June 05, 2019 @06:24AM
(#20102933)
Do you think it would be better if it was called try_or_return?