Windl, Ulrich
2024-02-07 11:39:57 UTC
Here is a problem:
I have a selftest that goes like "if ($obj->method()) { fine() } else {bad() }" I id coverd that depending on the version of some external module, the logic may be inverted, because the test should have failed actually if the module weren't broken
So to fix, I added a variable Boolean $broken, and the logic would be "if ($broken && $obj->method() || $broken && ! $obj->method()) { fine() } else {bad() }", obviously an XOR. However as I don't really know whether the method returns a number, I cannot use the ^ (bitwise) operator, and abviously there is no ^^ logical operator.
Here is the syntax that I'm proposing:
if (!($broken ^^ $obj->method())) { fine() } else {bad() }" (if I got the logic right)
Here are the benefits of this:
With & and &&, | and ||, (~ and !) that just seems logical to have ^and ^^.
Here are potential problems:
I don't see any potential problems with that.
I have a selftest that goes like "if ($obj->method()) { fine() } else {bad() }" I id coverd that depending on the version of some external module, the logic may be inverted, because the test should have failed actually if the module weren't broken
So to fix, I added a variable Boolean $broken, and the logic would be "if ($broken && $obj->method() || $broken && ! $obj->method()) { fine() } else {bad() }", obviously an XOR. However as I don't really know whether the method returns a number, I cannot use the ^ (bitwise) operator, and abviously there is no ^^ logical operator.
Here is the syntax that I'm proposing:
if (!($broken ^^ $obj->method())) { fine() } else {bad() }" (if I got the logic right)
Here are the benefits of this:
With & and &&, | and ||, (~ and !) that just seems logical to have ^and ^^.
Here are potential problems:
I don't see any potential problems with that.