The Go language will not be adding a "try" keyword in the next major version, despite this being a major part of what was proposed for version 1.14.
Go, an open source language developed by Google, features static typing and native code compilation. It is around the 15th most popular language according to the Redmonk rankings.
Error handling in Go is currently based on using if statements to compare a returned error value to nil. If it is nil, no error occurred. This requires developers to write a lot of if statements.
"In general Go programs have too much code-checking errors and not enough code handling them," wrote Google principal engineer Russ Cox in an overview of the error-handling problem in Go.
A try statement was proposed to help reduce the coding burden. Upon further reflection:
That proposal has now been abandoned. Robert Griesemer, one of the original designers of Go, announced the decision in a post yesterday.
[...] “Making an exit point of a function that isn't a return, and is meant to be commonplace, may lead to much less readable code,” said one user.
The outcome is a good one insofar as the Go community has proved able to make and withdraw a major proposal without rancour. And as for error handling, no doubt the team will, um, try again.
(Score: 2) by The Mighty Buzzard on Wednesday July 17 2019, @10:51PM (2 children)
Code legibility. Either method works just fine but having both of them potentially in the same file is a Perl-like headache waiting to happen. Handling by "if" is already in all the code and it is what people have learned to expect and use in Go, so "try" needs to fuck off.
My rights don't end where your fear begins.
(Score: 2) by janrinok on Thursday July 18 2019, @08:07AM (1 child)
It depends on what you mean by legibility. In Python you have the try:except:finally, with the latter being entirely optional. But it is very useful for cleaning up whether an error occurs or not. For example, if you are working with files you might want to ensure that all files are closed cleanly in either case. So:
I'm sure each language has its equivalent but I find the Python way clean and it keeps the structure easy to read and understand. There are also better ways of writing the above code in Python, but I've kept it this way to help those who are not used to Python code.
(Score: 2) by The Mighty Buzzard on Thursday July 18 2019, @11:03AM
By legibility I mean not having both methods in the same file and leading to confusion and bugs because of different contributors preferring one over the other.
My rights don't end where your fear begins.