Comment On Visual Basic Triple Play

Instead of reinventing the wheel, the company Ramirez works for decided to use a framework to build their Web Framework. Unfortunately, they may have made a poor choice. When they found out it does "crazy things" like saving reports as PDFs (which are stored locally) and then routing them through an IIS web service, they decided to take a closer look at the code. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Visual Basic Triple Play

2007-03-02 09:03 • by tharfagreinir
I see dead people.

Brain-dead, that is.

Re: Visual Basic Triple Play

2007-03-02 09:06 • by Matt (unregistered)
From a n00bs perspective, if something is indented that far, you must be doing something wrong.

CAPTCHA: "Ewww" Damn Straight :P

Re: Visual Basic Triple Play

2007-03-02 09:09 • by DOA (unregistered)
"Else Continue For"

When the end of the loop just isn't fast enough

Re: Visual Basic Triple Play

2007-03-02 09:14 • by vt_mruhlin

If n = 0 Then
n = n + 1

n = n + 1 + 27 - 27 + (384 * 0)
Useless arithmetic is fun!

Re: Visual Basic Triple Play

2007-03-02 09:15 • by dave (unregistered)
If only VB had a way to break out of a for loop without a goto...

Oh wait, it does.

Re: Visual Basic Triple Play

2007-03-02 09:16 • by jack (unregistered)
wow.

captcha: burned - i'm a witch?

Re: Visual Basic Triple Play

2007-03-02 09:21 • by zack (unregistered)
ze goggles, zey do notting!

Re: Visual Basic Triple Play

2007-03-02 09:25 • by Mark (unregistered)
Ow! My EYES!!

When mom said I'd go blind, she didn't say it would be from looking at too many WTFs!

Re: Visual Basic Triple Play

2007-03-02 09:26 • by Will (unregistered)
Question for someone who knows VB:

If n = 0


Is this use of the = operator an assignment in VB, as it would be in C? If so, what is the truth value of an assignment in VB?

Re: Visual Basic Triple Play

2007-03-02 09:26 • by WIldpeaks
I see a gun to shoot yourself in the foot.. ^_^

Re: Visual Basic Triple Play

2007-03-02 09:27 • by burnmp3s
124216 in reply to 124209
dave:
If only VB had a way to break out of a for loop without a goto...

Oh wait, it does.


Yeah, that would be "Exit For". The funny thing is, before VB.NET 2005 (which this code obviously uses), there was no "Continue For".

I've seen VB code where they use gotos instead of loops. Throw in a bunch of global variables and you have some fun code to maintain.

Re: Visual Basic Triple Play

2007-03-02 09:30 • by haldiggs
Assuming that n (possibly an error counter?) starts out as 0, then the first time it's incremented would be the last, as it then GoTo CloseCmd: which then kills the whole thing. However, maybe n is already > 0, in which case, for some unknown reason, it's ok to just keep running the loop?? I don't get it. I wish there was more to look at but then again I have finished my coffee,

- Hal Diggs

Re: Visual Basic Triple Play

2007-03-02 09:31 • by cruise (unregistered)
No one else think that basing the entire logic around a specfic exception is pretty barmy? Or is that sort of thing so common in a wtf that we don't blink anymore? :P

Re: Visual Basic Triple Play

2007-03-02 09:31 • by rStacey (unregistered)
124220 in reply to 124214
Will:
Question for someone who knows VB:

If n = 0


Is this use of the = operator an assignment in VB, as it would be in C? If so, what is the truth value of an assignment in VB?


No, the = operator is overloaded for comparision and assignment depending on context.

Re: Visual Basic Triple Play

2007-03-02 09:32 • by forgeten (unregistered)
124223 in reply to 124214
if a = b 'conditional

a = b 'assignment


vb as lot of these weird quirks

Re: Visual Basic Triple Play

2007-03-02 09:33 • by dyslexia (unregistered)
124224 in reply to 124214
Will: (re: 'If n = 0' ...)

This is not an assignment. In VB (and VB.NET, which is what this WTF is written in), = is either assignment or equality depending on the context.

If Foo = 1 Then ' <-- Equality
Foo = 2 ' <-- Assignment
End If

Perhaps not the best idea, but historically it's been that way, and they kept it in the move to .NET.

Re: Visual Basic Triple Play

2007-03-02 09:34 • by KattMan
124226 in reply to 124214
Will:
Question for someone who knows VB:

If n = 0


Is this use of the = operator an assignment in VB, as it would be in C? If so, what is the truth value of an assignment in VB?


In this context the = is a comparison operator. Basically the first = you find is a assignment all others are comparisons, but this happens only within their own context.

If x = y and a = b

The context for each is separate so they are both comparison operators, the IF precedes the first operation.

It is overloaded as a comparison and an assignment and can lead to some really strange code. i.e.

dim x as boolean = false
dim y as int = 1
dim z as int = 2

x = y = z
x = (y = z)

Just try to grok that and tell me what the value of x is in each case.

Re: Visual Basic Triple Play

2007-03-02 09:35 • by VB (unregistered)
Reason 1 : If ex.Message = "Invalid column name 'Result'." Then

Reason 2 : GoTo CloseCmd

Reason 3 : Continue For

Reason 4 : it's VB

Re: Visual Basic Triple Play

2007-03-02 09:37 • by Volmarias
124228 in reply to 124223
forgeten:
if a = b 'conditional

a = b 'assignment


vb as lot of these weird quirks


s/wierd quirks/reasons to rue ever working with it/

Re: Visual Basic Triple Play

2007-03-02 09:39 • by jon (unregistered)
haha, that's really bad :D

1. It doesn't do anything with DbReader2
2. Column name 'Result'
3. The n = n + 1
4. Breaking out of For
5. I'ts VB


not as bad as the name change but hey

Re: Visual Basic Triple Play

2007-03-02 09:40 • by jon (unregistered)
I mean the way that they're breaking out ofc, not just "oh god, they're breaking a for :o!!"


...editing?

Re: Visual Basic Triple Play

2007-03-02 09:45 • by KattMan
124234 in reply to 124228
Boy, talk about hard to explain VB quirks.

I totally messed up the If statement in my explanation.
The correct part, The first operation is always an assignment all others are comparisons.

If x = y and a = b

The If statement is the first operation that wraps the other two giving the rvalue an assignment of either true or false. This makes the other two fall into the second category of comparison operators.

In my examples:
x = y = z
x = (y = z)

x is false in both cases as the first equals is the assignment and the second is always a comparison regardless of the parentheses.

Re: Visual Basic Triple Play

2007-03-02 09:55 • by gruckiii (unregistered)
looks like Marvin the Martians de-atomizer to me.

Re: Visual Basic Triple Play

2007-03-02 09:59 • by Licky Lindsay
Someone enlighten this old-schooler.

Are you seriously telling me that GOTO has not been removed from the BASIC language in the last 20 years?

Can you also still PEEK and POKE?

Re: Visual Basic Triple Play

2007-03-02 10:00 • by Niall (unregistered)
dbreader2 is never used.

from memory n is only in scope in the exception clause so n=1 would have done just fine. Nothing is done with n either.

compare with message rather than error code - an interesting approach m'lud.

Even if it had worked iterating through a collection of database statements and 'randomly' throwing some away. I can only guess at the logic "If no customers found don't show their details, now query db for orders belong to the customers I didn't find earlier, now compute average delivery time by parcel wait for the orders i didn't find for the customers who didn't exist'.

Niall

Re: Visual Basic Triple Play

2007-03-02 10:01 • by Niall (unregistered)
124241 in reply to 124240
s/wait/weight/

though it makes as much sense.

Re: Visual Basic Triple Play

2007-03-02 10:03 • by Will (unregistered)
Thanks, everyone, for clearing up the comparison/assignment thing and for confirming that my decision not to use VB for anything ever was a good one.

Re: Visual Basic Triple Play

2007-03-02 10:03 • by Dave C. (unregistered)
124243 in reply to 124220
rStacey:
No, the = operator is overloaded for comparision and assignment depending on context.

A huge WTF right there.

Re: Visual Basic Triple Play

2007-03-02 10:09 • by lizardfoot
Everytime you use a GoTo, God kills a puppy.

Re: Visual Basic Triple Play

2007-03-02 10:12 • by Dave C. (unregistered)
124246 in reply to 124219
cruise:
No one else think that basing the entire logic around a specfic exception is pretty barmy?


No, that stood out more than the rest of it for me. Bonus: The logic isn't based on an error code, but on the text. Oh, I'm sure that won't change when you upgrade MDAC, connect to a different server, etc.

Re: Visual Basic Triple Play

2007-03-02 10:13 • by rdrunner
124247 in reply to 124240
Niall:
dbreader2 is never used.

from memory n is only in scope in the exception clause so n=1 would have done just fine. Nothing is done with n either.

compare with message rather than error code - an interesting approach m'lud.

Even if it had worked iterating through a collection of database statements and 'randomly' throwing some away. I can only guess at the logic "If no customers found don't show their details, now query db for orders belong to the customers I didn't find earlier, now compute average delivery time by parcel wait for the orders i didn't find for the customers who didn't exist'.

Niall


Well... Since it is a code snipped, you cannot tell whats (realy) happening to the reader. Also n is not defined in the context of that snipped, so it means its scope must be bigger then that what was posted here.

Another point is that not the statements are thrown away... Its only the results that noone cares about.

Besides that, the code is still stupid ;)

Re: Visual Basic Triple Play

2007-03-02 10:16 • by Nat5an
124248 in reply to 124243
Dave C.:
rStacey:
No, the = operator is overloaded for comparision and assignment depending on context.

A huge WTF right there.


Meh, SQL does the same thing, as do other languages, I'm sure. It's not that big of a WTF. Just because it's not like C or Java doesn't make it completely crazy.

Re: Visual Basic Triple Play

2007-03-02 10:18 • by Aaron (unregistered)
Just three reasons, you say?

1. Mystery meat variables - "DbReader2" and "n";
2. Eating the global Exception without any logging;
3. Comparing the text of an exception message within a catch block;
4. Comparing the text to a hard-coded string;
5. Using an exception to detect a condition that could easily have been detected some other way (syscolumns, information_schema);
6. Using "n = n + 1" when "n" is already known to be zero. In fact, "n" can never be anything other than 0 or 1, at least not in the code shown, so a boolean value should have been used instead.
7. Use of "goto";
8. Use of "goto" within an exception handler...!
9. Use of "continue" when there is nothing to bypass.
10. Overwriting the DB reader on each iteration without actually reading anything (just use ExecuteNonReader()).

Maybe there's more... it really is like a Rorschach test - the more you look, the more errors start to appear.

Re: Visual Basic Triple Play

2007-03-02 10:22 • by Jojosh_the_Pi
vb is shit why does it still exist *carves out eyes with rusty spoon*


Right, like this code is awful because it's VB, not because the coder didn't know what he was doing. You could do the same thing in, say, C#.

I'm not quite sure what the big deal is about overloading = is. Sure, I prefer the C-like == vs =, but it's not like the statement If a = b Then a = 2 is going to confuse a whole lot of people.

Re: Visual Basic Triple Play

2007-03-02 10:22 • by RobertB
124253 in reply to 124242
Will:
Thanks, everyone, for clearing up the comparison/assignment thing and for confirming that my decision not to use VB for anything ever was a good one.

Why all the VB hate? A poster in a previous discussion summed it up nicely: "A poor workman blames his tools".

If there's one thing I've learned from this site, it's this: There hasn't been a language developed in which bad code can not be written.

In fact -- and this ought to give you C elitists indigestion -- I'm currently converting several C-language programs TO Visual Basic. Why? Because they are unmaintainable garbage with constructions that would make Kernighan and Ritchie turn to GOTO for better clarity.

You use the tool that works best for the job.

(Proud VB coder since 1992. TRS-80 BASIC before that.)

Re: Visual Basic Triple Play

2007-03-02 10:22 • by Scott (unregistered)
124254 in reply to 124239
Licky Lindsay:
Someone enlighten this old-schooler.

Are you seriously telling me that GOTO has not been removed from the BASIC language in the last 20 years?

Can you also still PEEK and POKE?


GOTO is also still in all descendants of C, including C#.

PEEK and POKE are gone though....

Re: Visual Basic Triple Play

2007-03-02 10:23 • by JTK (unregistered)
124255 in reply to 124246
Dave C.:
cruise:
No one else think that basing the entire logic around a specfic exception is pretty barmy?


No, that stood out more than the rest of it for me. Bonus: The logic isn't based on an error code, but on the text. Oh, I'm sure that won't change when you upgrade MDAC, connect to a different server, etc.


Yeah -- I was so stunned by the attempt to actually do something useful with an exception thrown by the database that I missed the whole goto/continue wierdness. I mean, if your database code is so whacked that you consider exceptions as non-catastrophic and part of your typical process flow, then that's truly Worse Than Failure...

Re: Visual Basic Triple Play

2007-03-02 10:26 • by forgeten (unregistered)
124256 in reply to 124228
heh , true especially if you try to use vb and another language. no good comes from that

Re: Visual Basic Triple Play

2007-03-02 10:29 • by Jeff S
Enough with the VB bashing, kids, lets try something a little more original. And remember: if you truly, honestly feel that if you are forced to use VB that you will be forced to write bad code, then that pretty much says it all about your programming skills.

It's the programmer, not the language, let's all try to focus on what the programmer did, stop blaming the tools and making excuses, and move on.

I am issuing a challenge to all subsequent posters to actually be relevant, intelligent, creative and original. Let's see how that works out. (Based on this forum's history, I suspect not so good, but maybe I'll be surprised ....)

Re: Visual Basic Triple Play

2007-03-02 10:29 • by dyslexia (unregistered)
124258 in reply to 124253
RobertB: I'm with you. People on this site love to think they're witty when they pull out the old "the real WTF was using VB!" chestnut. Frankly, it's an old, tired joke that says more about the (often ill-conceived) preconceptions of the person who posts it than the inherent goodness or badness of the language.

The fact is, this code could exist easily in C++, C#, or Java, just to name a few -- there is nothing about it that is specific to VB.

VB is simply a tool, and people do terrible things with all sorts of tools all the time. When that happens, it's not the tool's fault, especially not in this case -- everything that's wrong with this relies on language features available in most modern languages.

Re: Visual Basic Triple Play

2007-03-02 10:30 • by Will (unregistered)
124259 in reply to 124253
RobertB:

Why all the VB hate? A poster in a previous discussion summed it up nicely: "A poor workman blames his tools".


Well, I've never used VB, so I can't say that I hate it. I can say that what I've seen of it makes me not want to start using it.

Re: Visual Basic Triple Play

2007-03-02 10:30 • by SilentTim (unregistered)
hmmm... is the guy using Option Strict On? I'm guessing not.

Re: Visual Basic Triple Play

2007-03-02 10:32 • by strickdd (unregistered)
124261 in reply to 124206
I don't know if you realized, the "Continue For" was in the catch block. If you didn't include it, then the loop would automatically exit.

Still, not the best programming...

Re: Visual Basic Triple Play

2007-03-02 10:34 • by Marcin (unregistered)
124262 in reply to 124248
Nat5an:
Dave C.:
rStacey:
No, the = operator is overloaded for comparision and assignment depending on context.

A huge WTF right there.


Meh, SQL does the same thing, as do other languages, I'm sure. It's not that big of a WTF. Just because it's not like C or Java doesn't make it completely crazy.

Defend this statement. Please show me a valid sql query which has assignment.

Re: Visual Basic Triple Play

2007-03-02 10:38 • by GeneWitch
124265 in reply to 124214
Will:
Question for someone who knows VB:

If n = 0


Is this use of the = operator an assignment in VB, as it would be in C? If so, what is the truth value of an assignment in VB?

VB pretends (and usually is) smart enough that you never see "=="... at least if my memory serves

dim j as string = "wtf"
dim k as string = "omg"
if (j = k) then
writeline("equal")
else
writeline("not equal"
end if

is the same as
If (j.equals(k)) then 'etc
...

:-D

Re: Visual Basic Triple Play

2007-03-02 10:39 • by Martin (unregistered)
I'd love to see the first time thezy deploy this program in a language other than English and the text of the error message changes. And, having been a support tech myself, I pity the support people who try to reproduce the problem on their machines with an English locale...

Re: Visual Basic Triple Play

2007-03-02 10:41 • by w'ever (unregistered)
no-one seems too bothered that none of the database connections are not getting closed explicity.

Re: Visual Basic Triple Play

2007-03-02 10:41 • by cowbert (unregistered)
124268 in reply to 124255
JTK:

Yeah -- I was so stunned by the attempt to actually do something useful with an exception thrown by the database that I missed the whole goto/continue wierdness. I mean, if your database code is so whacked that you consider exceptions as non-catastrophic and part of your typical process flow, then that's truly Worse Than Failure...


Uhm, there is no real(tm) exception handling in VB. So using goto to write an exception handler is perfectly fine. Of course, in that case you're supposed to use goto in the context of OnError Goto, so it really doesn't excuse this particular wtf, but as a BASIC practice (harhar) it is a favorable pattern (it's obviously worse to stick your error handler smack in the middle of the loop or if block).

Re: Visual Basic Triple Play

2007-03-02 10:41 • by Jeff S
VB BASHING RULES

If you'd like to be "witty" and "original" and "clever" and bash VB in a response, you MUST first answer this question before your post:

If you are forced to use VB.NET (or VB6 or VBA or even VBScript) to write a fairly complex program, would you be able to write code that not only works reliably but that is also clean, maintainable and efficient?

Answer that question first ( a simple yes or no is fine), and then bash away with your original, witty anti-VB statements.

(hint: if you say "no", then that says it all about your programming skills -- you are either a pretty horrible programmer, or you don't have sufficient knowledge of VB so you have no business criticizing it. If you say "yes", then you have no business bashing VB because you just demonstrated that it is the programmer, not the language.)

Thanks!

Re: Visual Basic Triple Play

2007-03-02 10:42 • by RobertB
124270 in reply to 124262
Marcin:
Nat5an:
Dave C.:
rStacey:
No, the = operator is overloaded for comparision and assignment depending on context.

A huge WTF right there.


Meh, SQL does the same thing, as do other languages, I'm sure. It's not that big of a WTF. Just because it's not like C or Java doesn't make it completely crazy.

Defend this statement. Please show me a valid sql query which has assignment.

Here's an example of an assignment and a comparison in a simple SQL query.
Select PseudoFieldName = 'Some value'

From TableName
Where Something = Nothing

And don't forget stored procedures:
Declare @x int, @y int

Select @x = 2, @y = 2
If @x + @y = 5
Select RetVal = 'For sufficiently large values of 2'
Else
Select RetVal = 'You took the blue pill'
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment