- 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
I don't get this query:
SELECT TOP (1) n = (ROW_NUMBER() OVER (ORDER BY number))-1 FROM [master]..spt_values ORDER BY n
Looks like
spt_values
comes from Sybase and SQL Server, but is this always guaranteed to return 0?Admin
I didn't understand much of it either... and I've been writing queries for Discourse (well our instance of it anyway):
https://meta.discourse.org/t/badges-request-for-reason-field-on-manual-badge-assignment/17625/7?u=pjh
Admin
Because for number starts at 1 and the query subtracts one form the route number....... That's always going to be zero.
Admin
haha Perl, remember when i had to port a perl script once... True headache lol
[image]Admin
Yes
As intended :)
You got it :)
Admin
Ah - think I've got it...
ROW_NUMBER()
starts at oneROW_NUMBER() OVER (ORDER BY number)
and increments one by eachnumber
that appears(ROW_NUMBER() OVER (ORDER BY number))-1
makes it zero-based instead of one-basedn = (ROW_NUMBER() OVER (ORDER BY number))-1
allows this incrementing 0-based number to become the first column of each row alised asn
TOP (1) n = (ROW_NUMBER() OVER (ORDER BY number))-1
but only the first row is selectedso..
while (my @row = $sth->fetchrow_array) {
will only ever iterate once, with the first (and only) row and$OurZero= $row[0];
selects the first column out of the one row returned, which pointed out above is the 1-based row number minus onewhich can only ever return 0.
Yuck.
Admin
A+! I believe the ROW_NUMBER OVER weirdness is because of MSSQL special syntax. [master]..spt_values is meta table which is useful for generating a list of numbers, and also has some actual meaning nobody uses it for.
Admin
Postgres has it as well (if you can spot it here that is...)
Our
5% Poster
badge:Whether this, of itself, is FP worthy, I'm not too sure...
Admin
I once had to maintain 5KLOC of perl (a telephone billing app).
When I got it, there was one comment in the codebase:
Of course, it didn't say f***up, but I'm following the community guidelines.
Admin
Ah. It's a speed-up loop. Perhaps said perl-slinging chimps were not entirely stupid but in fact rather cunning, after all?
Admin
I think it's a bit unfair to blame this on perl. TRWTF would have been exactly the same no matter what language the mentally challenged chimpanzees wrapped around that query.
Admin
I'm not sure how to interpret this. Did the coworker popped David's head into David's cube (popped as in placed? as in punched? as in popping a balloon? as in popping the stack?), or does their payroll system have three genders: Female, Male and FILE_NOT_FOUND?
Admin
Tumblr.
Admin
Which community's guidelines?
Admin
That's not even valid MySQL syntax! Never name your variables my-anything in any real code!
Where did this $sql variable come from? It was $mysql a moment ago.
Same... ($sth?)
Though this $OurZero smells like a global variable, which could be modified somewhere else and then
Would no longer be a no-op.
Also,
Seems like a WTF. Wouldn't you at least skim the sub before doing the hardcore optimisation?
Filed Under: Needs more regexp.
Admin
I was going to say maybe the original Jeff FAQ, but
/faq
now redirects to our early attempt at a custom FAQ, so I'm not even sure how someone would find that mealy-mouthed treatise on bland, "civilized" behavior.Admin
I've had some apparently androgynous coworkers before.
Admin
That thing is worse than failure. As it's an article with perl, would have been better to bowdlerize with some line noise:
Admin
It's at http://what.thedailywtf.com/t/faq-guidelines/1897 but since that's a direct link to it in
Staff
not many of you can see it.But it's the stock offering that could be found (mutatis mutandis) at https://meta.discourse.org/faq - it certainly hasn't got an edit history.
Admin
Wait, we have community guidelines? I thought we just had Bert Glanstron to enforce proper decorum.
Admin
Here:
Filed under: [I HATE MARKDOWN](#tag)
Admin
Admin
Relevant entry from my quote file:
Admin
Should I feel terrible that I did not see the multiplication of zero until after performing the addition? My LR>PEMDAS parser didn't even mention there was a multiplication at all until the sixth operation!...
Admin
Reminds me of the question my Maths teacher asked after we'd learned binomial expansions:
Expand (x-a)(x-b)(x-c)...(x-z)
[spoiler] It's 0 because there's an implied (x-x) in there [/spoiler]
Admin
It's the same association that goes along with VB (pre-.NET). VB itself isn't completely horrible, but most of the people that use it usually are.
Admin
That was the Car Talk puzzler a few weeks ago. Well, at least something similar:
(x+a)(x-b)(x+c)...(x-z)
Admin
The trouble with a CodeSOD is that often, there's not enough code submitted to explain the headaches the narrative that came with the code was trying to get across. The OP implied that unreadable perl led to many unspoken wonders of WTFness that I kinda wish s/he'd submitted as well. Alas, I only had the one example, and it was only half complete, so I had to translate some text into code to make it understandable :)
Admin
I do feel bad for the authors when it's a CodeSOD, and the code submitted isn't something that you can just immediately post.
Admin
After this morning, I'd like to go on record and say that I like Perl more than Linq.
Admin
Both have the property of being amazing when they work…
Admin
Yes, it's pretty amazing when either work.
Admin
Better ending:
Just as he checked his revision into the repository, a coworker popped his head into David's cube. "It's your kids, David! Something's gotta be done about your kids!"
Admin
Perl is wonderful. Most people cannot use it properly. It isn't a language you point an idiot or a code neophyte at, that's for sure.
I worked for a company that dismissed Perl because some dufus needed to parse the Unix account info (ypcat) on a system with thousands of user id's. IIRC, he ran the ypcat thousands of times, when running it once, and then putting results in a hash would have done nicely. And been very fast.
You cannot blame the tool when the people slinging the code are completely clueless. But this single "experiment" doomed Perl in the department I worked in a VERY large company. But they trusted the opinion of this programmer doing his very first Perl project. Unfortunately.
I have been slinging Perl since it came out (1992?). It really is powerful, and not nearly as bad as its reputation with the general public. It can be very readable, and very maintainable.
Don't toss the baby out with the bathwater.
Admin
But blaming it on perl is the hipster thing to do.
Admin
When I see someone saying that perl is unreadable, I hear "I CAN'T UNDERSTAND REGULAR EXPRESSIONS".
Admin
Huh? LINQ is as straightforward as it gets, especially when you're using it with extension methods. Now, things like LINQ to Entities can and will fail spectacularly if you don't know what you're doing (and because Entity is a bit of a clusterfuck in general), but it's like blaming SQL for the shittiness of Oracle databases.
I CAN'T UNDERSTAND REGULAR EXPRESSIONS. Seriously, whoever thought that syntax up should be shot with extreme prejudice. It kinda works for simple matches, but then you try something even a bit more complex and inevitably end up with what looks like the results of banging your head on your keyboard for a prolonged period of time.
Admin
Facebook is FULL of people who do that, or something similar, only with simpler problems like "solve 0 * 7 + 7 - 7"
Admin
I do agree that at its most basic, it's very easy to understand.
In the wild, real world, it can spawn its own WTFs.
Admin
They'll get that one correct. It's "7 + 7 * 0 + 7" they'll mess up. (I ignore those now - they're boringly the same.)
Admin
Without the parens your example misses the shortcut that you were replying to. Remember your order of operations (yes it still evaluates to 0 but the point was the shortcut around what is multiplied by 0).
Admin
Well, that's true for every tech.
And I still think that even the worst LINQ atrocities are more readable than average Perl code. But that's just, like, my opinion, man.
Admin
It was more an issue about behavior than readability.
Admin
The shortcut was just a particular form. I meant in more general terms. I mean, people will actually get wrong the thing I posted, in the form I posted it. "It's, uh, 23, right?" "No, it's -7!" And then they argue with the person who tells them what the right answer is because they simply don't understand precedence, and evaluate the entire thing left-to-right.
Admin
But you can evaluate it left-to-right and arrive at the correct answer, since the multiplication is first? Or am I lacking caffeine again?
If you really want to throw a bait, try something among the lines of 6 / 2(1 + 2). Hilarity ensues every time.
Admin
Look, I didn't even bother to work out the answer, I just made up something that looked sort of what I was after, because the actual answer wasn't important.
Admin
We really need a better syntax for that kind of shit.
Admin
We should've moved to RPN a long time ago, I say.
Admin
The RealWTF for me is when he doesn't delete the call to CalculateZero entirely.
Admin
Guess what it was using... :headdesk: