Two expressions, do they have the same result

0
I am fairly confident the answer is yes, I am just having one of those days where I am second guessing myself…   In a visibility check, these two expressions will give the same result, they just calculate it differently?   not($dataView6/DiscrepancyInStock)   $dataView6/DiscrepancyInStock = false  
asked
2 answers
3

They should be the same.

 

You can verify this by writing out a truth table.

not($dataView6/DiscrepancyInStock)

IN     OUT

true  false

false true

$dataView6/DiscrepancyInStock = false

IN     OUT

true  false

false true

I hope this helps.

answered
2

Hello Garion,

 

As you mentioned the answer is YES. But below is the explanation in general of how they are executed internally.

 

 not is a unary operator. "Unary" means that it takes one operand (compared with a binary operator such as +), which must be a Boolean expression. Strictly speaking, True and False are simple Boolean expressions so there is nothing wrong syntactically in writing not True, but as you note it would be pretty pointless. It is more usual to apply not to a boolean variable or expression whose value is only known at runtime.

It really depends on what logic you want to code. For example, you might have a boolean variable someting_happened that is true when something you are interested in happened, and perhaps you want to respond in the case that the thing didn't happen. In this case, you would write your code as:

 

if not something_happened:
    ... #do something in response

You might also use not to build up a more complex expression:

is_round = ... # could be True or False 
is_blue = ...   # ditto

if is_round and not is_blue:
   # only interested in round things if 
   # they aren't blue
   ...

 

Hope this helps in using both the option as per your needs.

 

answered