- 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
Deep VB? More like Deep Blockly or Deep RPA, because the same kind of code is all over there too.
Admin
Deep VB? More like Deep Hurting.
But what I really want to know is if someone got Mexico to pay for this wall.
Admin
Even from one application over, Resharper is screaming: "Invert if to reduce nesting"
Admin
It's the End If of the world as we know it.
Admin
Certainly the code could be rewritten to be more performant. Although current VB.NET compilers are pretty good at hoisting subexpressions.
The real fun here is what sort of convoluted business process generated a requirement like this. Stupid business logic will (almost) always produce stupid code.
We all know we're looking at an anonymized excerpt of the true code; much more is missing than is shown.
But as shown, the output of the loop is that LastReading will be set to the value of the Present field (or to zero) of the last wall-of-if's qualifying record in the retrieved record set. One wonders what value LastReading is initialized to above the loop. It's a good bet one could get a nice speed-up by iterating the record set in reverse order & quitting on the first wall-of-ifs match.
Look at the bright side: At least some young dev hadn't written the same thing in LINQ. Sometimes "query comprehension" is really "query incomprehensible".
Admin
Can't be sure, but it looks like a load of business rules/business logic is hardcoded into that chunk of code. Other than that, it's kinda beautiful.
Admin
So TRWFT is that they didn't use Continue For ? :)
Admin
It would be even better if there were Else somewhere in 8th level of nesting.
Admin
I'm particularly fond of:
reminds me of the student who kept writing:
A = A
to make sure the assignment took.
Admin
Now that would be a real WTF. Making every single condition harder to read (because it's inverted) just so coding style allows you to avoid indenting.
Next week, we'll learn about the magic of the "and" operator.
Admin
That's because when they print A it doesn't have the value they expect, which obviously means that they did properly set the correct value but it didn't stick. So better set it some more. That is real student thinking, I've seen it too.
Admin
The 'and' operator can't salvage this either. There is nothing that can make this readable and maintainable because the fundamental logic of the business rule is complete garbage.
Admin
Years since I've seen a GOTO statement.
Admin
It would remove most of the indentation, which was the point of the comment I was replying to. No-one said anything about making it maintainable.
Admin
Hey! That code looks like my worst Oracle query execution plan ever.
Admin
"Come From," surely?
I've always wanted to use a language with Come From. Preferably one that adds pattern matching to the thing.
Admin
IIRC, classic VB doesn't support boolean short circuiting, so use and would mean that every condition was checked EVERY time. Except some sort of null reference exception would occur fairly quickly.
basically, you can't use something like
if (value <> null) and (value.field = "XXX")
, as value.field would always be referenced.Admin
VB.Net has
AndAlso
andOrElse
for these situations. It's generally recommended to use them instead ofAnd
andOr
unless you specifically don't want short circuitingAdmin
This is VB.Net. It uses features of the For construct that were introduced in version 1.1 of .Net. That means they have AndAlso.
Admin
It would not be such a problem if the indentation level would only be just 2 spaces instead of 4 (apart from the incorrectly indented first shown line, which I assume is indented 3 spaces), wouldn't it? More payload visible on the screen to bedazzle us!
Admin
"I don’t know what this code does"
Well, it changes the value of LastMonth and LastReading. Or not. Whatever...
Admin
With a classical c or Pascal eye, you would have to declare tempLocation a lot earlier. And here, I would do the same thing anyway so you only need the assignment thirty doors down.
Yes, you run the 'risk' of declaring it unnecessarily (but just the once), but you could also end up with the declaration statement being executed (putting some strain on memory management) a possibly infinite number (well, actually R, to be exact) of times.
Admin
How is this unreadable? The logic is pretty straightforward to read:
Admin
Hmm, length limit. continued:
The requirements probably evolved like this: