proposal: Go 2: improve error handling with “??” keyword for a special case #37243
Labels
error-handling
Language & library change proposals that are about error handling.
FrozenDueToAge
LanguageChange
Suggested changes to the Go language
Proposal
Proposal-FinalCommentPeriod
v2
An incompatible library change
Milestone
Would you consider yourself a novice, intermediate, or experienced Go programmer?
Intermediate
What other languages do you have experience with?
PHP, Swift, Javascript
Would this change make Go easier or harder to learn, and why?
Easier to read and less to type.
Has this idea, or one like it, been proposed before?
No, I like to change the meaning of
??
for a special caseWho does this proposal help, and why?
I have seen different ideas for error handling and adding more characters seem requires more time to learn and explaining how it works, why not add 2 symbols?
#21161
#32437
#37165
What is the proposed change?
Propose to add
??
as a shorthand forif err != nil
Is this change backward compatible?
This is a new keyword in additional to the existing ones.
Show example code before and after the change.
Existing approach is explicit and verbose
The is valid:
https://github.com/evanw/esbuild/blob/master/src/esbuild/main/main.go#L58
New approach for fast typing
This method is an additional keyword, allowing
??
to be translated intoif err != nil
behind the scene.if err != nil
all the time when??
keyword took <1 second to type.??
is not implemented in Go.What is the cost of this proposal? (Every language change has a cost).
* What is the compile time cost?
Negligible, as it can be translate behind the scene.
Can you describe a possible implementation?
No
How would the language spec change?
No
Orthogonality: how does this change interact or overlap with existing features?
This change enable developers to type less and improve readability.
Is the goal of this change a performance improvement?
Compiler: no, Developer: yes
Does this affect error handling?
Yes
No
The text was updated successfully, but these errors were encountered: