- 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
If the current tally is -0 and you add +0 what is the result?
I guess it is frist!
Admin
It looks to me like the values are Left, Right, Both, and Neither, and this code is just counting whatever the things are. So if it's Neither, skip as there's nothing to add. Otherwise add the number of things to the tally - Left and Right are one thing, Both is two things, N is zero things, and if it's anything else that counts as zero as well. Apart from the redundancy in the code, that's hardly an ideal way of encoding the data - two Booleans for Left and Right would be much simpler.
Admin
I agree in principle. Unfortunately, all too often the demands on the code evolve, and not structuredly or methodically; and the code has to evolve with them. (Can you tell I've had to deal with customers who don't know what they want and once you have interviewed them enough to nail their wants to the paper, change their mind two months into development? To be effective one month ago?)
Admin
There's good Hungarian notation [citation needed], bad Hungarian notation, and bad Hungarian notation done badly. "rsRecordSet"?
Admin
Quick, delete this article! The world must not know about that crappy if-switch anti-pattern.
Otherwise the re-incarnation of Edgar Dijkstra will write an article titled "SWITCH STATEMENT CONSIDERED HARMFUL" and most languages will remove support for switch statements just like they remove support for goto.
Admin
One could argue that it's intended to make the code self documenting by including case elements for all possible values, with the "case else" there as a belt-and-suspenders defense against unknown values. That may be giving it unwarranted credit though since there are much better ways to document than using that "+0" nonsense. I have to wonder if any of that is optimized-out by the compiler?
Admin
Just one thought in the initial 'N' check: This is something that can improve code speed if you have a time-consuming test that doesn't apply most of the time. If 100,000 records are N, and only 1,000 have something to consider, then that initial check speeds up most operations. Now, the switch should be good enough in this particular case, but the principle is good. It has more than doubled speed of processing for me in the past. As for the other aspects, WTF?
Admin
"rsRecordSet"? IMHO, it could have been worse, they could have named it "rsTheRecordSet"
Admin
As this is VB6, I doubt the compiler was terribly smart about optimizations at all.
Admin
If this article is not a WTF, but still it's a WTF, then don't not ignore it.
Admin
Leaving aside FP, the only two languages I can think of that do not support goto are Java and Python. (Weirdly, PHP introduced goto in v5.3 or thereabouts.)
Not many languages outside C support longjmp (a goto that ends up outside the current stack frame), but that's probably all to the good. It's just a poor man's version of exceptions.
In fact, you could reasonably emulate goto in Java and Python (and presumably others, again leaving FP to one side) via exceptions....
Not that I'd recommend it in this case.
Admin
Yazeran
Admin
Also Modula-2.
Admin
"rsRecordSetD1T3" might be in the running for the worst identifier I've ever seen.
It's not just the Hungarian notation - it's the redundant expansion of the Hungarian notation that makes the Hungarian notation even MORE unnecessary.
And then the icing on the gilded lily: the only non-boilerplate part of the identifier, D1T3, is utterly cryptic.
Admin
We'll just need to read up on the mandatory company naming guidelines, I guess. Database 1 Table 3. It's so easy and well structured!
Admin
It's been a while so I could be wrong but I don't recall a GOTO in LISP, Scheme, PROLOG , ML or Haskell. Many of the languages that do still have it have limited it's usefulness
Admin
Oh, I've seen a worse one. A function called 'IsTicketnnnnn' (where nnnnn was the ticket number this function was written to support). I complained at code review that this was an entirely unhelpful function name, as it didn't describe what it was doing and none of the parameters was actually a ticket, but I was overridden because they couldn't think of a better one and the project was due for release.
Admin
It's not cryptic at all, the function records whether a relay block is set or not and that's located next to diode 1, transistor 3 on the Rev.19 PCB. Perfectly simple and logical really.
Admin
I don't find the +0 to be bad. It makes it very clear that you do nothing, I would expect the compiler to remove it. In a situation like this I would prefer the N branch have the +0, the only real WTF I see is testing for the N case rather than simply using the case to make it a nop.
Admin
Improved by GPT3 with "improve this" being the only prompt:
If rsRecordSetD1T3("ItemState") <> "N" then tally = 0
End If
Admin
There's no break in the case statements, so out of this routine you'll get either 2 or 3, not the 1 or 2 tha you would at a glance expect.
Admin
Since this is VB6 there aren't break statements. Cases don't fall through like C.
Admin
In the "happily ever after" portion of this, using the whole awful mess with loops and scattered comparisons of all kinds (including some dead code) I managed to get the whole thing as a single SQL statement. Well, a single SQL operation that was about 180 lines long.
Also, SteelCamel2 is correct: Left, Right, Both and Neither stored as a code in the database. There was one additional WTF in the data. There was "markup" field in the database that had both a $ markup and a % markup. Yeah, both in the same field. It was % if below 2 and $ otherwise. So much fun.
Admin
I reckon writing software is 1/3 working out how to solve the problem; 1/3 banging at the keyboard; and 1/3 trying to come up with decent names for things.