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

Dave Abrahams dabrahams at apple.com
Sun May 22 13:15:26 CDT 2016

on Sat May 21 2016, Антон Миронов <swift-evolution at swift.org> 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!”


More information about the swift-evolution mailing list