- 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
The Frist ... The Last ...
https://www.youtube.com/watch?v=Fcd3XuQwDQQ
Admin
I sort of understand:
It's a stub for functionality that never got implemented...probably in context editionModel is not well formed/implemented yet either.
Admin
Of course, countDocuments() does just that. It counts the documents. One by one, just like if you were counting documents.
'Course, I don't actually see any point in doing that to find out how many documents there are.
Unless it's a bit like the conditional branch instructions on the 6809. It had the usual combinations of assorted CPU flags set or clear (Zero set/clear, Carry set/clear, Sign set/clear, Overflow set/clear, etc.), but it also had two more branch instructions: BRA (no sniggers in the back of the class) and BRN, respectively BRanch Always and BRanch Never. Looking at the opcode byte values showed that branch-if-set and branch-if-clear for some condition differed by one bit (the same bit for all pairs), as did BRA and BRN. In effect, the 6809 had no unconditional branch instruction at all. All the pairs were "branch if some condition is true" and "branch if that condition is false". For the eighth pair of branch instructions (BRA and BRN), the condition was just "true".
Maybe this is just one of a series of conditional document counters, and in this one the condition is "true", and whoever wrote it was too afraid of the fucknuttery of a PHB to do it right. Or maybe it was built by the PHB itself.
Admin
WTFTFY
Admin
Admin
i have no idea. but my WTF version will happily report 0 documents when the user is null (or documents is)
in fact it will report whatever number it's happened to count up to ANY TIME an exception is thrown in the loop.
:laughing:
like i said i WTFified that for us.
Admin
Might not be a bad idea for the Classic WTF articles to link to the old comments instead. :laughing:
Admin
Timo's version (the getEditionModel() one) is completely valid if it's an override of a virtual method, on a subclass where the operation in question doesn't make sense.
Otherwise, it's definitely a WTF.
Admin
I like that. 0 is an assumption. Maybe the correct number is a fraction, or ... why not make the assumption NaN or a Schrödinger Kat. It's imaginary is nothing, is everyting, is fantastic until we actually count them, one by one!
Admin
That's precisely the problem. How do you count something one-by-one if you don't know if it uses a particular zero-indexed scheme? Certain languages allow you to arbitrarily use integers and keys under the same syntax. For example:
user.documents["First"]
could very well be the same as:user.documents[0]
And we're not even going to start talking about pointer math! :stuck_out_tongue_winking_eye: ;PAdmin
this is indeed true, however the attribute
index
ondocuments
does hint at a traditional array layout, does it not? :-)Admin
In C#, does that not just link to the
.Item()
method, where the.Item(string)
overload goes by field name, and the.Item(int)
overload goes by index?Admin
Sounds about right. I know PHP does it, but I'm not as sure about Javascript and whatnot. 'Tis why I made no specific reference.
Admin
Admin
Yeah, the if (true) is a bit silly. The return, if I had to guess, is probably there to silence a compiler that doesn't know enough about flow analysis to realize that this is not a "missing return value" problem.
...maybe.
Admin
I think the
if (true)
is there for the same reason. Maybe it was something like this:and then when that didn't compile
but wait - we aren't ready to expose that functionality yet
oops, that doesn't compile either!
perfect
Admin
For extra fun, trim a space or two from the timestamp length and see what happens. Particularly if you have source control that ignores whitespace changes.
Admin
Admin
Really? Also no SidebarWTF.
Admin
I think in many cases this kind of coding can be summarized by the old adage "When all you have is a hammer, every problem looks like a nail".