PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
It is easier to read...but that would be going against standard practice...as PHP is a C derivative...
It's bad enough every programmer has his/her own programming styles...by using the literal equivelants for logical connectives...you just further convoluting your source code and although not confusing anyone...certainly going to make people think your a newbie with a single booby using those instead of traditional &&
Last edited by s.dot on Thu May 18, 2006 9:43 pm, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
I read that, but I can't think of an example of where && or AND would ever actually make a difference. Unlike math operators, where precedence can result in a different result.
Although I can't think of an example either, it changes the order in which your code is read (and thus interpreted). I'd like to see an example of this affecting output, if anybody has one.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
I most often use "and" instead of && because they are lower precedence. Partly because it's easier for others to read and partly because I can bump up the precendence when I need it. I also dislike having to place lots of parens just to make the precendence work right for those occasions where I need to mix them. I've been in far too many situations where I have paren soup to deal with.. not of my own creation, mind you.
feyd wrote:I most often use "and" instead of && because they are lower precedence. Partly because it's easier for others to read and partly because I can bump up the precendence when I need it. I also dislike having to place lots of parens just to make the precendence work right for those occasions where I need to mix them. I've been in far too many situations where I have paren soup to deal with.. not of my own creation, mind you.
Interesting...I had no idea there was a difference in precedence order...
Although I fail to see a practical example...of when one would use AND over &&
first called.
third called.
fourth called.
bool(false)
As you can see $second is assigned the results of the logical combination of third() and fourth(). Since fourth() returns a false the rest of the if's evaluation is shortcircuited. I try to avoid these sorts of set ups though as they will likely confuse the hell out of a "newb" to the precedence wars; so my code gets a bit longer, but it's more readable for the less experienced (and crazy.)
first called.
third called.
fourth called.
bool(false)
As you can see $second is assigned the results of the logical combination of third() and fourth(). Since fourth() returns a false the rest of the if's evaluation is shortcircuited. I try to avoid these sorts of set ups though as they will likely confuse the hell out of a "newb" to the precedence wars; so my code gets a bit longer, but it's more readable for the less experienced (and crazy.)
I personally preffer to stay consistant with using && and using brackets to show precedence. It is much easier to read.
Although ofcourse you need to know precedence order to be able to read others code (feyd's)
Well from a logical standpoint, I started off using '&&' because I had some C++ background. I found that 'and' is much better at the showing what you mean. I don't think it is n00b, just logical and from the readability standpoint it gets a higher score than '&&'.
From standard practice I always use '(' and ')' when I have two or more conditional statements. I suppose it came also from my C++ background and I don't think it decreases readability, but increases it. Even with 'and', it shows you exactly what is going to be evaluated in groups.