{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreigcwqb7vgujm2n7csxmn6lgj3gedk27d73dq7aa6wy2l2szcker2q",
"uri": "at://did:plc:vyjlfm46mfv6u4vjp6qtrfx2/app.bsky.feed.post/3mmwnfiitem32"
},
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreidg2k33tiuupnstmiowh7hyyvtsbe3gyhfygiytrzynysnhoctrxi"
},
"mimeType": "image/jpeg",
"size": 81260
},
"path": "/articles/what-condition-is-this",
"publishedAt": "2026-05-28T06:30:00.000Z",
"site": "https://thedailywtf.com",
"tags": [
"CodeSOD",
"Utilize BuildMaster",
"Download"
],
"textContent": "**Untodesu** sends us this submission, with this comment:\n\n> Literally no idea what kind of drugs the guy was taking but nonetheless we've rewritten it to be just a two-liner\n\nWell, that doesn't tell us a lot about what to expect from the code, but let's take a look.\n\n\n QStringList TableViewAssembly::parametersFilter(ProbePart::Type type, int pos, QList<ProbePart> probeDesign) {\n QString to, from;\n\n if(pos == -1) {\n if(probeDesign.length() == 0) {\n to = \"*\";\n from = \"AutoJoint\";\n } else {\n to = probeDesign.at(0).fromMounting();;\n from = \"AutoJoint\";\n }\n } else if(pos == 0) {\n if(probeDesign.length() == 1) {\n if(probeDesign.at(pos).type() == ProbePart::Type::Stylus) {\n to = probeDesign.at(pos).fromMounting();\n from = \"*\";\n } else {\n to = \"*\";\n from = probeDesign.at(pos).toMounting();\n }\n } else {\n to = probeDesign.at(pos + 1).fromMounting();\n from = probeDesign.at(pos).toMounting();\n }\n } else if(pos == probeDesign.length() - 1) {\n if(probeDesign.at(pos).type() == ProbePart::Type::Stylus) {\n if(probeDesign.length() <= 1) {\n from = \"*\";\n to = probeDesign.at(pos).fromMounting();\n } else {\n from = probeDesign.at(pos - 1).toMounting();\n to = probeDesign.at(pos).fromMounting();\n }\n } else {\n from = probeDesign.at(pos).toMounting();\n to = \"*\";\n }\n } else {\n from = probeDesign.at(pos).toMounting();\n to = probeDesign.at(pos + 1).fromMounting();\n }\n\n return { to, from };\n }\n\n\n`QStringList` and`QList` 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.\n\nLet'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`.\n\nInside 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.\n\nWith 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.\n\n_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\".\n\nUntodesu 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.\n\n[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!",
"title": "CodeSOD: What Condition is This"
}