[swift-evolution] Propagating Optionals
swift-evolution at haravikk.me
Mon Sep 26 03:08:46 CDT 2016
> On 25 Sep 2016, at 21:19, Trans via swift-evolution <swift-evolution at swift.org> wrote:
> "john.residence.numberOfRooms" could just behave one way or the other
While I understand where you're coming from, I think the problem is that whichever version we specified as a guess would be wrong some of the time anyway, which is why it's better to just force the developer to think about it and put the correct symbol(s) for their use case.
For example, if we assumed a behaviour of !, then the user is going to get runtime errors that might not always occur (say the residence is nil 5% of the time, that's potentially only a 5% chance of triggering the error during testing). If we assume ? as the correct behaviour then the developer could end up with an error much further down their code depending upon when and how they use the result of the statement, and looking back at the code it won't be as obvious where that optional came from (especially if you meant to put an exclamation mark but didn't, so are assuming a non-optional value).
It's just one of those cases where I think it's better to force the developer to be explicit, rather than try to guess what they meant to do.
More information about the swift-evolution