[swift-evolution] Remove (!) logical negation operator
Dennis Lysenko
dennis.s.lysenko at gmail.com
Tue Dec 15 10:24:40 CST 2015
Andrew, we could theoretically implement `not`-negation and continue to use
!= until a better solution is found. Baby steps and all that.
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)`?
On Tue, Dec 15, 2015 at 10:19 AM Andrew Brown via swift-evolution <
swift-evolution at swift.org> wrote:
> I'm interested to hear what the opinions are for this.
> When I first read the idea I was a definite NO! (See what I did there :) )
> But after thinking about it I'm interested to hear how people feel about
> this.
> The obvious issue is what do we do with '!=' ?
> Most languages which do not use ! for negation use '<>' for '!=' and I'm
> no sure how popular that would be.
>
> ABR.
>
> On 15 Dec 2015, at 15:01, Marc Knaup via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> I'm uncertain but it's definitely worth considering.
>
> I also think that it's weird at the moment since in most cases the
> exclamation mark is now something dangerous.
> I also had a couple of bugs in my code because the operator is too easy to
> miss and the negation was not or no longer intended.
>
> On Tue, Dec 15, 2015 at 3:11 PM, Bruno Berisso via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> Hello,
>>
>> I'm really used to negate logical expressions with this operator but it
>> never feels confortable to me. If I need to negate some complex expression
>> sometimes I prefer to write a temporal variable and then negate that with
>> *!* because I fear than others, or myself, could overlook it and cause
>> confusion.
>>
>> Now that Swift use the same operator to force the unwrap of optional
>> values it becomes even worse.
>>
>> Consider this examples:
>>
>> if someOptionalValue != nil {
>> ...
>> if !(otherBoolValue && someOptionalValue! > 0) {
>> ...
>> }
>> }
>>
>> Or even worse, what happen when negating Optional<Bool> values?
>>
>> //Best case
>> if let value = optionalBool where !value {
>> ...
>> }
>>
>> //Worse case
>> if !optionalBool! {
>> ...
>> }
>>
>> Now what happen with this examples if we instead use a *not* operator:
>>
>> if someOptionalValue != nil {
>> ...
>> if not (otherBoolValue && someOptionalValue! > 0) {
>> ...
>> }
>> }
>>
>> if let value = optionalBool where not value {
>> ...
>> }
>>
>> if not optionalBool! {
>> ...
>> }
>>
>> I'm not sure if *not* is the right path here but I really want to
>> improve the *!* to something more clear at a glance and that doesn't
>> have different behaviour depending where it appears in an expression.
>>
>> Thanks,
>>
>> _______________________________________________
>> 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/9995d28f/attachment.html>
More information about the swift-evolution
mailing list