blitz-research/monkey2

boolean operation priority is not intuitive to me, expected behaviour?

Closed this issue · 3 comments

In the following code I get a result that I'm not used to. The "Not" operator will take priority on the equals "=" operator. This is not intuitive to me (it's like if "If 1=0" would run if 0 means false and 1 means true)

Function Main()

	Local a:=3
	Local b:=4
	
	Print a=b
	Print Not a=b 'should give True? 
	Print Not (a=b)
	
End

Prints:
False
False
True

I'd personally would have expected:
False
True
True

Thanks

engor commented

Just another example, I saw that code in php project:

if (!$try = get_post('try')) {
......
}

or

if (!$f = fopen('life_problem.csv', 'rt')) {
......
}

And in php firstly work =(assign to variable in this case) and then ! (not).

Please, never write such code in any language! :)