(This thread is a spin-off from https://www.b4x.com/android/forum/threads/1-1.117065/, which is a really interesting thread that I encourage people to read in full.)
I feel very naïve here, but I'm also learning a lot so I feel I have to ask a couple of follow-ups.
1. You're sort of saying that the left side decides how the comparison should happen, and that the right side is cast'd to same type as left side, is that correct?
2. In your example above, is either "a" or 1 considered an object? Because if they're not, perhaps that example isn't relevant..?
3. I suspect this would cause a lot of problems that I can't foresee, but I have to ask: If both sides of the equality comparison are different types, wouldn't it make sense to just consider them different and return false, instead of crashing?
I mean, if the compiler sees a comparison where one side is an object and the other is not, and its safer to put it on the right side of the comparison - couldn't the compiler just switch places so that the object is always is on the right side?
It is not possible as it will have other side effects. The left side type has semantic meaning.
B4X:Log("a" = 1) 'string comparison ("a" = "1") = false Log(1 = "a") 'numeric comparison => crash
I feel very naïve here, but I'm also learning a lot so I feel I have to ask a couple of follow-ups.
1. You're sort of saying that the left side decides how the comparison should happen, and that the right side is cast'd to same type as left side, is that correct?
2. In your example above, is either "a" or 1 considered an object? Because if they're not, perhaps that example isn't relevant..?
3. I suspect this would cause a lot of problems that I can't foresee, but I have to ask: If both sides of the equality comparison are different types, wouldn't it make sense to just consider them different and return false, instead of crashing?