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

Charles Constant charles at charlesism.com
Tue Dec 15 11:28:18 CST 2015


My vote is to leave "!" as is. I'd support changing the "unwrap" operator
to something else.

Sprinkling "not" all over my source files seems noisy to me. Like
AppleScript, it sounds good in theory, but in practice the code is no
easier to read than before.

I find it kind of strange that the last couple years the internet suddenly
views C language features with great suspicion. I have no problem with any
of the C features that remain in Swift. I find far more confusing the
remaining features and conventions from Obj-C and Cocoa.


On Tue, Dec 15, 2015 at 8:05 AM, Tommy van der Vorst via swift-evolution <
swift-evolution at swift.org> wrote:

> 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> 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
> 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/c92a3bef/attachment.html>


More information about the swift-evolution mailing list