[swift-evolution] [Proposal] Add property for negation to Bool
Антон Миронов
antonvmironov at gmail.com
Sat May 21 09:50:40 CDT 2016
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
Now it is easy to spot the statement I am actually getting negation of.
On my experience negation operator can occasionally be missed while reading code. This happens less often with “not” property. So I’m proposing to add this property to standard library and prefer it in most cases.
Thanks,
Anton Mironov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160521/9442412f/attachment.html>
More information about the swift-evolution
mailing list