View Poll Results: Is goto an acceptable command in VB?
- Voters
- 15. You may not vote on this poll
-
January 23rd, 2003, 07:29 PM
#1
Using Goto in VB
Well, I'm reading a C++ Book. It says that using the goto command in C++ is shunned by programmers. I'm just wondering if that applies to vb...
Now not being an expert programmer, I've found the goto command very useful in vb to get out of loops, and just to streamline my whole code.
So thats the question at hand... Is goto an acceptable command in VB?
-Edited by Cimperiali to add two more options
Last edited by Cimperiali; January 28th, 2003 at 11:52 AM.
-
January 23rd, 2003, 08:09 PM
#2
Good question for debate....I think what your c++ source is intimating is the notion of 'spaghetti code' which is an archaic style of programming. In today's world of modular and object oriented approaches, using goto statements to jump around various bits of logic is indeed frowned upon, however, in VB, the goto is obviously needed in the error handling department (on err goto error_trap ie.) This sort of flow control is certainly useful, but if you are using goto to jump to various parts of code that could be encapsulated in a sub or function (perhaps within a class or module) the latter is definately preferred. Otherwise, altering the app down the road would be nightmarish, not to mention the great advantage in terms of code reusibility that is gained with the modular approach....and that's my two cents...next!!
DA
-
January 23rd, 2003, 08:55 PM
#3
I think you need to modify the poll to add "It Depends"
I don't think any of the poll answers actually reflect what I think. It is good (and pretty much imperative for error handling), but I've seen it used in some pretty crazy ways!
-
January 23rd, 2003, 10:07 PM
#4
Used properly and not to excess its excellent. I like it...
but like TwoDogs said, it can be misused.
-
January 25th, 2003, 01:41 AM
#5
goto has ots own place
Yes GOTO has its own place in coding. In some cases like error handling we have no other option but GOTO.
But i think i is not good idea to use this command in any logic. GOTO is makes code less-readable and less-undertandable.
-
January 25th, 2003, 02:23 AM
#6
Well there's no harm in GOTO as long as it is handled properly. In fact, it is useful in many ways!
Busy 
-
January 26th, 2003, 11:12 AM
#7
It's the fastest 'jump' because it doesn't have the overhead of inserting return address to the stack that are common on jump commands for those so-called 'structured' programming languages.
Marketing our skills - please participate in the survey and share your insights
-
-
January 28th, 2003, 11:56 AM
#8
I use it only in error trapping
And usually avoid it as long as I can in normal code.
But I accept it as long as you're able not to make code obfuscated
That is: Clarity of code (not only for me but also for those who may follow) is a priority to which I am ready to sacrify time (mine, in coding more, and of Pgm in quikness).
Have a nice day, you all
Cesare Imperiali
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
January 28th, 2003, 12:20 PM
#9
Exit function substitute
It depends of the use of the GoTo, most of the time, it can be avoided, however, I think it can make a good Exit Function substitute.
Lets think about a validation function validating many entries. You will probably have to use Exit Function now and then, like:
If not IsNumeric(Variable) Then
Exit Function
End if
However, you could want to replace the Exit Function by a GoTo EndOfFunction, so you can do additionnal thing when the function exit, like resetting the MousePointer of the screen to normal.
Most of the times, you can avoid (or replace) a GoTo by using imbricated IF, Select statement and Loop. Also, naming the Goto Label is important. I did never use Goto except for error trapping and to replace Exit function, it can be avoided in most of the case 
JeffB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|