Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
I used is_numeric instead of ctype_digit because I've never heard of the latter and cannot see the difference.
EDIT | Ok, ctype_digit means every character in the string must actually be a digit, whereas is_numeric has support for hexadecimal numbers and what not. Still would go with is_numeric because it's alot clearer what the function does.
Don't think there's anything wrong with either approach, just down to personal preference. Got used to using the ternary style but I suppose it doesn't make any difference either way.
I try to write my code so newbs can read it and follow the logic.
Couldn't think of a good phrase in place of line-friendly! Y'know what I mean.
More readable for newbs, but the more lines you have, the more readable it is. So you have to strike a happy medium, which I think my code does. In my opinion.
Couldn't think of a good phrase in place of line-friendly! Smile Y'know what I mean.
'fraid I don't. Who cares about lines of code anyway?
You don't actually need ternary for anything you know, its just a shorthand. I find myself using it on occasion most of the time I can force myself to use an if..else and it looks better for it when I can't force myself to use if..else is usually because I'm feeling lazy -- which is a really great motivator for good code.
feyd wrote:I try to write my code so newbs can read it and follow the logic.
Amen to that brother!
Readable code, for me, is understandable code. Same as commenting, in my opinion. What the code does not explain clearly the comments do, but I would hope that no one looking at my code would ever look at it and scratch their head asking what that means.
I use them (and will continue to do so) as I don't see what is difficult to understand about them. Have never come across a need to next them tho, but i imagine that could become messy
Using ternary style in PHP, is like using l33t speek in ur lang.
Shorter is harder to read by other people. I agree with Everah and Feyd - and I also have banned ternary and on occassion even the short single line if() condition in a coding standard. Sure longer versions of conditions take longer to type, but they often make things more obvious. In my view, if I have to slow down to decipher a piece of code I'm more likely to rewrite it on the spot to a) figure it out, and b) not have someone else down the line spend the extra seconds figuring it out. We developers are supposed to be lazy people, but sometimes that laziness can bite you in the future.