[swift-evolution] Proposal: x == 2 should not be a valid statement

Jessy Catterwaul mr.jessy at gmail.com
Thu Feb 11 18:22:27 CST 2016


> “==“ for equivalence isn’t broken.   It doesn’t need fixing.
> 
> -jcr

It’s two equals signs. Or three equals signs. People can do better than this.

https://en.wikipedia.org/wiki/Assignment_(computer_science)#Assignment_versus_equality

> The assignment operator (=) does not return a value, to prevent it from being mistakenly used when the equal to operator (==) is intended.
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/BasicOperators.html

The history of this badness is crumbling.


Perhaps the solution is to first do a better job of assignment, freeing up the operator for comparison without semantic overload?

let string = ""
var int = 2
int = 3

string, be ""
var int, be 2
int, be 3

string be ""
var int be 2
int be 3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160211/9018ba76/attachment.html>


More information about the swift-evolution mailing list