Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XOR operator '^' for bools #22740

Closed
wants to merge 1 commit into from
Closed

Conversation

DavidSichma
Copy link
Contributor

closes #18816

The bitwise xor operator (^) has been extended to also work as an logical operation.

@aaronfranke
Copy link
Member

aaronfranke commented Oct 5, 2018

How is this different from !=?

@akien-mga akien-mga added this to the 3.1 milestone Oct 5, 2018
@akien-mga akien-mga changed the title '^' now can be used on bools XOR operator '^' for bools Oct 5, 2018
@akien-mga
Copy link
Member

The code could be simplified with p_a._data._bool != p_b._data._bool since that's the same as XOR for booleans.

I don't mind adding this, but I also don't see much use case since != is the same. Opinions welcome.

@bojidar-bg
Copy link
Contributor

Given that the other bitwise operators don't work on booleans, I would prefer to have a special boolean-xor operator than that (e.g. x ^^ y?).

@akien-mga
Copy link
Member

Given that the other bitwise operators don't work on booleans, I would prefer to have a special boolean-xor operator than that (e.g. x ^^ y?).

Well then I'd prefer none at all if it's the same as !=... We don't need to create another operator/another token for a feature that is not needed.

@DavidSichma
Copy link
Contributor Author

I made this PR merely for training c++. The addition of this little feature seemed like a good task to me.

I know that this is not a necessary feature. != is pretty much the same, not many folks use xor and with optional typing this won't even add type safety. The only people profiting would be those expecting ^ to work out of the box.

If you don't want to add ^ then don't. I got my bit of training so I am happy either way.

@ghost
Copy link

ghost commented Oct 5, 2018

Even though logically it is the same as !=, at least in my case sometimes conceptually they seem different or are recognized more immediately in certain context. Not equal and one or the other.

Check if these are not equal. A != B
Allow only one of the options. option_1 xor option_2

Though redundant I wouldn't mind xor and ^^ for the sake of readability and preferences. There were one or two occasions in months past where I would've reached for it, because in the context it would've been easier for me when reading it later down the road.

Something like: (A and B) xor not C against (A and B) != not C

@akien-mga akien-mga requested a review from vnen October 11, 2018 15:33
@vnen
Copy link
Member

vnen commented Oct 22, 2018

If this is really needed we could add ^^ and xor operators for booleans. But I'm against using ^ for booleans, to be consistent with & and | being bitwise operators that only works with integers.

@DavidSichma
Copy link
Contributor Author

Most languages don't have an logical xor operation and just use the bitwise xor. The ones that actually have an logical xor usually just overload ^. Java and C# do it this way. I don't think adding a new ^^ operator just for GDScript would be a good idea.

And I wouldn't go through the hassle of adding a new 'xor' operator, token and all unless there were a decent amount of people requesting the feature.
I think I will just close this PR if it does not pick up some interest in the next days.

@akien-mga
Copy link
Member

As per the above discussion, I don't think this is a useful addition for now, since it doesn't have any practical use case nor strong community involvement to get it nevertheless.

I'll also close the original feature request as such. Thanks for working on it and pushing the discussion forward though!

@akien-mga akien-mga closed this Nov 1, 2018
@DavidSichma DavidSichma deleted the xor branch November 24, 2018 12:46
@groud groud mentioned this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Bool XOR from GDscript
5 participants