Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Go 2: #54686

Closed
dmitryuck opened this issue Aug 26, 2022 · 1 comment
Closed

proposal: Go 2: #54686

dmitryuck opened this issue Aug 26, 2022 · 1 comment
Labels
error-handling Language & library change proposals that are about error handling. FrozenDueToAge LanguageChange Proposal v2 A language change or incompatible library change
Milestone

Comments

@dmitryuck
Copy link

dmitryuck commented Aug 26, 2022

Author background

  • Would you consider yourself a novice, intermediate, or experienced Go programmer?
  • I'm a novice
  • What other languages do you have experience with?
  • Js

Related proposals

  • Has this idea, or one like it, been proposed before?
  • Not sure
    • If so, how does this proposal differ?
  • Does this affect error handling?
  • Yes
    • If so, how does this differ from previous error handling proposals?
  • Is this about generics?
  • No
    • If so, how does this relate to the accepted design and other generics proposals?

Proposal

  • What is the proposed change?
  • Add a new way of error handling
  • Who does this proposal help, and why?
  • This adds a new convenient way of handling errors
  • Please describe as precisely as possible the change to the language.
    the error handles after the function call, block executes when error != nil
func MyFunc(arg1, arg2 any) error {
  // Function body

  return errors.New("Some error info")
}

in a place where we call this function

err := MyFunc(arg1, arg2) {
  // An error handling goes here
  Log(err)
}

similar to function with return value

  func MyFunc(arg1, arg2 any) any error {
    // Function body

    return nil errors.New("Some error info")
  }

  in a place where we call this function

  result, err := MyFunc(arg1, arg2) {
    // An error handling goes here
    Log(err)
  }
  • What would change in the language spec?
  • Adding a specific error handling mechanism: A curly braces after a function call
  • Please also describe the change informally, as in a class teaching Go.
  • Add a mechanism to handle any error in function like callback after a function call
  • Is this change backward compatible?
  • yes, compatible with G1
    • Breaking the Go 1 compatibility guarantee is a large cost and requires a large benefit.
      Show example code before and after the change.
    • Before
    • After
  • Orthogonality: how does this change interact or overlap with existing features?
  • No conflicts with existing code
  • Is the goal of this change a performance improvement?
  • No, more about convenience and elegance
    • If so, what quantifiable improvement should we expect?
    • How would we measure it?

Costs

  • Would this change make Go easier or harder to learn, and why?
  • No effect
  • What is the cost of this proposal? (Every language change has a cost).
  • Don't know
  • How many tools (such as vet, gopls, gofmt, goimports, etc.) would be affected?
  • None
  • What is the compile time cost?

  • What is the run time cost?

  • Can you describe a possible implementation?

  • Do you have a prototype? (This is not required.)

@gopherbot gopherbot added this to the Proposal milestone Aug 26, 2022
@seankhliao
Copy link
Member

Duplicate of #41908

@seankhliao seankhliao marked this as a duplicate of #41908 Aug 26, 2022
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 26, 2022
@seankhliao seankhliao added LanguageChange v2 A language change or incompatible library change error-handling Language & library change proposals that are about error handling. labels Aug 26, 2022
@golang golang locked and limited conversation to collaborators Aug 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
error-handling Language & library change proposals that are about error handling. FrozenDueToAge LanguageChange Proposal v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

3 participants