if(a || b)
But to my knowledge we don't have:
if(a ^^ b)
I believe it would be a functional && helpful addition to the list of operators.
ID:1903758
Jul 25 2015, 3:10 am
|
|||||||
Redundant
| |||||||
We currently have:
if(a || b)
But to my knowledge we don't have:
if(a ^^ b)
I believe it would be a functional && helpful addition to the list of operators. |
More workarounds, just for fun:
!a == !!b |
I've played enough roguelikes to know that shop has a lot of rings and potions and seems to have been invaded by a parade of ants and blobs.
|
In response to Ter13
|
|
O. o wut
|
In response to Ter13
|
|
Ter13 wrote:
I've played enough roguelikes to know that shop has a lot of rings and potions and seems to have been invaded by a parade of ants and blobs. I get it lel |
As useful as this would be, I've never heard of a language supporting this. The easiest workaround I know of is !a != !b.
|
In response to Lummox JR
|
|
Lummox JR wrote:
As useful as this would be, I've never heard of a language supporting this. The easiest workaround I know of is !a != !b. Personally, I think the reason no other language does this is because it doesn't short circuit like && and || do, because that's how the logical operators work; It'd be nice to have it, but for consistancy I wouldn't because of short circuiting. I use something like bool x = a; in C++ though. |
In response to Pokemonred200
|
|
Agreed. I think that's the reason as well.
|
In response to Lummox JR
|
|
To quote Dennis MacAlistair Ritchie (Creator of C):
"There are both historical and practical reasons why there is no ^^ operator." "The practical is: there's not much use for the operator" "The main point of && and || is to take advantage of their short-circuit evaluation not only for efficiency reasons, but more often for expressiveness and correctness." "By contrast, an ^^ operator would always force evaluation of both arms of the expression, so there's no efficiency gain. Furthermore, situations in which ^^ is really called for are pretty rare, though examples can be created. These situations get rarer and stranger as you stack up the operator" In conclusion: "My guess is that &,&& |,||; ^,^^ is a false symmetry. But it's one that people seem to want, and, though it's not much help, adding it wouldn't do much harm." |
if((a || b) && !(a && b))