Skip to content

Simplify if condition for nil checking #68127

Closed
@mosleim

Description

@mosleim

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    LanguageChangeSuggested changes to the Go languageProposalv2An incompatible library change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions