[swift-evolution] Proposal: remove "assert" and always use "precondition" instead.

Adrian Kashivskyy adrian.kashivskyy at me.com
Tue Dec 8 18:06:44 CST 2015


> raise an exception

throw an error*

–

Or you could take advantage of powerful type system and error handling mechanisms and use neither `assert` nor `precondition`. Swift has so many features which ensure safety that using assertions is the last thing you could possibly lean towards – and I think that the flexibility to differentiate between `assert` and `precondition` is a precious choice to have, especially in high-performance code.


Pozdrawiam – Regards,
Adrian Kashivskyy

> Wiadomość napisana przez Amir Michail <a.michail at me.com> w dniu 09.12.2015, o godz. 01:00:
> 
> 
>> On Dec 8, 2015, at 6:59 PM, Adrian Kashivskyy <adrian.kashivskyy at me.com <mailto:adrian.kashivskyy at me.com>> wrote:
>> 
>> That's a choice I would have to carefully make when designing the behavior. Not all asserts are non-recoverable.
>> 
> 
> You could have precondition raise an exception so you can catch it if you really want to.
> 
>> Pozdrawiam – Regards,
>> Adrian Kashivskyy
>> 
>>> Wiadomość napisana przez Amir Michail <a.michail at me.com <mailto:a.michail at me.com>> w dniu 09.12.2015, o godz. 00:56:
>>> 
>>> 
>>>> On Dec 8, 2015, at 6:55 PM, Adrian Kashivskyy <adrian.kashivskyy at me.com <mailto:adrian.kashivskyy at me.com>> wrote:
>>>> 
>>>> Strong -1, `assert` is a great tool for catching programmer errors in development phase, without compromising the stability in release mode.
>>> 
>>> You would rather have an ill-defined state rather than a crash with a useful bug report?
>>> 
>>>> 
>>>> Pozdrawiam – Regards,
>>>> Adrian Kashivskyy
>>>> 
>>>>> Wiadomość napisana przez Amir Michail via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> w dniu 09.12.2015, o godz. 00:52:
>>>>> 
>>>>> Swift is a safe language after all. Moreover, it is all too easy to accidentally type “assert” when you mean “precondition”.
>>>>> _______________________________________________
>>>>> swift-evolution mailing list
>>>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>>> 
>>> 
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151209/020aefdc/attachment.html>


More information about the swift-evolution mailing list