2 ms·
I'd make it a keyword at least (things would be fine with lots of warning, just call it Go 2 and accept the incredibly minor breakage), so you don't spray neste
by grey-area 7y ago
I'd make it a keyword at least (things would be fine with lots of warning, just call it Go 2 and accept the incredibly minor breakage), so you don't spray nested brackets everywhere.
f := try os.Open(filename)
Or perhaps better, leaving the working code alone and concentrating on the bits people actually don't like (the error handling boilerplate).
f, err := os.Open(filename)
check(err)
There is no need to attempt to put the error handling on the same line as the function, and if you do it just gets in the way of reading the actual function call, permits nesting etc. This approach would have the advantage of leaving normal code alone and only touching the error handling.
I'd even be fine with check as a new builtin function, since it would typically sit alone anyway, I don't think it needs to be a keyword, whereas with try I think all the brackets will make it harder to read.
In fact I've just found a variant of this proposed here:
https://github.com/golang/go/issues/32811 https://github.com/golang/go/issues/32811