[swift-evolution] Remove (!) logical negation operator
Thorsten Seitz
tseitz42 at icloud.com
Tue Dec 15 15:46:10 CST 2015
I never liked "!" because it can so easily be overlooked, so I'm fine with "not"
-Thorsten
> Am 15.12.2015 um 16:01 schrieb Marc Knaup via swift-evolution <swift-evolution at swift.org>:
>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151215/272545d0/attachment.html>
More information about the swift-evolution
mailing list