dark_master4, on Sep 7 2009, 04:33 AM, said:
All right, but in any case, it's not a bad programming practice to use multiple and in an if statement. I get your point.
It isn't, but I can show you an example of a bad way of using
and, which many people people do.
Using the last example, doing this in GML, is ok. Your not going to suffer any speed lose, really, so you can get away with doing it.
if ((x==5) and (y==6) and (z==10))
{
//do stuff.
}
However, new programmers, often have a set up like this,
if ((x==5) and (y==6) and (z==10))
{
//do stuff.
}
else
if ((x==5) and (y==6) and (z==11))
{
//do stuff.
}
Obviously, it is FAR superior to use nested if statements, in this case. Which is why, I think it's a good habit to get into, using nested statements. (although, lazy programmers like me, still use
and....

)
B&B_Gaming said:
The reason this is is because it's not always that simple. Take this for example:
if x==5 or (y==6 and z==10)
While this may be easy for you to tell what does and doesn't need to be checked, for an interpreter it's not as clear. Devising a general set of rules that will work for all conditions would be complicated, and even after you get that the implementation may even result in a speed decrease because of what needs to be checked. Remember that GM has extremely loose syntax.
I'm not sure I understand you. The interpreter reads the expression (y==6 and z==10), and if either of those two statements are false, (I'm guessing this is c++, so...) it will short-circuit, and return the value 'false'. (which, if x==5 is false, means that the entire expression is false).
I thought Boolean logic, was something computers excelled at. [It's certainly not something I find easy!]
Quote
It's simpler to just leave the responsibility in the user's hands. If it's necessary you can simply split the conditions up like this:
if x==5 { if y==6 { if z==10 {
}}}
To implement your own short-circuiting and still save line space.
That's pretty neat, actually

But I'm, personally, not fussy about saving line space, since the more space there is, the more room it is to put comments.
I just had a thought, since GM8 is being written in C++, does that mean it will have short-circuiting?
This post has been edited by Desert Dog: 06 September 2009 - 11:07 PM