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

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


~ is just trading one operator for another, which isn't a lot better.
Also ~ is quire annoying to type on non-english keyboards.

"&" and "|" have a different meaning than "&&" and "||".
The former two evaluate both operands and then perform the logical
operation on the results.
The latter two evaluate the right operand iff the left operand is true or
false respectively.

On Tue, Dec 15, 2015 at 10:17 PM, Bruno Berisso via swift-evolution <
swift-evolution at swift.org> wrote:

> Keep in mind that the discussion isn't "!" vs "not" but how to address
> basically two issues with "!":
> - invisibility in non-trivial expressions
> - collision with the forced unwrapped of optional values
>
> I personally collect really good arguments against the use of "not" as an
> alternative to address this two issues without being to disruptive.
>
> I think that the best option we have until now is "~" used for bitwise
> "not" operation. This bring the next question: why we need to distinguish
> between bitwise logical operators and boolean logical ones? Doesn't that
> should be implicit in the type of the operands?
>
> The bitwise operators are not defined for Bool types and logical
> operations are only defined for Booleans. So we could have:
>
> boolValueX & boolValueY = Boolean "and"
> notBoolX & notBoolY = bitwise "and"
> ~boolValueX = Boolean "not"
> ~notBoolX = bitwise "not"
>
> I'm thinking out loud here so let me know if this doesn't make sense.
>
> On Tue, Dec 15, 2015 at 17:33 Jordan Rose via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> Today &&, ||, (prefix) !, !=, and !== are not magic; they are just like
>> every other operator. Adding user-overridable keyword operators would be a
>> non-trivial change to the language.
>>
>> (Everyone—nearly—keeps forgetting about != and !==. Replacing these with
>> not(a == b) is not really a good answer.)
>>
>> Jordan
>>
>> On Dec 15, 2015, at 12:13 , Rudolf Adamkovic via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>> +1 for clean-up:
>>
>> • "and" instead of &&
>> • "or" instead of ||
>> • "not" instead of !
>> • if expressions instead of ?!
>>
>> Easier to read, easier to type, easier to understand for beginners.
>>
>> As a bonus, it doesn't look like optionals (less !s and ?s).
>>
>> R+
>>
>> Sent from my iPhone
>>
>> On 15 Dec 2015, at 20:49, Sune Foldager via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>>
>> On 15 Dec 2015, at 17:05, Tommy van der Vorst via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>> 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.
>>
>>
>> I completely agree. While it *is* a bit weird to use the same symbol for
>> forced unwrap and its more traditional use as boolean negation, removing
>> the one virtually all other languages have is not the answer. If we do
>> that, why not also ~ for binary negation, || and && and even + and -.
>>
>> It’s always a balance between verbosity, “natural language”-ness and
>> terseness. It’s not always easier to read code that’s very verbose, and I’m
>> sure we don’t want Swift to be like AppleScript.
>>
>> -Sune
>>
>> _______________________________________________
>> 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/41054e3b/attachment.html>


More information about the swift-evolution mailing list