[swift-evolution] Remove (!) logical negation operator

Marc Knaup marc at knaup.koeln
Tue Dec 15 12:50:17 CST 2015


Lua is also quite popular and doesn't support the "!" operator but the
"not" keyword instead.
Adapting to that wasn't all that difficult for me when writing Lua for a
while. You rarely have to think about what a negation looks like because
"not" just comes to mind naturally. It's like you're writing regular text
in that moment.

In any case such a decision should not depend primarily on whether a
specific operator or keyword is common in other languages but whether it
helps expressing and understanding the code's intent. "not" achieves that,
esp. for newbies and people getting someone else's code.

On Tue, Dec 15, 2015 at 7:45 PM, Paul Cantrell via swift-evolution <
swift-evolution at swift.org> wrote:

> Though the “! means negation” operators are too widely used and too
> elegant for me to get behind this change, I would say a word in favor of
> Swift’s loose convention of “! means danger:”
>
> !  (force unwrap)
> !  (IUO)
> as!
> try!
>
> …all mean “potential crash here.” That’s a nice convention.
>
> However, because not all potential crash points are marked with ! (array
> subscripting, assert / precondition / fatalError, and of course any
> function that contains one of the above crashing constructs), we can’t say
> “danger implies !”. It thus doesn’t seem worth the pain of removing the !,
> != and !== operators to make the “! implies danger” association strong.
>
> Still, I’d be in favor of anything that helps me audit code for potential
> crash points — if not changing the negation operators, then perhaps
> something AST based, perhaps even library annotations. At the very least,
> I’d appreciate it if SourceKit / Xcode could apply different syntax
> coloring to the negation bang and the danger bang.
>
> Cheers,
>
> Paul
>
>
> On Dec 15, 2015, at 12:26 PM, Craig Cruden via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> -1 as well.
>
> I cannot think of a language where I don’t have ! as negate (which I read
> as not).
>
> What would it be replaced by a keyword of “not”?
>
>
>
>
> On 2015-12-16, at 1:18:14, Austin Zheng via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> -1. In terms of C features that people complain about, prefix '!' for
> negation doesn't seem to be high on the list, and it's never something that
> has caused me or any other developer I know a problem (although these are
> all anecdotes, take them as you will). A linter/style checker can always be
> used if you really want to enforce 'x == false' over '!x' for your team or
> project.
>
> '~' is already used for bitwise negation.
>
> More broadly, in terms of "words" vs "cryptic symbols" as operators, I am
> strongly against the former and for the latter. The symbols are 'cryptic'
> for the few minutes it takes to figure out what they mean, after which the
> developer is good for a lifetime of coding in many different languages. The
> words are nicely self-descriptive for a bit, then increase verbosity and
> destroy your ability to visually delineate arguments via symbols forever.
>
> Best,
> Austin
>
>
> On Tue, Dec 15, 2015 at 9:59 AM, ilya via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> > For example in `if let aBool = aBool where !aBool`, let's suppose that
>> we know that `aBool` optional it's not empty before this check. How would
>> you write it? `!aBool!` or with the `if let...` ?
>>
>> if aBool == false {} covers this nicely.
>>
>> As for the whole topic of words vs cryptic symbols for Boolean operators
>> I'm agnostic on what's best but imho we need to have consistency. E.g.
>> either all words, or all math symbols or all the same as in C (current
>> state of things).
>>
>> You can always rewrite !x as (x==false) if x is a Bool and forced
>> unwrapping is undesirable anyway so the confusion can be minimized in
>> practice.
>>
>> Ilya.
>>
>> On Tue, Dec 15, 2015 at 19:56 Bruno Berisso via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>>> I also hit the *!=* vs *<>* dilema and conclude that we could continue
>>> using the *!=* as "not equal".
>>>
>>> It's true that it will not be as consistent as before but I think it's a
>>> reasonable price to pay taking into account the issues with *!* as
>>> 'not'.
>>>
>>>
>>>> Not that I necessarily think this proposal is a good idea. The given
>>>> examples reek of being against unwrapping for some reason.
>>>>
>>>> Why not use `if let aBool = aBool where !aBool`? And `if let someValue
>>>> = someValue where !(otherBoolValue && someValue > 0)`?
>>>>
>>>
>>> I think the issue is the complete different meanings of a symbol
>>> depending only in where it appears in an expression. Adding that *!*character
>>> is really easy to miss in an expression make it at last uncomfortable.
>>>
>>> I agree that we are all really used to find *!* in logical expressions
>>> and our brain is trained to translate it to NOT automatically but that
>>> doesn't mean that it's good idea to keep it there.
>>>
>>> For example in `if let aBool = aBool where !aBool`, let's suppose that
>>> we know that `aBool` optional it's not empty before this check. How would
>>> you write it? `!aBool!` or with the `if let...` ?
>>>
>>> I think that clearly *!* is not good choice for negation but my mind is
>>> so used to it that I can't totally affirm that *not* is *the* alternative
>>> to it. Do we have another alternatives?
>>>
>>>
>>>  _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>>
>  _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>  _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151215/27e8fd91/attachment.html>


More information about the swift-evolution mailing list