How Princess Diana and Sarah Ferguson went from childhood friends to falling out: ANDREW LOWNIE reveals the inside story of their fractured bond
Is Russell Crowe the angriest man in showbiz? From his notorious BAFTA outburst to throwing a telephone at a hotel concierge as the actor's temper surfaces again during autograph row
How Off Campus heartthrob Belmont Cameli saved SEVEN lives after donating his kidney before rocky rise to fame with Amazon Prime smash hit
CHRISTOPHER STEVENS reviews Richard Madeley's Inside The World's Mega Prison: His chat show charm doesn't wash in El Salvador's hell hole jail
Terrifying moment British racehorse violently kicks out at female groom - before she was rushed to hospital
Gliding club issues statement after aircraft crash
Gliding club issues statement after aircraft crash
M25 crash near Dartford Crossing sparks four miles of rush hour traffic queues
Perfect Randomness Realized For the First Time
Read more of this story at Slashdot.
Company CEO flooded file share with smut, called for help after he deleted it
Trump's DOJ launches criminal probe into former New York magazine writer E Jean Carroll, who accused him of sexual assault
Cops confirm grandparent of missing boy Gus Lamont still remains a suspect in his disappearance - as officers fail to find a single scrap of evidence after eight months and 11 searches: 'It's hard to explain'
Three knives seized and 13 arrests after groups of youths flock to Southend
Husband killed and wife injured after home explodes in a leafy Michigan suburb... now cops believe he sparked blaze in murder-suicide attempt
Restore Britain reinstates sacked member who posed doing Nazi salute after furious backlash from hard-Right supporters
Dave Grohl's nepo baby Violet, 20, name drops him twice while promoting debut album... after his secret baby scandal
CodeSOD: What Condition is This
Untodesu sends us this submission, with this comment:
Literally no idea what kind of drugs the guy was taking but nonetheless we've rewritten it to be just a two-liner
Well, that doesn't tell us a lot about what to expect from the code, but let's take a look.
QStringList TableViewAssembly::parametersFilter(ProbePart::Type type, int pos, QList<ProbePart> probeDesign) { QString to, from; if(pos == -1) { if(probeDesign.length() == 0) { to = "*"; from = "AutoJoint"; } else { to = probeDesign.at(0).fromMounting();; from = "AutoJoint"; } } else if(pos == 0) { if(probeDesign.length() == 1) { if(probeDesign.at(pos).type() == ProbePart::Type::Stylus) { to = probeDesign.at(pos).fromMounting(); from = "*"; } else { to = "*"; from = probeDesign.at(pos).toMounting(); } } else { to = probeDesign.at(pos + 1).fromMounting(); from = probeDesign.at(pos).toMounting(); } } else if(pos == probeDesign.length() - 1) { if(probeDesign.at(pos).type() == ProbePart::Type::Stylus) { if(probeDesign.length() <= 1) { from = "*"; to = probeDesign.at(pos).fromMounting(); } else { from = probeDesign.at(pos - 1).toMounting(); to = probeDesign.at(pos).fromMounting(); } } else { from = probeDesign.at(pos).toMounting(); to = "*"; } } else { from = probeDesign.at(pos).toMounting(); to = probeDesign.at(pos + 1).fromMounting(); } return { to, from }; }QStringList andQList tell me that this is a Qt-based application. The goal of this function seems to be to take some inputs about a "probe part" and construct a pair of strings. Let's trace through it.
Let's just walk through the conditions, quickly, without worrying too much about the inside. We look at pos, and check for three cases: either pos is -1, 0, or probeDesign.length() - 1.
Inside each of those branches, we also check the length of the list, testing if it contains no elements, exactly one elemnet, or more than one element. We also check if the part in question is a stylus.
With that in mind, let's see if we can summarize the conditions here. If pos == -1, we do some automatic stuff, using the first element in the list if there is one. If pos == 0 and there's exactly one element in the list, we grab the first element and link it to * (the to/from order depends on the stylus question). If there's more that one element in the list, we pair the current pos with pos+1; notably, in this branch, pos is definitely zero. If pos is the last element in the list, we follow the same logic, but pair with pos-1, with a side branch for checking against the length of the list.
It's all bounds checking. That's all this code is. Bounds checking that's gotten out of hand. The main branch here is actually the final else: that's where most of the code is going to pass through. All the other branches are just handling edge cases. Literal edge cases, as in "the edge of the list".
Untodesu didn't supply the two line version, but based on the fact such a version exists, I also suspect that many of these branches weren't actually used. Or, at least, based on the actual business rules, could be combined.