The current solution is checking thevar != nil before using the var, but forgetting to do that means your program will crash. That means this simple p

Go Desperately Needs Nil Safe Types

submited by
Style Pass
2021-06-22 06:00:09

The current solution is checking thevar != nil before using the var, but forgetting to do that means your program will crash. That means this simple programmer error could take down your whole server. Hopefully you catch these errors with tests before they reach production. However, we’re not machines so inevitably we won’t catch some of these until our end users encounter an error in production.

Non-optional variables in Swift are guaranteed to never be nil. Your function no longer needs to check it’s arguments for nil if you declare your arguments non-optional. Imagine deleting all those duplicate if myarg == nil in all your functions with the guarantee your inputs won’t ever be nil!

Go2 has several open proposals for non-nil types, but nothing seems to be decided upon yet. Hopefully they don’t dismiss this lightly. In my opinion, this is the only thing holding Go back from competing with Rust, Swift, TypeScript and other languages with non-nullable types.

Leave a Comment