Proposal to change Logical NOT Operator from exclamation mark ( ! ) to something else


(Sadiq) #1

Hello,

I would like to suggest to change Logical NOT Operator from ! to something
else.
It will increase the readability of the code and will avoid any confusion
with the symbol used for force unwrapping of optional values.
It would be easier for new programmers to learn Swift as the first
language.
I don't understand the rational behind using the same operator for two
different purposes.

Thanks and Regards,
Mohammad Sadiq


(David Waite) #2

If someone came with a nice syntax I’d be for this. I can’t imagine what that would be.

I doubt there is an alternate prefix or postfix operator that would pass muster, due to ‘!’ already meaning the appropriate thing in so many languages, and swift only supporting symbolic operators.

I can’t think of a method on boolean which would read properly either, e.g.

  if isValid.not() {…}

The closest I could think to a decent bike shed color would be a global function:

  if not(isValid) {…}

-DW

···

On Feb 15, 2017, at 11:10 AM, Robert Widmann via swift-evolution <swift-evolution@swift.org> wrote:

So you've identified the problem, but what do you propose as a solution here?

It should be noted that a (non-stdlib) language-level answer to this question has already been discussed and rejected (https://lists.swift.org/pipermail/swift-evolution/2015-December/000032.html).

~Robert Widmann

2017/02/15 9:02、Sadiq via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> のメッセージ:

Hello,

I would like to suggest to change Logical NOT Operator from ! to something else.
It will increase the readability of the code and will avoid any confusion with the symbol used for force unwrapping of optional values.
It would be easier for new programmers to learn Swift as the first language.
I don't understand the rational behind using the same operator for two different purposes.

Thanks and Regards,
Mohammad Sadiq
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Robert Widmann) #3

So you've identified the problem, but what do you propose as a solution here?

It should be noted that a (non-stdlib) language-level answer to this question has already been discussed and rejected (https://lists.swift.org/pipermail/swift-evolution/2015-December/000032.html).

~Robert Widmann

2017/02/15 9:02、Sadiq via swift-evolution <swift-evolution@swift.org> のメッセージ:

···

Hello,

I would like to suggest to change Logical NOT Operator from ! to something else.
It will increase the readability of the code and will avoid any confusion with the symbol used for force unwrapping of optional values.
It would be easier for new programmers to learn Swift as the first language.
I don't understand the rational behind using the same operator for two different purposes.

Thanks and Regards,
Mohammad Sadiq
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Derrick Ho) #4

There is no need to change it

Since the context basically disambiguates the meaning of !

The next best thing is to compare it to false

(val == false) // same as !val

···

On Wed, Feb 15, 2017 at 3:02 PM David Waite via swift-evolution < swift-evolution@swift.org> wrote:

If someone came with a nice syntax I’d be for this. I can’t imagine what
that would be.

I doubt there is an alternate prefix or postfix operator that would pass
muster, due to ‘!’ already meaning the appropriate thing in so many
languages, and swift only supporting symbolic operators.

I can’t think of a method on boolean which would read properly either, e.g.

if isValid.not() {…}

The closest I could think to a decent bike shed color would be a global
function:

if not(isValid) {…}

-DW

On Feb 15, 2017, at 11:10 AM, Robert Widmann via swift-evolution < > swift-evolution@swift.org> wrote:

So you've identified the problem, but what do you propose as a solution
here?

It should be noted that a (non-stdlib) language-level answer to this
question has already been discussed and rejected (
https://lists.swift.org/pipermail/swift-evolution/2015-December/000032.html
).

~Robert Widmann

2017/02/15 9:02、Sadiq via swift-evolution <swift-evolution@swift.org>
のメッセージ:

Hello,

I would like to suggest to change Logical NOT Operator from ! to something
else.
It will increase the readability of the code and will avoid any confusion
with the symbol used for force unwrapping of optional values.
It would be easier for new programmers to learn Swift as the first
language.
I don't understand the rational behind using the same operator for two
different purposes.

Thanks and Regards,
Mohammad Sadiq

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Chris Lattner) #5

Source breaking changes like this have to be motivated by an overwhelming reason to be worth changing in Swift 4. Surface level syntax changes like this were the purview of Swift 3, and are very unlikely to make the cut in Swift 4.

-Chris

···

On Feb 15, 2017, at 6:02 AM, Sadiq via swift-evolution <swift-evolution@swift.org> wrote:

I would like to suggest to change Logical NOT Operator from ! to something else.
It will increase the readability of the code and will avoid any confusion with the symbol used for force unwrapping of optional values.
It would be easier for new programmers to learn Swift as the first language.
I don't understand the rational behind using the same operator for two different purposes.


(Sadiq) #6

If that's the case, force unwrapping can be done with a different symbol.
Personally I like '!' for force unwrapping.

···

On Wed, Feb 15, 2017 at 11:45 PM, Jose Cheyo Jimenez <cheyo@masters3d.com> wrote:

https://lists.swift.org/pipermail/swift-evolution/
2015-December/000032.html

Swift tries to be part of the C family of languages so keeping all the
familiar symbols is on purpose. See the ?: operator.

On Feb 15, 2017, at 10:01 AM, Sadiq <msadiqaadil@gmail.com> wrote:

I tried to find it there. I did not find it. You mean here

https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md

right?

On Wed, Feb 15, 2017 at 11:27 PM, Jose Cheyo Jimenez <cheyo@masters3d.com> > wrote:

Hi Mohammad,

This has been proposed before. Please see the commonly rejected section
in the GitHub repo for Swift Evolution.

Thanks!

On Feb 15, 2017, at 6:02 AM, Sadiq via swift-evolution < >> swift-evolution@swift.org> wrote:

Hello,

I would like to suggest to change Logical NOT Operator from ! to
something else.
It will increase the readability of the code and will avoid any confusion
with the symbol used for force unwrapping of optional values.
It would be easier for new programmers to learn Swift as the first
language.
I don't understand the rational behind using the same operator for two
different purposes.

Thanks and Regards,
Mohammad Sadiq

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(André Videla) #7

As of today, this is possible:

prefix operator ¬
prefix func ¬ (value: Bool) -> Bool {
    return !value
}

let t = true
let f = ¬t

I have to admit that I quite like this but it has a couple drawbacks:
1: if you've never seen the ¬ operator in math it makes no more sense than "!"
2: It's quite tricky to find on your keyboard depending on your layout
3: maybe ~ is a better fit?

Seems like a lot of work for a very small improvement. But I'm all for it.

André

···

On 15 Feb 2017, at 22:28, Derrick Ho via swift-evolution <swift-evolution@swift.org> wrote:

There is no need to change it

Since the context basically disambiguates the meaning of !

The next best thing is to compare it to false

(val == false) // same as !val
On Wed, Feb 15, 2017 at 3:02 PM David Waite via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
If someone came with a nice syntax I’d be for this. I can’t imagine what that would be.

I doubt there is an alternate prefix or postfix operator that would pass muster, due to ‘!’ already meaning the appropriate thing in so many languages, and swift only supporting symbolic operators.

I can’t think of a method on boolean which would read properly either, e.g.

  if isValid.not() {…}

The closest I could think to a decent bike shed color would be a global function:

  if not(isValid) {…}

-DW

On Feb 15, 2017, at 11:10 AM, Robert Widmann via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

So you've identified the problem, but what do you propose as a solution here?

It should be noted that a (non-stdlib) language-level answer to this question has already been discussed and rejected (https://lists.swift.org/pipermail/swift-evolution/2015-December/000032.html).

~Robert Widmann

2017/02/15 9:02、Sadiq via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> のメッセージ:

Hello,

I would like to suggest to change Logical NOT Operator from ! to something else.
It will increase the readability of the code and will avoid any confusion with the symbol used for force unwrapping of optional values.
It would be easier for new programmers to learn Swift as the first language.
I don't understand the rational behind using the same operator for two different purposes.

Thanks and Regards,
Mohammad Sadiq
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Nicolas Fezans) #8

3: maybe ~ is a better fit?

just for information this is in line with Matlab in which the following
three "not"-related syntax exist:
a) ~ as a prefix operator for not
b) not as a function
c) ~= as an infix operator for "is not equal to"

I see pros and cons for each option and have a very slight preference for ~
over !.

I would however avoid ¬ because I would not like to have a character that
is not directly accessible on most keyboards for something as simple as a
not operation, even if I like these maths notations very much.

If it would be decided to keep ! I could imagine that adding syntax
coloration in code editors to make both uses of ! look a bit different
would help beginners and newcomers. This is more complicated to do than the
typical syntax coloration logic in text editors (syntax must be understood
for doing that), but this should not be a problem in Xcode.

If ~ would be preferred, I would recommend to continue accepting ! for one
or more versions of swift but with a warning recommending to change it (we
do not need to make a source breaking change when it is possible to
continue accepting it and to mark it as obsolete)

Nicolas

···

On Wed, 15 Feb 2017 at 22:55, André “Zephyz” Videla via swift-evolution < swift-evolution@swift.org> wrote:

As of today, this is possible:

prefix operator ¬
prefix func ¬ (value: Bool) -> Bool {
    return !value
}

let t = true
let f = ¬t

I have to admit that I quite like this but it has a couple drawbacks:
1: if you've never seen the ¬ operator in math it makes no more sense than
"!"
2: It's quite tricky to find on your keyboard depending on your layout
3: maybe ~ is a better fit?

Seems like a lot of work for a very small improvement. But I'm all for it.

André

On 15 Feb 2017, at 22:28, Derrick Ho via swift-evolution < > swift-evolution@swift.org> wrote:

There is no need to change it

Since the context basically disambiguates the meaning of !

The next best thing is to compare it to false

(val == false) // same as !val
On Wed, Feb 15, 2017 at 3:02 PM David Waite via swift-evolution < > swift-evolution@swift.org> wrote:

If someone came with a nice syntax I’d be for this. I can’t imagine what
that would be.

I doubt there is an alternate prefix or postfix operator that would pass
muster, due to ‘!’ already meaning the appropriate thing in so many
languages, and swift only supporting symbolic operators.

I can’t think of a method on boolean which would read properly either, e.g.

if isValid.not() {…}

The closest I could think to a decent bike shed color would be a global
function:

if not(isValid) {…}

-DW

On Feb 15, 2017, at 11:10 AM, Robert Widmann via swift-evolution < > swift-evolution@swift.org> wrote:

So you've identified the problem, but what do you propose as a solution
here?

It should be noted that a (non-stdlib) language-level answer to this
question has already been discussed and rejected (
https://lists.swift.org/pipermail/swift-evolution/2015-December/000032.html
).

~Robert Widmann

2017/02/15 9:02、Sadiq via swift-evolution <swift-evolution@swift.org>
のメッセージ:

Hello,

I would like to suggest to change Logical NOT Operator from ! to something
else.
It will increase the readability of the code and will avoid any confusion
with the symbol used for force unwrapping of optional values.
It would be easier for new programmers to learn Swift as the first
language.
I don't understand the rational behind using the same operator for two
different purposes.

Thanks and Regards,
Mohammad Sadiq

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Haravikk) #9

> 3: maybe ~ is a better fit?

just for information this is in line with Matlab in which the following three "not"-related syntax exist:
a) ~ as a prefix operator for not
b) not as a function
c) ~= as an infix operator for "is not equal to"

I see pros and cons for each option and have a very slight preference for ~ over !.

I would however avoid ¬ because I would not like to have a character that is not directly accessible on most keyboards for something as simple as a not operation, even if I like these maths notations very much.

If it would be decided to keep ! I could imagine that adding syntax coloration in code editors to make both uses of ! look a bit different would help beginners and newcomers. This is more complicated to do than the typical syntax coloration logic in text editors (syntax must be understood for doing that), but this should not be a problem in Xcode.

If ~ would be preferred, I would recommend to continue accepting ! for one or more versions of swift but with a warning recommending to change it (we do not need to make a source breaking change when it is possible to continue accepting it and to mark it as obsolete)

Tilde is already used in Swift for bit-flipping, though actually on a boolean type (if you treat it as 1-bit) bit-flipping and logical NOT are equivalent, and you can't use logical NOT an Ints at the moment anyway.
So tilde could be a good option, however the ~= operator also already exists in Swift for pattern matching, so couldn't be used as a replacement for !=, unless there's a better operator for pattern matching (personally I don't like using an operator for pattern matching at all but maybe that's just me).

···

On 15 Feb 2017, at 22:44, Nicolas Fezans via swift-evolution <swift-evolution@swift.org> wrote:

On 15 Feb 2017, at 22:28, Derrick Ho via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

There is no need to change it

Since the context basically disambiguates the meaning of !

The next best thing is to compare it to false

(val == false) // same as !val
On Wed, Feb 15, 2017 at 3:02 PM David Waite via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
If someone came with a nice syntax I’d be for this. I can’t imagine what that would be.

I doubt there is an alternate prefix or postfix operator that would pass muster, due to ‘!’ already meaning the appropriate thing in so many languages, and swift only supporting symbolic operators.

I can’t think of a method on boolean which would read properly either, e.g.

  if isValid.not() {…}

The closest I could think to a decent bike shed color would be a global function:

  if not(isValid) {…}

-DW

On Feb 15, 2017, at 11:10 AM, Robert Widmann via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

So you've identified the problem, but what do you propose as a solution here?

It should be noted that a (non-stdlib) language-level answer to this question has already been discussed and rejected (https://lists.swift.org/pipermail/swift-evolution/2015-December/000032.html).

~Robert Widmann

2017/02/15 9:02、Sadiq via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> のメッセージ:

Hello,

I would like to suggest to change Logical NOT Operator from ! to something else.
It will increase the readability of the code and will avoid any confusion with the symbol used for force unwrapping of optional values.
It would be easier for new programmers to learn Swift as the first language.
I don't understand the rational behind using the same operator for two different purposes.

Thanks and Regards,
Mohammad Sadiq
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution