on Sat May 21 2016, Антон Миронов <[email protected]> wrote:

> I found negation operator (!) the least detectable among the code. So
> I’ve decided to add property “not” to BooleanType (Swift 2.2) or
> Boolean on 3.0 with extension:
>
> extension BooleanType {
>       var not: Bool { return !self.boolValue }
> }
>
> This is code with negation operator:
>       return !self.lanes[position.y][currentLaneRange].contains(.Gap)
>
> As I sad before negation operation is hard to spot. Moreover at first
> it looks like I’m trying to negate self for some reason.
>
> This is code with “not” property:
>       return self.lanes[position.y][currentLaneRange].contains(.Gap).not

I think having the “not” up at the front of the boolean condition is
useful.  Think about why this joke works:

    “I'm a big fan of reference semantics...           NOT!”

-- 
-Dave

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to