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

Jean-Denis Muys jdmuys at gmail.com
Fri Feb 12 02:03:46 CST 2016

Strong -1

Swift is in the C-family of languages, syntax-wise. == as the comparison operator is as much rooted there as are braces.

All these are questionable on similar grounds: ==, += -= and so on, braces as block delimiters, even the single = sign

> It’s too easy to accidentally write “x==2” instead of “x=2”.

And I can also argue that +, - *, / are also bad, because 'It’s too easy to accidentally write “x+2” instead of “x-2”.’  and therefore we should replace them  with ADD, SUBTRACT, MULTIPLY, DIVIDE

or something

What is the reason for Swift to use C-like syntactic constructs? I suppose it’s familiarity. Granted, familiarity might not be the strongest argument. Yet it counts.

== is familiar, unambiguous, and the compiler can catch most cases of mistyping.


> On 12 Feb 2016, at 00:50, Jessy Catterwaul via swift-evolution <swift-evolution at swift.org> wrote:
>> What do you propose as an alternative operator for testing equivalence?
> =
> http://catterwaul.com/equality-operator/
> Jonathan Tang’s brings this up: 
> {x == 2}
> You’d need to use the return keyword. Oh well; I think it reads better.
> {return x = 2}
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list