Similar to the useless use of cat award. The useless use of if award highlights code examples where people use the if function or ternary operator when the return of the expression does the exact same thing. I first noticed this with returning boolean values from php functions. To protect the innocent the winner of today’s award will remain anonymous.
<anonymous> to my knowledge, youll have to SUM(IF(your_field <> “”, 1, 0)) as total_non_empty
Ignoring that the whole query should be using where your_field != ” and group by the non if() way to write this is:
SUM(your_field <> ”)
These examples aren’t an award to a specific person since I’m digging them up from my memory. This pretty much applies to both C and PHP.
$str = 'foo';
return $str == 'foo' ? TRUE : FALSE;
Can be written as
$str = 'foo';
return $str == 'foo';
I hope this helps you save a few keystrokes when writing code in the future.
I woke up last friday and sat down at my computer much like I do every day. Only this day was different. My DSL was dead! After a bit of diagnostic work I found that my phone line was also dead. “Diagnostic work” means pulling a phone out of the closet to see if it has dial tone. Nothing but silence. So I went to work and was too busy friday to deal with it before going on vacation saturday. So today I finally get around to calling AT&T.
AT&T has one of those annoying voice call systems that try to require you to say what your problem is and they decide which option that most closely matches. I’m not sure who came up with this system but they should be shot. Anyone that couldn’t figure out the old multiple choice system has no business owning a phone. AT&T’s new system makes me feel very awkward. I can’t stand talking to a computer voice. In my desperation to find a way out of talking to the machine I found out that AT&T built in a way to use the old system, they just don’t tell you about it. If you press zero (or speaking garbled) a few times when the system answers you a question it will say
“I’m sorry let’s try this another way. I will give you a few options and you pick the one that sounds the best.”
Sweet! Thank god for that fallback or else I would have been very testy when talking to the operator after saying my phone number 3 times and picking 8 different options.
I still can’t figure out why they make people put in their phone number 3 different times then say it again to the operator when he/she answers the phone.
After getting an operator who then called the CO to do some diagnostics my land line rings. The operator said it was a loose jumper at the CO… Bastards…