[swift-evolution] Proposal: An assignment operator := that ensures nil before assignment.
Craig Cruden
ccruden at novafore.com
Sat Feb 27 10:42:32 CST 2016
Additionally, the study that Microsoft does is about making sure a variable is != null as a precondition.
The vast majority of defects in Java is due to an operation on a variable that was unexpectedly found to be null when it should be a value.
Because of the hole in the type system you can get runtime exceptions stating that there was a “Null Exception”
As such the precondition would be ensure it is not null — not the opposite.
As a mentioned early by numerous people using Swifts type system ensures that this cannot be the case.
For example
var x : Int = 0
would make sure x is never an unexpected “Null value”
And
var x : Int?
You would not be using it with operations directly since it would give a compilation error if you did so.
As such the problem of the “Null Exception” was handled through optionals in the type system and not through scattering preconditions checking for unexpected null values.
A much better solution to the problem.
> On 2016-02-27, at 23:30:55, Stephen Celis <stephen.celis at gmail.com> wrote:
>
>> On Feb 27, 2016, at 11:28 AM, Amir Michail via swift-evolution <swift-evolution at swift.org> wrote:
>>
>> It’s a convenience feature that saves lots of finger typing.
>>
>> Which would you rather have:
>>
>> precondition( x == nil )
>> x = 3
>>
>> OR
>>
>> x: = 3
>>
>> ?
>
> A bunch of us have tried to point out that toy examples like these are not helpful enough.
>
> You're not addressing the actual content and questions of any of your replies, Amir. Would you please take the time and effort to do so?
>
> --
> Stephen
More information about the swift-evolution
mailing list