boolean operation priority is not intuitive to me, expected behaviour?
Closed this issue · 3 comments
abakobo commented
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
blitz-research commented
Yeah I sort of agree but this is the way 'C' does it so I went with that.
Perhaps I should have been a bit bolder here, but it's too late now. To
change it would likely quietly break a ton of code due to monkey2's relaxed
bool conversions.
…On Wed, Jan 16, 2019 at 6:21 AM abakobo ***@***.***> wrote:
In the following code I get a result that I'm not used to. The "No"t
operator will take priority on the equals "=" operator. This is not
intuitive to me (it's like if "If 0=0" would run if 0 meant false)
Namespace myapp
#Import "<std>"
Using std..
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
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#452>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADU3QnrhtXw36EjUgsR6woWbUlYcXEjqks5vDg4egaJpZM4aBbpr>
.
abakobo commented
Thanks, glad to see Monkey2 behaves as expected!
Le sam. 19 janv. 2019 à 00:37, Mark Sibly <notifications@github.com> a
écrit :
… Yeah I sort of agree but this is the way 'C' does it so I went with that.
Perhaps I should have been a bit bolder here, but it's too late now. To
change it would likely quietly break a ton of code due to monkey2's relaxed
bool conversions.
On Wed, Jan 16, 2019 at 6:21 AM abakobo ***@***.***> wrote:
> In the following code I get a result that I'm not used to. The "No"t
> operator will take priority on the equals "=" operator. This is not
> intuitive to me (it's like if "If 0=0" would run if 0 meant false)
>
> Namespace myapp
>
> #Import "<std>"
>
> Using std..
>
> 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
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#452>, or mute the
thread
> <
https://github.com/notifications/unsubscribe-auth/ADU3QnrhtXw36EjUgsR6woWbUlYcXEjqks5vDg4egaJpZM4aBbpr
>
> .
>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#452 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ANBkSRAM7ykJKxy33uInNW2JsU4noJ41ks5vElqggaJpZM4aBbpr>
.
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! :)