Very Small First Program

Re: Very Small First Program

Post by KthProg on Tue Feb 26, 2013 9:08 pm
([msg=74196]see Re: Very Small First Program[/msg])

I use gotos all the time in VBA and I've never had an issue with them. They are extremely useful.
Also...jesus too many comments lol.
I'm still learning c++ at this point myself.
User avatar
KthProg
Poster
Poster
 
Posts: 219
Joined: Wed Jan 23, 2013 7:06 pm
Blog: View Blog (0)


Re: Very Small First Program

Post by centip3de on Tue Feb 26, 2013 9:29 pm
([msg=74199]see Re: Very Small First Program[/msg])

KthProg wrote:I use gotos all the time in VBA and I've never had an issue with them. They are extremely useful.
Also...jesus too many comments lol.
I'm still learning c++ at this point myself.


Goto's are generally accepted as bad practice because they form terrible spaghetti code. Not only that, but they're usually unneeded and thus, really only form spaghetti code.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1412
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: Very Small First Program

Post by KthProg on Tue Feb 26, 2013 9:32 pm
([msg=74200]see Re: Very Small First Program[/msg])

Well, they're dangerous in extremely large projects, because it's difficult to see the flow of the program.
But when the code compiles down, it has to use gotos at the the assembly level, from what I know.
But it does save space sometimes. Also, in VBA, they're the only means of error catching.
It's actually very efficient to do things this way.
You use a statement like this at the beginning of a piece of code.
On Error Goto errorCatcher
then later you do this...
errorCatcher:
If Err.Number = someerrornumberofimportance or Err.Number = someotherimportanterrornumber then
Do error catching routine.
End If

this allows you to consolidate all of your error catching at the end of the program, and if the error catching fails, it will continue wherever you place the errorCatcher label. It also allows you to create a different, separate, easily readable routine for each error type. You could also use flags to tell where in the code the error is coming from, if you only want to catch it if it occurs in a certain block.

I think they should at least be used in situations like this, where you don't need error catching for a specific statement, but rather for a specific error.
User avatar
KthProg
Poster
Poster
 
Posts: 219
Joined: Wed Jan 23, 2013 7:06 pm
Blog: View Blog (0)


Re: Very Small First Program

Post by centip3de on Tue Feb 26, 2013 11:25 pm
([msg=74208]see Re: Very Small First Program[/msg])

KthProg wrote:Well, they're dangerous in extremely large projects, because it's difficult to see the flow of the program.
But when the code compiles down, it has to use gotos at the the assembly level, from what I know.


No, ASM does not use gotos, it uses jumps. And although some similarities between the two can be drawn, they're completely different.

KthProg wrote:But it does save space sometimes. Also, in VBA, they're the only means of error catching.
It's actually very efficient to do things this way.
You use a statement like this at the beginning of a piece of code.
On Error Goto errorCatcher
then later you do this...
errorCatcher:
If Err.Number = someerrornumberofimportance or Err.Number = someotherimportanterrornumber then
Do error catching routine.
End If

this allows you to consolidate all of your error catching at the end of the program, and if the error catching fails, it will continue wherever you place the errorCatcher label. It also allows you to create a different, separate, easily readable routine for each error type. You could also use flags to tell where in the code the error is coming from, if you only want to catch it if it occurs in a certain block.

I think they should at least be used in situations like this, where you don't need error catching for a specific statement, but rather for a specific error.


I can't speak for VB, but in other languages you would do this just by calling a function, which is a much cleaner and clearer way of doing things. Not only that, but with functions, you don't get accidental calls to errors, or what-have-you. In fact, in any language (that supports them) there is no reason to use gotos versus functions.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rick Cook
User avatar
centip3de
Moderator
Moderator
 
Posts: 1412
Joined: Fri Aug 20, 2010 5:46 pm
Blog: View Blog (0)


Re: Very Small First Program

Post by KthProg on Tue Feb 26, 2013 11:51 pm
([msg=74213]see Re: Very Small First Program[/msg])

Well I dont think VB.Net supports gotos, and VB.net has try-catch-throw syntax but error catching with On Error Goto in VBA is my preferred syntax after using both, only because try catch throw is messier especially when you want to make changes to how and what errors you catch.
I don't think it should be used pretty much anywhere else, but for error catching its great.
User avatar
KthProg
Poster
Poster
 
Posts: 219
Joined: Wed Jan 23, 2013 7:06 pm
Blog: View Blog (0)


Re: Very Small First Program

Post by fashizzlepop on Wed Feb 27, 2013 12:47 am
([msg=74225]see Re: Very Small First Program[/msg])

I don't know much about VB but in just about Any other language, using try, catches is the preferred method.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Very Small First Program

Post by KthProg on Wed Feb 27, 2013 1:36 am
([msg=74228]see Re: Very Small First Program[/msg])

In just about any other language try catch is the only method lol.
And VB is different than VBA which is different than VB.Net
Just sayin'. lol

VBA is a subset of VB
VB.Net is a language based on VB.
VB is now deprecated (As of version 6)

VB and VBA are very similar
VB.Net is very different.
User avatar
KthProg
Poster
Poster
 
Posts: 219
Joined: Wed Jan 23, 2013 7:06 pm
Blog: View Blog (0)


Previous

Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests