Description
Backwards compatibility should be a function of a previous design's quality. It should NOT be a function of adherence to backwards compatibility. Go 2 does not promise to be compatible with Go 1: While compatibility is nice to have, it isn't required. Change is inevitable. So why are we limiting ourselves on this specific issue? Luckily, the answer to that question does NOT matter for this proposal. It's backwards compatible and boomer approved.
With that out of the way...
Proposal
You want error handling ideas. Yet restriction is bad for creativity. This proposal is unhinged. I might not even like it... but I'm making it anyways. Perhaps, my outlook will change. Perhaps it won't and I will regret this decision for the rest of my life. All I know is that it isn't a duplicate.
An error is a value in Go, so anything that is applicable to errors should also be applicable to values; except panic
and recover
I guess... If we are going to use a function, it is either a built-in or keyword; none of this top of the page, 4th dimension, quantum realm nonsense.
People want to be able to return if not nil
, wrap errors, and feed their families, all with a single error feature. Now, I'm not gonna lie: This one might leave lil timmy a lil hungry. Expecting a single feature to handle errors is like expecting the language to work without if
statements and... Let's not get ahead of ourselves here. This proposal will meet the requirements.
At this point, I know you have your tongue out panting like a dog in front of your computer. heh heh heh. Otherwise, you are NOT amused right now. You may be asking yourself if this post even has a proposal in the first place. It does. I just needed to make it longer so it seems more sophisticated than the other ones. So without further ado...
Add the ability to accept functions in place of a value - or only error values - if it isn't equivalent to its zero value.
func bezo(baller, dollers string) error {
bucko, (err) := strconv.Atoi(baller) // returns err if not nil
bucks, _ := strconv.Atoi(dollers)
fmt.Println("$:", bucko + bucks)
ballin, fmt.Errorf("error: balled too hard\n%w", err) := isBaller(bucko + bucks, 2147483647) // returns err if not nil
if ballin {
take50(err) := MakeMackenzieHappy() // returns err (cause not nil)
}
return nil
}
For the MENSA members out there.
func musk(money string) (bool, error) {
if money == "long" {
money = "longer"
}
sec, fmt.Tweet(err) := findSEC() // returns false, fmt.Tweet(err) error if not nil
RunFrom(sec)
return false, nil
}
READ THE FOLLOWING FOR CONTEXT BEFORE COMMENTING
#52416 (comment)
#52416 (comment)
#52416 (comment)
#52416 (comment)
Potential Supporters
@ianlancetaylor Due to my flow control.
@networkimprov he did it. he solved go errors.
Similar Proposals (Not Duplicates)
#21732 @faiface +8 -8
idek @lldld
#14066 @gertcuykens
#46655 @smasher164
Symbolic Proposals
#50207 @misaka123456
#42214 @kidlj
#32884 @integrii @alanfo
#42318 @be-impl +18 -19 @sirkon
#36390 @cmidt-veasna -5
Implications: #52415
More Implications: #52380
Downvote Offset: #52416 (comment)