- 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
Edit Admin
This is gold! A
For-Casethat doesn't need theFornor theCase. 🤣Admin
It could be so much improved:
if (frist) step1(); if (secnod) step2(); ....
Admin
I feel cheated. There is no switch, only if.
Admin
I think this may be the result of a dead requirement. At some point there was a perceived need to be able to execute steps 1 - n in a runtime determined order and the order of steps would be handed in as an array, list, whatever. The requirement got dropped or it was realised that there were no circumstances in which the steps would ever be run in any but one order, but the (part implemented?) code didn't get cleaned up properly.
Edit Admin
Or perhaps there was some additional logic at the beginning/end of that loop which would run between each step, but it got removed at some point?
Edit Admin
Wait, maybe I'm getting old and senile but isn't that just this?
Edit Admin
You're more with it than the developers responsible!
Edit Admin
Somone started with a for-loop and then got told about this newfangled thing called a "race condition" ....
Admin
Yes, yes it is.
Edit Admin
Ah okay. I thought it can't be that easy and there's some hidden thing I missed.
Welp, I guess there's always a complicated way to waste processing resources lol
Edit Admin
You can even do a For-Case using recursion!
Edit Admin
Once upon a time some coding jobs billed by LOC so now I'm wondering about the actual reason for the extra lines. 🤔 If it turns out this code was intentionally inflated it'd be pure genius because I don't think any LOC measurement algorithm of the era would be able to catch it and that's 175% extra for the exact same functionality.🤑
Admin
I have seen a similar pattern used before when steps need to be skipped in a way that makes it implausible to use regular ifs.
The place I most recently saw it was during an appointment booking system logic. It initialised it with a step from the order, then it'd attempt to do the next thing in the list, and that might do a bunch of skipping around in steps to find appointments based on other factors. So say you're booking a home visit for an elderly patient, we want to give preference to doctors they've worked with previously, but also get the appointment soon, and ideally while a doctor is already close, and maybe the patient has already expressed a desire to only be seen by doctors of a particular gender. There's a lot of little factors to consider and sometimes it's worth shuffling things around and trying a few variations to find the best fit for all the factors. Of course we didn't use numbers, we used constants labelled after the step names and sometimes it'd repeat steps with different parameters to try finding the best possible fit.
It got fairly complicated, but it worked really well for the end users which was the important thing.