[swift-evolution] [Proposal] Add property for negation to Bool

Brent Royal-Gordon brent at architechies.com
Sat May 21 18:45:38 CDT 2016

> 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 do agree with you that `!` is sometimes hard to notice, but I think putting the "not" at the end is sort of burying the lede—"if the lane at position y's current lane range contains a gap…NOT!" I don't like making `not(_:)` a function, and I don't think we should introduce a freestanding keyword just for this, either.

One workaround is to write this instead:

	return !!!self.lanes[position.y][currentLaneRange].contains(.Gap)

Three nots is logically equivalent to one, but far more visible. Of course, then you have to worry about accidentally writing two or four, which would be the opposite.

Brent Royal-Gordon

More information about the swift-evolution mailing list