- 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
Goto plays two really important roles.
First, it gives you access to patterns that VB doesn't support yet. For example, Continue For wasn't available for a long time even though it can really make code cleaner. The same goes for Try-Catch blocks. Goto is the ultimate workaround for limitations in procedural programming.
Second, there are times when using goto is a lot cleaner than deeply nested if statements or constantly checking a SkipMe flag.
As VB gets more powerful I find myself using Goto a lot less. However there are still times when one well placed goto can elminate dozens of statments and conditionals.
Admin
The number of clueless coders in this thread who are confused by BASIC-style "=" handling is truly mind-boggling and disheartening.
This is what happens when you start newbie programmers out with Java. It warps their fragile little brains.
Admin
Heh the often hated but misunderstood Goto statement. Tell me what is the difference between these two flavors of VB:
VB6: On Error Goto ErrorCatch 'Do a bunch of stuff here Goto Cleanup
ErrorCatch: 'Trap your error here
Cleanup: 'do your cleanup stuff here
Vb.Net Try 'Do a bunch of stuff here
Catch 'Trap your error here
Finally 'do your cleanup stuff here
I was using the first one for years in VB6, talk about easy porting of my code over to .Net when it arrived.
Admin
insert into names (name) select 'Jo'
update names set name = 'Joe' where name = 'Jo'
Assignment and comparison, same exact symbol. I'm going to assume from you not knowing that that you've never written an update command in SQL, or you've never written a Where clause.
Admin
I vote for never written a where clause!
Delete from Table1
Admin
No, but it was something similar.
Admin
Admin
Let me take off my VB fanboy hat and grab a Bashing Bat for a moment...
Whenever we have a new programmer, chances are they will not know to go into the VB6 configuration option that automatically adds "Option Explicit" to the top of any new module. What is MS thinking by having that option default to "No, let me use random and/or misspelled variable names, thanks"? I suspect it's a sneaky plan to make sure that nobody puts together an Office Killer Application out of VB. :)
Another VB6 irritant. What should this do?
What it does is dim Baz as Integer. Foo and Bar have no particular place to go, and are defined as Variants. This actually got fixed between VB6 and .NET, though, which would be enough to make me want to upgrade.
Except for the fact that you can't have control arrays in .NET, which pretty much breaks all the code in the application. I'm sure there's some good reason for getting rid of them, but darned if I can figure it out. Ditto with the elimination of Sub Main. I'm creating any new VB6 applications with a form's Load event as the starting point, but what was wrong with Sub Main? (I suspect y'all will give me the answer soon...)
Admin
Problem is not to find what'swrong with this code, it's to find what's right... Which is absolutely nothing...
Admin
Go do a little industry research. Probably more apps used in business over the last 10 years were written in VB than any other Windows language. Some good, some crappy - but it CLEARLY proves that some folks consider it worth using, even if you're not up to the task.
Admin
As much as I agree with how bad that code is, I think that it might be nice for some perspective on all the goto comments.
Basically structured programming has come up with like 10 different ways to do what a goto used to do with one keyword.
Given they are easier to follow because they are special purpose, they are at their heart just calls to a jmp instruction.
Let us count the ways.
Goto of course is a jump. Method calls are jumps. if statements cause a jump. else statements cause a jump continue, break, exit... all jumps loop statements are just glorifed jump statements switch statements return statements try/catch/finally statements and so on and so forth.
I'm just saying that it is not fair to pick on a certain kind of statement just because it is a goto. It is fair to pick on the fact that it is used incorrectly, as in the example for the wtf. My problem is that most people don't even know when a goto is a good idea, so they complain about it at every opportunity.
For clarification a goto is a good idea if you are three or more nested levels deep and you want to terminate early. In that case, it can make the code simpler and faster.
Admin
Remember this one?:
WAIT -16368, 128
If you know what that means, I can guarantee you that you are at least 35 years old, probably at least 40. :) What's funny is, I have Googled "WAIT -16368, 128", and guess what-- it's not out there. You'd think it'd be out there on some Apple II tribute site, but no.
Admin
See http://www.users.on.net/~farnik/upload/APL2union.gif for a keyboard layout of APL2.
Most of these are special operators that don't exist in most other languages; e.g., {iota}x (where x is an integer) returns a 1D array consisting of the integers from 1 to x.
Many other symbols are more "mathematically pure" versions of operators constructed by compound symbols in other languages. e.g., "not equals" is a single character, and looks like what you write on the blackboard: an equals sign with a slash through.
The special symbols/operators, and the expression syntax results in extremely dense code. For example, I once wrote a prime number generator (up to some fixed N) in one expression. Mind you, it was horrendously inefficient, but, "cool, one line...".
If nothing else, the language is fun for mind expansion.
Admin
Dijkstra would disagree with you. He was smarter than you are.
If you're having to do the kind of backflips you discuss in your code snippet to get out of loops, there is something wrong with your code's structure. Adding these gotos isn't going to make your code any better.
Yes, languages should have a structured way to exit from deep nesting (break from named loop, as in perl, perhaps). But, as any other control structure, even structured breaks will be abused.
Admin
You dance around your own answer. Backwards compatibility. your vb 1.0 does not have to re-written to plug into vb6
your vb 6.0 needs to be re-written (except for the most trivial of functions) to work in .NET which is based on OO classes and not modules.
Admin
Well, I don't know. "x = 1" always meant assignment in basic algebra to me. Equality (or more specifically equivalence) was expressed, in my day, by an APL-like character with three bars rather than two.
Which isn't really the point. I hate all this crap in Perl and various other languages that means that you have to consider the context in order to determine the meaning of a terminal/operator/whatever. (Although at least Perl makes some attempt to disambiguate via line-noise.)
Yes, compilers are just dandy at understanding context. Human beings, on the other hand, are less than perfect at this. Indeed, as the earliest post on this particular sub-topic pointed out, you actually have to understand the left/right associativity of the '=' operator before you can have a clue what the context is -- and who needs that misery?
This whole (silly) debate does bring up an interesting point, though. If Visual Basic, amongst other languages, is so intent on being ecologically sound with the use of horizontal lines -- I mean, there are tons of crap VB programs out there; we're bound to run out of horizontal lines eventually -- then why not extend the concept further?
I mean, we surely don't need a different symbol for subtraction and negation. (Look, it's symbolically overloaded, according to context, already!)
I vote that VB.NET (3 and counting) should define '-' for assignment, equality, negation and subtraction, and dispense with the need for '=' altogether. Judicious use of parentheses should ensure that the context remains clear to the intellectual titans who prefer to write in VB.
Actually, I don't really see why we need '+', '*' or '/' either. Certainly not for programs such as that shown in the OP.
Admin
I use C and Visual Basic. (And like you, my first language was BASIC on the CoCo2. That was in 1985. I was 8 years old. (Yes, I've been programming as long as some people have been reading.))
You're spot on - it's the programmer, not the language. I've seen things in C that would make you claw out your eyes with a rusty PIC.
(My favorites are a pair of global flags named "MISC1" and "MISC2" and a global, all-purpose, pointer called ptr.)
Admin
Ok, I'll bite. WHAT is a "typical" language? And what makes that language any more "typical" than C?
And how is C "assembler" like?
Admin
I learned a bit of BASIC in 1980 in college, programming on a mainframe, but don't remember what flavor it was (if I ever knew). I also did a little programming in Apple II BASIC and IBM BASIC for the Apple II (they were different) around that same time. But I remember very little of it, and am primarily trained in C++ (went back for a CS degree in 2000).
Admin
I second that. In fact I noticed that C-like languages are disturbingly ambiguous when it comes to parentheses:
So I think it's time we define some new symbols whose meaning wouldn't depend on context:
2+3
*4,How readable! I'd call this new language WTF++.
Admin
He builds better tools.
Admin
Unless, of course, you want to use the serial port. Have fun doing that with VB.NET 2003!
You can use object-oriented programming in any language you want. I use it on embedded C, for science's sake!
Admin
Here, this will help: 0x0d2C
May your signals all trap May your references be bounded All memory aligned Floats to ints rounded
Remember ...
Non-zero is true ++ adds one Arrays start with zero and, NULL is for none
For octal, use zero 0x means hex = will set == means test
use -> for a pointer a dot if its not ? : is confusing use them a lot
a.out is your program there's no U in foobar and, char (*(*x())[])() is a function returning a pointer to an array of pointers to functions returning char
Admin
Wow, another APLer in the thread. That doesn't happen very often. I like my left arrows too. x?4. APL is good for expanding the mind all right, though most code more than 5 years old is one big WTF. (For the uninitiated, another oft-used symbol is the right arrow, or branch. APL only got control structures recently.)
Pascal is the best of the conventional languages over the equality/assignment issue, imo. I'm sure we've all written if(x = 5) a lot in C family languages, and imo it's a failing of the language that it's such an easy mistake to make. At least in C# it's a compiler error because it doesn't produce a bool.
The obvious WTFs are the checking of the exception message, not using the result set anyway and the use of continue in the last line of the loop. (And a big WTF to the poster who thought that the continue was necessary!)
VB bashing is rather unnecessary in this case, the code would be just as WTFy in C#.
LOL @ "throw new GotoException()" example :)
Admin
No, it's a comparison operator in Visual Basic. Well, it's both an assignment and a comparison operator; depends on the context.
For example, "A = 0" is an assignment, whereas "If A = 0" is a comparison.
Admin
The same could be said of machine code or ASM. Just because something is possible in principle possible doesn't mean it's easy, desireable, or efficient.
Still, I have no position regarding VB. I fall into the "No, I don't know VB, ASM, or machine code". Use the right tool for the job, etc. My job doesn't involve Windows, and requires portability.
But is VB really the right tool for any job? I mean, I can understand why someone would choose C over Ruby, or ASM over C. Or even the need to use machine code over ASM. What does VB offer over C#?
Admin
I got pissed off at that too. Solution: Global module with this function (C# version):
private Control ByName(string name) { return this.Controls.Find(name, false)[0]; }
And call everything with ByName("txttracks" + i).Text etc. No, they're not real control arrays, but it was the best alternative I came up with in a hurry. Unless anyone here has better.
Admin
Why people blame VB when as far as I know there's no IOVBCC I don't know. (Not that I like it much, its default libraries are terrible before .Net, and that's where The Real WTF(tm) comes from.)
I like how you make this claim with a straight face, when the goto is right in the middle of a Try block. VB has supported threading since VB5 iirc, if not in an elegant or easy way, but .Net cleaned most of that up. But yeah, threading (or rpc) is a liiiiiittle more complex than that. Please study the topic before coming up with neato custom methods of performing thread synchronization! To keep this site in business, obviously.Admin
update thingamajig set whatsit = 'whosays' where whosit = 'me';
Given a table thingamajig with varchar columns whatsit and whosit, this is perfectly valid SQL, using the equals sign in different ways based on context. Though I love the C language for its type-specificity, have always thought K&R pulled a big WTF in using the traditional equality sign as an assignment operator. Pascal did it right [at least in this regard, using the much more intuitive := for assignment.
Admin
I don't see what is it supposed to be but surely it will be something visual and not to do with the programming content?
http://en.wikipedia.org/wiki/Rorschach_inkblot_test
Admin
Speaking of stupid VB behaviour... This is a classic one. Let's say I have a thingamob that I want to perform operations on, but only when physically connected and it's not busy. The C++ code would be something like:
if (thingamob.IsConnected() && thingamob.IsBusy() == false) { thingamob.DoSomething(); }
While as the VB code would be (might be some mistake here, used it 1998 the last time):
If thingamob.IsConnected And thingamob.IsBusy = False Then thingamob.DoSomething End If
Not that different, right? Yeah, except for the evaluation. The C++ code sees that the thingamob isn't connected, and moves on. The VB code sees that it isn't connected, but have to check if it's busy "just in case". Which leads the system to do silly things, since the IsBusy() method was written by an incompetent idiot who didn't have any safeguards at all in his code.
Yes, you can develop pretty big applications in VB. Yes, I have seen some big VB apps. No, it's not possible to maintain them. Every single one of them have been perverse lumps of code filled with lying comments, variable names that are plain wrong, horribly inefficient code...
It actually does seem like if you design a language that an idiot can use, only idiots will use it. And with that, I'll have to return to my embedded C++ code here...
Admin
tell VS to start a new project and pick "console" as the type... Module Module1 Sub Main() End Sub End Module
Admin
[quote user="foxyshadis"]VB has supported threading since VB5 iirc, if not in an elegant or easy way, but .Net cleaned most of that up. But yeah, threading (or rpc) is a liiiiiittle more complex than that. Please study the topic before coming up with neato custom methods of performing thread synchronization! [quote]
Look, dude/lady, i wasn't coming up with neato custom methods. i know how complex threading is. I was merely saying that Peeking (overall) wasn't that useful to me as a programmer. Occasionally i would peek and poke values, but it wasn't for anything spectacular... I was also about 7 years old. So... Forgive me my trespasses.
Addendum (2007-03-03 07:42): Effed the quote up, should be like: [quote user="foxyshadis"]VB has supported threading since VB5 iirc, if not in an elegant or easy way, but .Net cleaned most of that up. But yeah, threading (or rpc) is a liiiiiittle more complex than that. Please study the topic before coming up with neato custom methods of performing thread synchronization! [/quote]
Admin
Admin
Anyone else notice that if the exception message is NOT the specified text then this code will silently all ALL others exceptions of any type that are thrown? Thats pretty WTF in my book too.
Admin
Actually, i probably would be capable of using VB to do usefull stuff, but i still don't like it. Mainly because all IDE's i've used with it (pre .net) sucked bigtime, plus the whole verbosity of the language gets me pounding the keyboard more than i should in a hurry.
You won't hear me bashing the languge though, that's just distastefull.
Admin
I'll pass on the second condition, since I'm a vegetarian, and also since I don't feel particularly subject to conditions that presuppose a judgement.
On the first condition, I will simply point out a few things:
While VB may not be terribly portable, within its target platform it is probably the most straightforward WYSIWYG GUI builder. This means that as a developer one is freed to focus largely on business logic of the application, without having to futz around with the minutae of presentation implementation.
Frankly, I am a bit ill at ease defending any Microsoft product. I have a lot of reservations about the ethics of that corporation, and I deplore some of the tricks they have pulled that disempower their users. Nevertheless, I even more deplore prejudice and mindless put-downs, and a lot of the comments I see concerning VB have nothing whatsoever to do with experience in using the tool, and constitute a basically apelike repetition of the prejudices expressed by others.
Admin
The thing I hate about VB is it's syntax. the only consistent thing about the VB syntax is it's inconsistenty. For example you can declare a a variable, or you can just set it to the appropriated value (without declaring a type). Also because the lanaguage is case incensitive, AA and aa mean the same thing.
To set a variable to an object you have to use the set keyword, but to set it to a built-in type don't have to use it.
The following lines all do the same thing.
Another thing I hate is not that it's not portable, the client system must have a dll(s), so it's not even portable to across windows platforms.
I could go on for hours.
Admin
If you're wondering how far back VB in VS 2005 will let you go, I just tested this lovely bit of code:
Module Module1
5: Dim a 10: Console.WriteLine(a) 20: a = a + 1 30: GoTo 10 End Sub
End Module
Works just fine. Scary. :)
Admin
Well, if you know that your program relys on the short-circuiting behaviour, then that VB code is not really equivalent... The appropriate code would be:
Which is not less readable, clearly indicates the short-circuit behaviour and allows you to have much more specific error messages if you need them:
The way I look at it: there are far more idiots in the world than anything else (except possibly insects, but that's debatable...) So if you design a language which idiots can use, their junk will drown out even the most dedicated senible programmer's contributions....
Admin
Clearly, it's a Klingon Bird of Prey. I've definitely seen worse ASCII art.
Admin
Then you must really hate C++, since it was designed with the intent of doing the same thing as this flexibility in VB syntax. In an interview with the IEEE some years ago, [the real one, not the earlier hoax] Dr. Bjarne Stroustrup, the creator of C++, made the point that C++ was not designed to be an "object-oriented" language exclusively, but rather one that supported a wide range of programming styles, object oriented being one of them.
This doesn't mean that there should not be coding standards within any particular organization, and certainly any development project that uses contributed code or modules could benefit by having clearly-defined interfaces as well as coding and style standards. The point is that the best of programmers don't get stuck in the box of "one way to do it".
Admin
I understand what you mean, but this is the point I'm getting at, All of VB's features seem to just be a quick and dirty hack of the original BASIC language. where as C++'s features seem to be incorporated as part of the language.
Addendum (2007-03-04 04:29):
I understand what you mean, but this is the point I'm getting at, All of VB's features seem to just be a quick and dirty hack of the original BASIC language. where as C++'s features seem to be incorporated as part of the language.
I'm not saying that I would never use VB. What I am saying, is that I dislike the language for what I have stated above
Admin
At work I work in both VB.net and C#. The only times I have ever written something like "if(x = 5)" instead of "If(x == 5) is when I have switched languages within the last couple of hours.
Admin
A poor worker blames his tools, but a good worker doesn't start off by mucking around with poor substitutes for good tools, and thus doesn't need to blame the poor work on the actual shortcomings of the tools.
The fact that it's possible to do something doesn't prove that its a wise thing to do.
Admin
I totally see a hand giving me the finger. Makes me want to see if I can restructure some of my code to do that ;)
Admin
Actually you probably could. However, on modern architectures, there's little point as peeking or poking anywhere other than where you already have a variable will probably just crash your app. But you still can put arbitrary addresses into a pointer. Plus your compiler complains about converting nonpointer to pointer (which you have to do to pull this off).
This code assumes an x86 architecture. Obviously having fun with pointers like this isn't portable. You will also have to silence the compiler complaints.
In C++ it's probably easier to do without complaints from the compiler (but still not a good idea):
Only useful if you're doing something like DOS or embedded C++ where specific addresses might give you access to things. But then you should have headers with predefined pointers and not have to do this.
(sidenote: what's with the forum doublespacing code blocks?)
Admin
Admin
First: No validation of the "command" (I guess that is what cmd stands for).
Second: Not using a qualified exception, but identifying an exception based on its message string (which might be localized).
Third: Exceptions used for flow control.
Fourth: if n = 0 then n = 1.
Fifth: Jumping out of a loop with goto when there is a perfectly legal way of quitting (I have to elaborate: I read that there is an "End For" statement in VB, and I see no ellipse down there, so I guess that the label CloseCmd really is below the loop.)
Captcha: Tesla (brzzzzzzzzzzzzzt*zap*bang)
Admin