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 DannyB on Wednesday July 17 2019, @07:36PM (9 children)
According to this [geeksforgeeks.org]. You can use continue instead of break. You can jump backward as well as forward. You do not have to do it within a switch statement.
It is restricted to be within the same function. But I do not see any obviously useful porpoise for being able to 'goto' outside of the current function.
The lower I set my standards the more accomplishments I have.
(Score: 2) by All Your Lawn Are Belong To Us on Wednesday July 17 2019, @07:59PM (3 children)
If you want to goto outside of a function then why not use a function call or a GOSUB. Porpoises like to travel with subs after all.
(And more seriously, I suppose if you wanted to terminate a running function and purposely drive yourself somewhere other than what called it you'd want a goto.... otherwise why not jump to the bottom of your function and let it terminate naturally... ? )
This sig for rent.
(Score: 2) by tangomargarine on Wednesday July 17 2019, @08:52PM (1 child)
The obvious answer is, because that doesn't let you discard your context. But good practice means that should be a rare desire anyway.
If you absolutely feel you *need* a goto in Java, you can somewhat cumbersomely simulate it with a try-catch and purposely throwing an Exception. Which is also basically a comefrom [wikipedia.org] :)
"Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"
(Score: 2) by All Your Lawn Are Belong To Us on Wednesday July 17 2019, @10:19PM
Indeed. But if you execute COMEFROM, should you not also execute an IFKTR [faisal.com] as well?
This sig for rent.
(Score: 1, Redundant) by DannyB on Thursday July 18 2019, @01:10PM
I would replace all GOTO with GOSUB for reasons of artistry and fashion.
The lower I set my standards the more accomplishments I have.
(Score: 2) by tangomargarine on Wednesday July 17 2019, @08:55PM (4 children)
It doesn't "jump backward" any more than to the top of the nested block you're in, though. To be "really just a goto" you need to be able to jump to an arbitrary point in execution, which would include across function boundaries. It may not be super *useful* but let's not confuse our definitions by saying this is "basically goto" when it has all these restrictions built into it.
"Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"
(Score: 2) by DannyB on Thursday July 18 2019, @01:12PM (3 children)
If you can jump to any label within a certain construct, how is that not a GOTO ?
Would any GOSUB smell as sweet?
The lower I set my standards the more accomplishments I have.
(Score: 2) by tangomargarine on Thursday July 18 2019, @02:50PM (1 child)
How many more times do I have to say this?
Wikipedia:
Jump instructions [wikibooks.org] are literally "resume execution at line X". They don't care about context at all.
The Java goto is a strict subset of gotos as generally understood, since the...compiler (or whatever it is they call the thing in Java that makes bytecode) checks the context where the label you're trying to jump to is located.
Gosubs aren't gotos either. If it returns, it's a function call.
"Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"
(Score: 2) by DannyB on Thursday July 18 2019, @05:04PM
I do understand the difference between gosubs and gotos, once long ago programming WANG BASIC and TRS-80, etc.
I've never needed to use a goto in Java. (Or C, or Pascal for that matter). Structured programming really does eliminate goto's.
So I looked more closely at the link I gave, and I see that in Java the labels are more limited than I realized in where they can be placed. Surprise. But I've never need to use a goto since spring 1982. After that it was all Pascal and some bits of x86 and 68000 for me until the early 1990s.
The lower I set my standards the more accomplishments I have.
(Score: 2) by tangomargarine on Thursday July 18 2019, @02:54PM
And you can't jump to *any* label within a function either. As I said.
void foo()
{
label A:
code
code
code
label B:
while(true)
{
goto _;
}
}
Putting "B" in the blank will work. Putting "A" there will cause the compiler to yell at you.
"Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"