Skip to content

Simplify if condition for nil checking #68127

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

Closed
4 tasks done
mosleim opened this issue Jun 22, 2024 · 1 comment
Closed
4 tasks done

Simplify if condition for nil checking #68127

mosleim opened this issue Jun 22, 2024 · 1 comment
Labels
LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change

Comments

@mosleim
Copy link

mosleim commented Jun 22, 2024

Go Programming Experience

Novice

Other Languages Experience

Go, C/C++

Related Idea

  • Has this idea, or one like it, been proposed before?
  • Does this affect error handling?
  • Is this about generics?
  • Is this change backward compatible? Breaking the Go 1 compatibility guarantee is a large cost and requires a large benefit

Has this idea, or one like it, been proposed before?

No

Does this affect error handling?

No. But, caused error is an interface, this will make more simple to check.

Is this about generics?

No

Proposal

we need to simplify if condition for pointer nil checking.

var err error =  nil
if err != nil {
   // do somethings
}

my expectation is:

var err error =  nil
if err {
   // error handling
}

Language Spec Changes

No response

Informal Change

No response

Is this change backward compatible?

Not sure, but i think will not compatible.

Orthogonality: How does this change interact or overlap with existing features?

No response

Would this change make Go easier or harder to learn, and why?

more harder to learn. But, more easier to code.

Cost Description

No response

Changes to Go ToolChain

gofmt, gopls will affected

Performance Costs

No response

Prototype

No response

@mosleim mosleim added LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change labels Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

2 participants