- 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
It's almost as if
should be
in which case it would, indeed, be an interleaver.
Admin
The hard part to see is what the wider point of this code is, even if it was an interleaver. Why would anyone actually need to reorder
LaborService
s like that?Admin
Bonus points for the author to call out "tranposition" but writing about a "C# fuction" themselves.
Admin
QuickSort?
Admin
fuction?
Admin
I have no idea.
Admin
Or perhaps they refer to it as a "fuction" as a humorous riff on the typo of Tranpose...
Admin
I think 'fuction' is probably the best description of that piece of code.
Admin
Could be something to do with pagination, printing evens then odds, assuming a device that prints/engraves/scans/craps on a stack of media one side at a time, then does the other side. Although you'd expect one half to be in reverse order then, probably.
Unless we discover what calls it we'll never really know. either, seems a bit of a cack-handed way to do it.
Admin
The fact that '"fuction"' is quoted in the original article seems to suggest this, doesn't it?
Admin
It looks like an algorithm to find the firing pattern for the eight cylinders of a 1969 Plymouth.
Admin
Am I the only one annoyed by the if/else inside the for loop ? Looping on one half, then on the other, would be more efficient and readable (it would still make no sense, though).
Admin
This looks like a bad attempt of "For homework, write a program that uses a Merge Sort routine" and was written in the 5 minutes between classes on the day it was due. It sorta sorts, and it merges the list with exquisite WTFery, right?
Admin
I feel like I have written a lot of "fuctions" over the years.
Admin
*its
Admin
A true What The Fuction
Admin
I find the fact that the order appears to have been added specifically in order to do this kind of telling, actually. My guess is that this is someone's about 1/8 completed progress towards something that was never finished - this was a checkpoint with a minimal-effort placeholder for the math, they left to go look up the correct math or maybe the correct spelling of "transpose" - or perhaps what the word was they were trying to remember that actually described what they were doing, which was not transpose - and never got back to it.
I have no strong evidence for this hypothesis but I am inordinately fond of it.
Admin
This feels a bit like a half-baked attempt to do something based on a heap, where the items "under" node n would be at 2n and 2n+1, but it doesn't actually do that.
Admin
This looks like a (broken) implementation of a Faro shuffle, but it missed the mark. At least it is not throwing away any data. On my first reading during BC (before coffee), I was thinking it was setting the element of the original list to the positions in the resulting list, which would have overwritten element and left gaps. Thankfully, it just set the Order member and sorted on that to get a different ordering.
Still, these are LabourServices, not playing cards, so why try a Faro shuffle on them? Trying to mix us scheduling or something?
Addendum 2020-11-10 12:03: Oops, mix UP scheduling...
Admin
its like shuffling cards. In real life when you shuffle you never get the cards perfectly interleaved so this perfectly represents the partial interleaving of an actual physical shuffle. Now call it three, four times in a row and you've created a manual card shuffle. It's brilliant*.
Admin
My thought is its a defective attempt at a fair share algorithm. The business use case is something like a government website showing a roster of LaborServices to would-be job seekers. But the site cannot show favoritism between the services and therefore needs to show each successive pageview the same list of e.g. 8 items but in a different order.
The dev thought truly random would be too hard, or not provably "fair" to the PHBs. So they went for some sort of a shuffle. Which they duly fouled up.
it would be interesting to look at the wider app to see if the persistence layer saves the updated order field back to the backing store or if the results of a run of this function are saved and used as input to the next run.
Admin
I'm pretty sure you'd still need to remove the "i" for that to be the case.
Admin
It does read like some sort of stream-of-consciousness thing; the way
half
is calculated is less real-world code and more a peek into someone's thought processes.Admin
Of course, if it was a fair share thing, rather than shuffling, I'd just do it in a round-robin way where the second element of the list before is now the top element of the list now, and the top of the list before is at the bottom of the list now. That way they all have their time at the top equally.
Of course, one needs to consider the possibility that an option gets removed and you might accidentally skip two ahead, but without the requirements, that consideration may be moot to begin with.
Admin
I once saw someone create a producer/consumer model where id's with alternate starting-letters went to different consumers (e.g.: consumer 1 did a/c/e/g/... and 2 did b/d/f/h/...). Maybe they were going for something like that? Admittedly it's stupid...
Admin
I have to agree with MiserableOldGit. Probably intended to do interleaving for pagination but they messed it up the first go around and never came back to it.
Admin
Now that's fuct up.
Admin
You can see the interleaving as a special case of transposition; write n entries into a 2×(n/2) in LR-TD order and then read them back in TD-LR order.
Admin
While we're poking fun at "tranposition"s and "fuction"s there is another issue to pick at. Unlike many WTFs we review, this dev doesn't have any repeated and therefore unnecessary code. Not so our friend and host @Remy whose Department of Redundancy Department is alive and well:
;)
Admin
Most people don't, but some professional casino dealers actually do perfectly interleave the cards when shuffling.