Stories
Slash Boxes
Comments

SoylentNews is people

posted by martyb on Wednesday July 17 2019, @05:37PM   Printer-friendly
from the No!-Try-not.-Do,-or-do-not.-There-is-no-try.-YODA dept.

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.


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 2) by DannyB on Wednesday July 17 2019, @07:36PM (9 children)

    by DannyB (5839) Subscriber Badge on Wednesday July 17 2019, @07:36PM (#868176) Journal

    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.
    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2  
  • (Score: 2) by All Your Lawn Are Belong To Us on Wednesday July 17 2019, @07:59PM (3 children)

    by All Your Lawn Are Belong To Us (6553) on Wednesday July 17 2019, @07:59PM (#868185) Journal

    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)

      by tangomargarine (667) on Wednesday July 17 2019, @08:52PM (#868212)

      If you want to goto outside of a function then why not use a function call or a GOSUB.

      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: 1, Redundant) by DannyB on Thursday July 18 2019, @01:10PM

      by DannyB (5839) Subscriber Badge on Thursday July 18 2019, @01:10PM (#868477) Journal

      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)

    by tangomargarine (667) on Wednesday July 17 2019, @08:55PM (#868214)

    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)

      by DannyB (5839) Subscriber Badge on Thursday July 18 2019, @01:12PM (#868478) Journal

      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)

        by tangomargarine (667) on Thursday July 18 2019, @02:50PM (#868511)

        If you can jump to any label within a certain construct, how is that not a GOTO ?

        How many more times do I have to say this?

        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.

        Wikipedia:

        GoTo (goto, GOTO, GO TO or other case combinations, depending on the programming language) is a statement found in many computer programming languages. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control. The jumped-to locations are usually identified using labels, though some languages use line numbers. At the machine code level, a goto is a form of branch or jump statement.

        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

          by DannyB (5839) Subscriber Badge on Thursday July 18 2019, @05:04PM (#868588) Journal

          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

        by tangomargarine (667) on Thursday July 18 2019, @02:54PM (#868512)

        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?"