[swift-evolution] Proposal: remove "assert" and always use "precondition" instead.
andrey at tarantsov.com
Mon Dec 14 16:48:34 CST 2015
> 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.
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.
More information about the swift-evolution