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

Xiaodi Wu xiaodi.wu at gmail.com
Sat Aug 6 12:43:25 CDT 2016

Changes to Swift syntax aren't really in scope for the Swift 4 Stage 1
evolution process. See this list:

On Sat, Aug 6, 2016 at 2:37 AM, Darren Mo via swift-evolution <
swift-evolution at swift.org> wrote:

> 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.”
> See how much harder the programming language version is to understand?
> Most of the time I write the positive version first because it comes out so
> naturally, and then I add the exclamation marks afterwards. It really
> burdens my mind every time I need to write code like this. Let’s come up
> with a solution to address this!
> Here’s my zero-thought solution:
> guard parameters.!contains(where: { validValueRange.!contains($0) }) else …
> I’d love to hear alternate solutions and whether other people are having
> this problem too!
> Darren
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160806/ff2f8c97/attachment.html>

More information about the swift-evolution mailing list