There have been many threads on the Swift forums pitching to deprecate or replace force-unwrapping of optionals. Discussions in those threads were always divisive, with those against it finding values in force-unwrapping where the variable is known to be non-
nil. For example:
var optionalNumber: Int? = nil optionalNumber = 1 let number = optionalNumber! // number == 1
Now what if we make some minimal change to the code snippet above, and make it impossible for anyone to predict whether
optionalNumber can be force-unwrapped successfully? Something like this maybe:
@Quantum var optionalNumber: Int? = nil // `optionalNumber` is initialised with an initial state of `nil` optionalNumber = 1 // `optionalNumber` now has a 50% chance of being `nil`, and 50% being 1 let number = optionalNumber! // The force-unwrapping has a 50% chance of being successful
It won't invalidate the opinion that force-unwrapping is useful, but it should be interesting though.
Full text of this silly proposal here.
April fools has basically gone by, but since there are still some places in the world where it's 2021-04-01, I hope it's still fine for me to post this.