- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
$isFrist = 0; $isFrist = (is_null($isFrist)) ? 0 : $isFrist;
Admin
No, it can't be sung to Rule Britannia... it fits neither the verse or chorus structure. You can try to jam loads of syllables into a single note, but it doesn't scan very successfully.
Heaven's command, by the way... heaven's command, matchless beauty, envy of them all... and don't any of you forget that.
Admin
Depends on how you choose to pronounce the symbols, or if you choose to. It also can fit to "Happy Birthday" and "Les Petits Reins" if you're creative.
Admin
I almost got it to work with "row, row, row your boat".
Admin
Well, you can fit the word "Blah" to The Modern Major General Song if you really want to, but you can't reasonably say that "it fits". Its just words badly fit to some random tune.
Just singing a melody with X notes, and sentence with Y syllables (Y!=X), in any old haphazard fashion, doesn't mean it scans.
Admin
initialTab = 0; if (isNaN(initialTab)) { initialTab = 0; } This is the Butterfly Effect pattern. Something might maybe have the possibility of having the probability to cause initialTab to change.
Admin
initialTab = 0; if (isNaN(initialTab)) { initialTab = 0; }
Probably best to check that initialTab is a number after that conditional assignment. After all, if the first assignment could fail...
Admin
I really like this quantum-indetermination safe code. The variable won't have its value determined until the moment when its value is actually observed.
Admin
I think me and Jeremy have worked at the same place. The guru there would always quote "belt, braces and superglue" when I asked him about his massive WTFs.
Admin
easter egg: click anywhere in "shell-shocked", and surprise!
Admin
I was slightly surprised when reading the one about Jeremy's ex-coworker.
Bear in mind that in "British English" (i.e. English not American) suspenders are called braces.
Suspenders are lingerie and imply a belt already!
Of course, this conjures up a totally different image depending on whether you've assumed the coworker is male or female.
Admin
Admin
Yes, they really should have been more careful and gone for something like:
initialTab = 0; while (isNaN(initialTab)) { initialTab = 0; }
Admin
Nested if statements: Easy to read, easy to follow the logic, easy to modify the logic if needed. Nested Ternary operations: Pain in the brain (way above neck) to read, easy to screw up the logic entirely by misplacing a bracket. Reminds me why I don't write code in LISP anymore.
Admin
How terribly unsafe. Better to do:
Admin
Is this what you have to do if you declare a floating-point variable to be volatile? Does it really need to be declared volatile? Let the optimizer do its job.
Admin
Or literally any Ludacris "song".
Admin
When your only tool is a shell_exec, every problem looks like a shell command.
And when your only tool is PHP, every problem looks like an opportunity to shoot yourself in the foot.
Admin
No difference really to ?: ?: can be harder to read per line, but you need fewer lines. Of course in this example, there was no need at all for nesting, if the "not editable" case had been handled first. And putting the source code into some structured form helps with readability.
Admin
initialTab = 0; if (isNaN(initialTab)) { initialTab = 0; }
It makes sense if
Admin
Admin
Unless, of course, the code in question was written in JavaScript, in which case, it's just stupid.
Admin
Fewer lines not a goal. Maintainability is.
That said, it's a case-by-case basis. I've used nested ternary when it's a simple case and was still easy to read.
Just try to review your code from the perspective of an outsider: is it something the functionality of which can be gleaned relatively quickly and properly? If not, go to the more verbose if-then-else construct.
Admin
No, it doesn't.
volatile
is not a substitute for synchronization.Admin
I prefer The Elements set to that tune, myself...
theeeeresss antimony, arsenic, aluminum, selenium...
Admin
And hydrogen and oxygen and nitrogen and rhenium, And nickel, neodymium, neptunium, germanium, And iron, americium, ruthenium, uranium, Europium, zirconium, lutetium, vanadium, And lanthanum and osmium and astatine and radium, And gold and protactinium and indium and gallium, <gasp> And iodine and thorium and thulium and thallium.
There's yttrium, ytterbium, actinium, rubidium, And boron, gadolinium, niobium, iridium, And strontium and silicon and silver and samarium, And bismuth, bromine, lithium, beryllium, and barium.
There's holmium and helium and hafnium and erbium, And phosphorus and francium and fluorine and terbium, And manganese and mercury, molybdenum, magnesium, Dysprosium and scandium and cerium and cesium. And lead, praseodymium, and platinum, plutonium, Palladium, promethium, potassium, polonium, And tantalum, technetium, titanium, tellurium, <gasp> And cadmium and calcium and chromium and curium.
There's sulfur, californium, and fermium, berkelium, And also mendelevium, einsteinium, nobelium, And argon, krypton, neon, radon, xenon, zinc, and rhodium, And chlorine, carbon, cobalt, copper, tungsten, tin, and sodium....
Admin
Yeah but that works, because Mr. Lehrer sat down and figured it out properly..... and hydrogen and oxygen and nitrogen and rhenium... and now look what you've made me do.
Edit: I bet the guy above didn't type that from memory.
Admin
I prefer the tune to "I am the very model of a Scientist Salarian." Or for the slightly older crowd who remembers Reboot. "Everything is alphanumeric."
Admin
Admin
Algeria Bulgaria Cambodia Dominica Egypt France the Gambia! Aitch-teem-ell, zero. Japan Kazakhstan, Lybia Emm-el, HTML! Norway, Oman, Shell exec, Qatar Russia mysql Turkey Uruguay Vietnam. Handle the error! Yemen Zimbabwe!
Admin
Did you just have a stroke in your superior temporal gyrus?
Admin
Perhaps singing code out loud is not a thread-safe operation.
Admin
So, definitely a stroke then.
Admin
Admin
Yah, I had to look up the rest of the lyrics...
I can still recite "Mother", "Pigeons", and "Irish Ballad" from memory though (much to the dismay of those around me...)
Admin
Let's see if formatting that ternary makes it any clearer... (pffftt...!)
Nope, no luck. The author of this pile of shite should be sentenced to debugging and modifying this pile of code excrement on a Friday afternoon before a holiday weekend.
Admin
Ah, but people have coding standards you know! The type of thing that says 'there shall be no more than 20 lines per function'. So, you have to squeeze as much into each line as you can! You can even fit several actions onto a single line if you use commas judiciously, even if your coding standards mandate only on statement per line.
Admin
I rewrote it clearer:
This still isn't good though. The main problem is that the method is doing too much. It should just return the finance credit, not do validation as well. Validation should be done in a separate method which can be called if necessary.
Although there are still more problems such as the need for NullMoney.NULL_AMOUNT at all and the fact percentageOfBasis can equal null (why not have a default?). The naming also is faulty and unclear.
basis.multiply(percentageOfBasis)
What does that have to do with finance credit? the term finance credit isn't in the names of those variables at all.
And NullMoney.NULL_AMOUNT. WTF does that even mean?
Surely it means something like Money.InvalidState
But even that is a WTF why not return null?
Admin
That definitely improves on it, but I personally I still feel it's needlessly complicated. If you're not doing something trivial like
then I have to disagree with a ternary approach. Even a somewhat veteran programmer needs to "process" that way more than should have to considering the appropriate if/else structure could be followed by someone 2 days into programming 101.Admin
Yeah... maybe you should architect your code to break large functions into a number of smaller, maintainable functions, then you wouldn't have to rely on esoteric language features to smugly get round that shit.
Admin
Admin
Indeed. I'm not sure I agree with just declaring "no function can be over 20 lines, ever, period." But the point of such a declaration is that a large function is a sign you're doing something else wrong, not an invitation to "collapse" your overdone function into an even crappier version.
Admin
Admin
Admin
So its agreeded then.
"if not x then without-x else with-x" is a bad pattern.
Prefer "if x then with-x else without-x".
Admin
Then why dont you use a good old if() structure? There no adventage to use ternary ops in this case.
Ternary operator are always horrible to read. The only case where i use it is on SSIS with the conditional split because you can only enter ONE line of code w/o indentation/carriage return. It often give a mess worst then the today's wtf.
You should kill the inventor of ternary ops!
Admin
heh
Admin
The real coding standars is: Make your code readable!
using an horrible ternary to save you 3-4 lines of code is worst then make a function with over 20 lines.
Admin
Multiple returns in a statement? Blasphemy!
Admin
TRWTF is, as usual, PHP.
If anyone working on your codebase has even thought about PHP, ternary operators should be verbotenated.
(And anyone who nests them should be sucker-punched once for every ? and twice for every : in the expression)