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

Tommy van der Vorst tommy at pixelspark.nl
Tue Dec 15 10:05:09 CST 2015


I do not see a problem with the '!' negation operator. The case with forced unwrap + negation doesn't happen very often, (in my opinion) doesn't look that bad, and certainly isn't confusing. The other example cases also look pretty clear to me. Usage of '!' for implicit unwrapping vs its usage for negation is well-separated (one being prefix, the other postfix). 

I *do* see negative effects of removing it: ! is part of virtually all programming languages currently in use, any decent programmer is accustomed to it and read it like 'not' in their head anyway. Removing would definitely confuse newcomers to the language. 

/T

> Op 15 dec. 2015, om 15:11 heeft Bruno Berisso via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> het volgende geschreven:
> 
> 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 <mailto: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/ddaf1472/attachment.html>


More information about the swift-evolution mailing list