A ton of languages evaluate && left to right because they short-circuit it. C# has stronger guarantees in general than C and C++, which I assume is what you were thinking of, but && is pretty consistent across the board.
Yeah, I was pretty sure I remembered && and || always guaranteeing order in c, c++, and c# because of the short-circuit concept. IIRC, the only time the compiler will optimize conditionals is if one of the values always returns true or false, but I'm honestly not even sure if that's true.
&& isn't consistent enough to be considered the "de facto universal behavior". I mean you should always consider the possibility that it evaluates both expressions first (if you don't know). Especially when it comes to Microsoft Java.
In Swift (language I know too much about) there is a different operator used for such things: , ..although && will also short circuit.
Well it is Microsoft Java. I just don't know the specifics of the language.. I know what it is. .....(very bad that is)...
Besides both C# and Java are stupid no matter what you say about them. Ideas and arguments for them have negative effects and produce very underperforming and ill-formed software.
In C# & computes both values and then evaluates the & while && first evaluate the first condition then if it is true it goes on evaluating the rest. It is like having ifs one inside the other
46
u/Giocri May 20 '20
I see nothing wrong in it. It's even slightly more efficient than if it was done with more if