[swift-evolution] Location of ! in Boolean negation expressions

Anton Zhilin antonyzhilin at gmail.com
Sat Aug 6 13:32:34 CDT 2016


2016-08-06 10:37 GMT+03:00 Darren Mo via swift-evolution <
swift-evolution at swift.org>:

> Consider code like
>
> guard !parameters.contains(where: { !validValueRange.contains($0) }) else …
>
> Oftentimes I need to write negation expressions like this. The location of
> the exclamation marks really bugs me when writing and reading this code.
> The natural English ordering would be something like
>
> “Make sure parameters does not contain an element such that
> validValueRange does not contain this element.”
>
> But the programming-language-imposed ordering is
>
> “Make sure NOT parameters contains an element such that NOT
> validValueRange contains this element.”


One solution to this problem would be to add negative method versions
wherever possible. For example: 'all', 'any', 'some', 'none' methods
instead of just 'contains(where:)'.
Plus, we could add 'unless' alongside 'guard'. But these features were
postponed to Stage 2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160806/dc395bb1/attachment.html>


More information about the swift-evolution mailing list