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

Amir Michail a.michail at me.com
Mon Dec 14 17:01:01 CST 2015


What about these renamings?

assert => debugAssert

precondition => assert

> On Dec 14, 2015, at 5:48 PM, Andrey Tarantsov <andrey at tarantsov.com> wrote:
> 
>> Here’s some rationale that may be missing.  The two functions have distinct roles:
>> 
>> - assert: checking your own code for internal errors.
>> - precondition: for checking that your clients have given you valid arguments.
> 
> Makes sense.
> 
> I think the issue here is that for many people who write just plain apps, the following holds true:
> 
> 1) assert performance is not a concern
> 
> 2) asserts are used to prevent something terrible from happening
> 
> 3) the most interesting bugs happen inside the code (where assert is appropriate), not on module/layer/class boundaries
> 
> Given #1 and #2, we'd prefer to be able to write asserts that can guarantee that the asserted condition never happens below the assertion point.
> 
> Why not distinguish between them via assert? and assert!, with "assert?" highlighting the fact that execution may continue in some cases, and "assert!" highlighting the fact that it will always crash?
> 
> That would be beneficial when reading other people's code, because it'll show whether they assume that the subsequent code doesn't need to deal with the asserted condition.
> 
> A.
> 



More information about the swift-evolution mailing list