Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
Google Programming

Go Abandons try() Function Proposal, Citing 'Overwhelming' Community Response (theregister.co.uk) 124

Google's Go programming language will not add a try() function in its next major version, "despite this being a major part of what was proposed," reports the Register: 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.

There was therefore a proposal to add a built-in try function which lets you eliminate many of the if statements and triggers a return from a function if an error is detected. The proposal was not for full exception handling, which is already present in Go via the panic and recover functions. That proposal has now been abandoned. Robert Griesemer, one of the original designers of Go, announced the decision in a post Tuesday...

"Based on the overwhelming community response and extensive discussion here, we are marking this proposal declined ahead of schedule. As far as technical feedback, this discussion has helpfully identified some important considerations we missed, most notably the implications for adding debugging prints and analyzing code coverage.

"More importantly, we have heard clearly the many people who argued that this proposal was not targeting a worthwhile problem. We still believe that error handling in Go is not perfect and can be meaningfully improved, but it is clear that we as a community need to talk more about what specific aspects of error handling are problems that we should address."

This discussion has been archived. No new comments can be posted.

Go Abandons try() Function Proposal, Citing 'Overwhelming' Community Response

Comments Filter:
  • by Anonymous Coward

    The conclusion here is that developers really, really don't like try catch blocks. And this is probably a learned response because for upwards of 20 years, try catch blocks have been advocated by experts and included in virtually every CS curriculum going. This is one instance where you can't accuse a popular decision of being "uneducated" or "ignorant" of the the topic.

    Exceptions have been abused with abandon by certain developers, and others have been left to deal with the consequences of that fallout for

    • by freakingme ( 1244996 ) on Sunday July 21, 2019 @07:43AM (#58959786)
      I'm not sure why you refer to 'try catch blocks'. The 'try' keyword as it was proposed is not in any way related to exceptions. Golang does have something that resembles something akin to exceptions, namely panics, from which you can recover() in an upper scope.

      In Go, a function can have multiple return arguments, oftentimes the last return argument being an error object. It's a best practice that whenever you invoke a function that can return an error you check if there's an error set, and handle that, e.g.:

      foo, bar, err := foobar()
      if err != nil {
      return fmt.Errorf("foobaring faied: %s", err)
      }

      A while ago, a survey was published where 6% of respondents said that error handling could/should be improved. This was subsequently interpreted as 'we need a syntax that allows for less lines than currently required. Besides the proposed syntax, that basic premise was discussed as well. Currently, native errors don't have e.g. stack traces etc, the survey didn't differentiate any further, so it's hard to conclude if one or the other should be improved.

      • by AmiMoJo ( 196126 )

        Can you or someone familiar with the arguments against explain them? As far as I can see this makes a lot of sense.

    • by Anonymous Coward on Sunday July 21, 2019 @09:09AM (#58960016)

      I really can't agree with your post. As a veteran software developer who has maintained legacy code for a long time, I have found try/catch blocks essential to making the software robust. Proper logging within the catch blocks does worlds for helping the first tier tech support figure out what is wrong.

      I have not found the try/catch structure to be problematic, nor does it make the code unreadable and hard to maintain, as you claim. I HAVE found that poorly-done object oriented design makes the code an utter mess. Many developers who insist they understand the right way to code to an interface just wind up inserting multiple layers of abstraction that aren't needed and require you to wade through three to four times as many files as you otherwise would in order to follow execution and get your head around the code. They do NOT "keep it simple," and that is what makes the code unmaintainable.

      Try/catch blocks help keep the code simple, and I prefer them over using many branches for error checking.

      • tiers of essence (Score:2, Insightful)

        by epine ( 68316 )

        I really can't agree with your post. As a veteran software developer who has maintained legacy code for a long time, I have found try/catch blocks essential to making the software robust.

        You've vastly overstated "essential". What you mean here is "essential" in the absence of another viable method.

        Not only is this idiom non-essential, it isn't even the best idiom for writing robust code.

        Dijkstra explained this long ago. There is no such thing as an error. There are only things you can legally do and things

      • As someone pointed out, the author is a javascript weenie.

    • Re: (Score:1, Interesting)

      by Anonymous Coward

      I wonder what the next software concept revolt will be against? OOP? Agile? Build systems? The Cloud?

      Agile is no longer a software concept. It is now a management concept. I have never worked in a single agile environment that seemed to care at all about how Agile affected people below a certain level of management. 45 minute daily standup with 15 ppl? Sure why not? Doesn't waste management's time. Incredible rate of bug growth because no one with intimate knowledge of the code base has the allowance to think more than 2 weeks ahead? You bet. Agile is a perverse management practice and an absolute cancer.

      • Agile is a joke, I have worked for lots of places that touted they were "Agile". Turns out most of them were using waterfall with daily fucking standup meetings. That is not Agile. The ONE company I worked at came damn close, with nightly builds, full automated code coverage tests, build masters, KANBAN etc. but even THEY acknowledge they were not fully agile and were working towards implementing it properly. EVERYONE else was just spouting shit about being agile when they were nothing close to it. Hav
        • by jeremyp ( 130771 )

          Agile is not a joke. The thing is nobody "uses" it. In fact, when people say they are "using Agile", that's a sign they simply don't know what Agile is. It's not a method of writing software. It's a philosophy that should inform the way you produce software. SCRUM is not Agile. SCRUM is a process for developing software. SCRUM was not informed by Agile; it can't be because it was invented before the Agile manifesto was published. If you rigidly adhere to SCRUM, you are probably not being Agile.

        • I worked at a place that used their own version of Agile for development of new projects. What a nightmare. They would go off and ask the client what they wanted. Then about a month later the first version was ready with what they thought the client wanted. The client would provide some feedback on how they got it wrong and in two weeks the next version would show up after massive changes to the whole design and architecture. Repeat and repeat and repeat ...

          The problem was that they refused to sit down with

    • Re: (Score:2, Insightful)

      by Anonymous Coward


      The conclusion here is that developers really, really don't like try catch blocks.

      What an odd conclusion. I'm a developer, though not a Go developer, and I LIKE try/catch blocks. Sometimes multiple things REALLY has to happen, and if it fails, we have a problem.

      You sound like a black/white thinker. It either has to 100% solve the problem, or it's bad. Try/Catch is a tradeoff, like any other. It' a tool that you have to know how to use. Does the fact that some people miss-used try/catch mean that nobod

    • by Daltorak ( 122403 ) on Sunday July 21, 2019 @10:12AM (#58960264)

      The conclusion here is that developers really, really don't like try catch blocks.

      Okay, hold up there. You can't draw this conclusion from the actual discussion. This proposed addition to Go was never about adding try/catch blocks. Go already has a similar concept called panic/recover.

      The proposal was to allow changing this:

      f, err := os.Open(filename)
      if err != nil { return ..., err }

      into this:

      f := try(os.Open(filename))

      and that's it. There is no transferring of control to another block of code in the current or a parent function. The idea wasn't liked for a few reasons, but mainly because it hides the "return" keyword, so it's less clear that control flow is changing.

    • The conclusion here is that developers really, really don't like try catch blocks.

      Not really. The conclusion is that a vocal minority don't really like try(). I'm willing to bet if you did a census of developers you'll find an overwhelmingly positive opinion of a feature used in many languages.

      Exceptions have been abused with abandon by certain developers

      10 Come up with irrelevant statement.
      20 Post on Slashdot
      30 GOTO 10.

      Every language feature can be abused.

      Academia can't fix it. Conference talks can't fix it. Media articles can't fix it. Books can't fix it.

      Of course not. There's nothing that actually needs to be fixed. If you think you can eliminate poor developers somehow I try(sell bridge).

      • In some cases exceptions are a really good match for the types of errors generated. In other cases, they are a bad match. An experienced developer will know when exceptions are a good match, and when other types of error handling work better.
        • Exactly. Exceptions are bad because they screw up everyone else's code and the only fix is to wrap everything you didn't write with ugly boilerplate to prevent hard crashes. And all because the upstream library raises exceptions on bad mixing of language encodings that 99.99% of people doing text parsing will have something in THEIR code that fixes THEIR specific needs when it comes to bad data.

          Similar to goto, perhaps Exceptions should be considered harmful and only used when it's absolutely the best way t

    • Like program did not get broken in case of exception. Oh yes they did ! Myriad of null pointer usage detected, division by zero and other stuff. At least the try catch forced a subset of developper to "think" about what's about to happen with the catch or the fact exception/error do happen. Without it ? Far from the eyes, from from the heart.
    • by cowdung ( 702933 )

      The experiment has failed.

      Academia can't fix it. Conference talks can't fix it. Media articles can't fix it. Books can't fix it. Overburdened developers can search for "exceptions" and find everything from articulate blog posts to expletive laden Youtube videos giving voice to the frustrations of three generations of working professionals, who are tired of the failed projects, morasses of code, and undebuggable core dumps out in the real world, all consequences of flawed ideologies of software development.

      I willing to be educated in the contrary. But do you remember what there was before try/catch and exceptions?

      You say that your program failing with an Exception was bad. But I remember when the program didn't fail at all. It just kept chugging along corrupting my data. Debugging that was WAY worse than seeing an exception in my code. Forcing well defined crashes in programs has been very helpful during the las 20 years. In the previous 20 I remember lots of ignored errors, lots of return codes not checked,

      • The problem is the language not providing the tools you need. Exceptions are a loaded gun pointed at the head of your program and you have no idea where they are going to come from, if any will at all. Failure to check return codes is the end programmer's fault and they'll learn sooner or later. Failure to catch exceptions is everyone's problem. If any dependency anywhere in your project throws exceptions, now EVERYONE needs exception handling code and I bet none of the code your project depends on has any.

        • by cowdung ( 702933 )

          Yes. Failure to check return codes may be the programmer's fault, but other developers on the project get sloppy. In languages that properly support exceptions, nobody can ignore the exceptions. The exceptions can be handled globally for the most part anyway. Unfortunately code is written by teams and its often hard to enforce good practices, even moreso if you add external libraries. Exceptions have made things much better.

          Your example about C++ kind of proves my point. C++ a language known for the innumer

  • by Shane_Optima ( 4414539 ) on Sunday July 21, 2019 @07:19AM (#58959740) Journal
    Alright, who has the "Yoda" username registered around here?

    Your moment to shine has finally come.
  • Abandoning it because you can't use debug print or code coverage? Adding the try option would have been a good addition, as you can still use the if version when needed.
  • Of course, a try() operator is a good idea. It offers an alternative to the way this is done now and, in some situations, it will be superior. But apparently, some people feel threatened by more ways to do a thing. And apparently, Google has no idea about real-world language design and gave in to pressure from the masses.

    Well, Go is not really useful for most things anyways. Far too limited and far too specialized to the containerized model.

    • The problem with their attempt was that the developers lost some functionality with the implementation. Doing things the current way someone could handle the error in a way that met their needs (log it, return it or an error message, etc).

      Google would have been better off implementing a try-catch functionality. (If my code is wrong don't criticize as I've never programmed in Go before. It's an example to show how to keep the functionality.)

      f := try(os.Open(filename)) catch (error) {
      return fmt.Errorf("Open file %s failed: %s", filename, error)
      }

      • by gweihir ( 88907 )

        The messed with previous behavior? That is not a good idea either. Sure, Google itself probably has the resources to change all their code, but other users may not. In that case, I retract my statement. Never break compatibility unless you absolutely have to. (Of course, that assumes a good design to start with. If you do not have that, you will need to break compatibility time and again and the whole thing may be better of scrapped in the first place.)

  • by PPH ( 736903 ) on Sunday July 21, 2019 @02:54PM (#58961386)

    try { to implement a new construct. }

    catch { shit for doing so. }

    finally { just give up and use C++. }

  • by Anonymous Coward

    Basically the proposal was to formalise the concept that if a function returned a success / error tuple, that try would test for error and return the error value, otherwise take the success value.

    Given how ad hoc error handling is in Go, this seems like a useful thing. Other languages like Rust and Swift have far better error handling and its thought out and purposeful.

    • Given how ad hoc error handling is in Go, this seems like a useful thing.

      This is a good start to solving the problem, but it only solves one subset of the problem. If they want to use the 'if' style of error handling, and replace it with helper functions, they need to create a system that handles all the common error cases, not just one of them. Here is a list:

      1) A function that returns on error (which this does, which is less useful).
      2) A function that prints an error and returns on error.
      3) A function that prints a stack trace and returns on error.

      Actually there are more

  • Every Star Wars fan knows: "There is no try."

Ocean: A body of water occupying about two-thirds of a world made for man -- who has no gills. -- Ambrose Bierce

Working...