[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

I'm starting to use Goto

mm

6/29/2012 10:44:00 PM

Lately, it's about the third time that after thinking... how to do something
inside a procedure, and I don't want to repeat a whole section of code, but
there are also many procedure level variables that would make difficult to
send that section outside and put in into function, and I came to the
conclusion that it is just more practical to place a jump, a Goto.

I know that it's tagged as a bad practice, but... is it?


107 Answers

Joe Bruno

7/31/2010 11:15:00 AM

0

On Jul 31, 12:36 am, "Anonymous" <anonym...@nowhere.com> wrote:
> "Joe Bruno" <joebr...@indystart.com> wrote in message
>
> news:0613fd25-caaa-4971-9883-003a9d1b962d@i4g2000prf.googlegroups.com...
>
> You aren't very bright Bruno.

You aren't bright enough to make that decision,

Joe Bruno

8/3/2010 6:10:00 AM

0

On Aug 2, 4:33 pm, "Unhappy Observer" <n...@allhappywithisrael.not>
wrote:
> "Joe Bruno" <joebr...@indystart.com> wrote in message
>
> news:9edc7540-771e-4342-a7c5-75d6abf25011@g21g2000prn.googlegroups.com...
> On Jul 29, 9:55 pm, "Unhappy Observer" <n...@allhappywithisrael.not>
> wrote:
>
>
>
>
>
> > "Joe Bruno" <joebr...@indystart.com> wrote in message
>
> >news:0613fd25-caaa-4971-9883-003a9d1b962d@i4g2000prf.googlegroups.com...
> > On Jul 29, 9:17 pm, "Unhappy Observer" <n...@allhappywithisrael.not>
> > wrote:
>
> > > On Nov 21, 11:24 am, Joe Bruno <jbr...@indystart,com > wrote:
>
> > > > On Nov 20, 9:34 pm, The Rebberend <abus...@googlemail,com > wrote:
>
> > > > > On Nov 21, 5:15 am, Joe Bruno <jbr...@indystart,com > wrote:
>
> > > > > > On Nov 20, 8:28 pm, flav...@verizon,net wrote:
>
> > > > > > > Are you cowering under the kitchen table again, as I predicted,
> > > > > > > Philthy?
>
> > > > > > > Susan
>
> > > > > > The real coward is the one who posts as someone else.
>
> > > > > Ah, you mean someone called Art Tandy who posts as "Joe B'runo",
> > > > > B'runo?
>
> > > > NO, I mean someone who is not a reverend posting as one.
>
> > > Even Art Tandy is a fake name;
> > >So is your nym of "Unhappy Observer",
>
> > I am an observer and I am very unhappy with what I see you jews doing to
> > the
> > world.- Hide quoted text -
>
> > - Show quoted text -
> >That's quite beside the point, which is that you do not identify your
> >self with your true legal name. I have already done that.
>
> If I do identify myself by my real name, the Jews will jail me or assault
> me. It's their way.- Hide quoted text -
>
> - Show quoted text -

Assault? You're such a fruitless nothing, they can knock you down with
a sneeze.

BeeJ

6/29/2012 11:04:00 PM

0

Eduardo was thinking very hard :
> Lately, it's about the third time that after thinking... how to do something
> inside a procedure, and I don't want to repeat a whole section of code, but
> there are also many procedure level variables that would make difficult to
> send that section outside and put in into function, and I came to the
> conclusion that it is just more practical to place a jump, a Goto.
>
> I know that it's tagged as a bad practice, but... is it?

It's based on the complaint that GoTo's are hard to follow.
But you can write hard to follow code without any GoTo's.
Just don't format/indent it.

You don't need to goto previous (upwards) code. That I consider bad
form.

Spagetti code (lots of GoTos going forward and backwards) using GoTo is
hard to read.

Watch 'em jump on me.

On Error GoTo ... ' Oh no, a GoTo

I always use these and I classify them as GoTos becasue they are not
named destinations. You have to scan the code to see where they are
going.

Do

Exit Do ' is a goto.

Loop While True

For I = ...

Exit For ' is a goto

Next I

' All these are GoTos but easier to follow
Exit Function
Exit Sub
Exit Property

And if I do not want to make a variable global (Public) then I
sometimes (seldom) use GoSub. Listen to the screams.

Whenever i do use these constructs it just tickles me to know that
someone out there is screaming.

Bottom line, well commented code can stand a few GoTos.

--
Present and unaccounted for.


mm

6/29/2012 11:22:00 PM

0


"BeeJ" <nospam@spamnot.com> escribió en el mensaje
news:jslc9f$nbf$1@speranza.aioe.org...

> It's based on the complaint that GoTo's are hard to follow.
> But you can write hard to follow code without any GoTo's.
> Just don't format/indent it.

Yes, are hard to follow and if you want to follow the code execution, and
you start the step by step in a section of the code that has a label, you
don't know if it the flow came from a Goto or from the normal execution.

Yes, I try to avoid it like the plague, but I see that sometimes it's
practical just to place a goto, adding three or four lines, and not to have
to rewrite the code and to add a function with ten variables.



Ralph

6/30/2012 12:55:00 AM

0

On Fri, 29 Jun 2012 16:04:12 -0700, BeeJ <nospam@spamnot.com> wrote:

>Eduardo was thinking very hard :
>> Lately, it's about the third time that after thinking... how to do something
>> inside a procedure, and I don't want to repeat a whole section of code, but
>> there are also many procedure level variables that would make difficult to
>> send that section outside and put in into function, and I came to the
>> conclusion that it is just more practical to place a jump, a Goto.
>>
>> I know that it's tagged as a bad practice, but... is it?
>
>It's based on the complaint that GoTo's are hard to follow.
>But you can write hard to follow code without any GoTo's.
>Just don't format/indent it.
>
>You don't need to goto previous (upwards) code. That I consider bad
>form.
>
>Spagetti code (lots of GoTos going forward and backwards) using GoTo is
>hard to read.
>
>Watch 'em jump on me.
>
>On Error GoTo ... ' Oh no, a GoTo
>
>I always use these and I classify them as GoTos becasue they are not
>named destinations. You have to scan the code to see where they are
>going.
>
>Do
>
> Exit Do ' is a goto.
>
>Loop While True
>
>For I = ...
>
> Exit For ' is a goto
>
>Next I
>
>' All these are GoTos but easier to follow
>Exit Function
>Exit Sub
>Exit Property
>

Actually none of those are "GOTOs" within the context of what Dijkstra
meant when he started the brouhaha, some 40+ years ago, with the
immortal words - "... the go to statement should be abolished from all
"higher level" programming languages...". Your examples are all either
conditional jumps or part of a language supplied flow control
statements.

What he, and later others are referring to, is using what might be
called unstructured gotos within a structured programming paradigm.
Even then Dijkstra allowed the exception for complicated control flow
structures.

The admonition is useful for beginning programmers because it helps
them to not so quickly adopt an "escape clause" in a complex situation
when there is likely a more viable flow control structure available in
using a standard control structure - and they are just not aware of it
yet.

>And if I do not want to make a variable global (Public) then I
>sometimes (seldom) use GoSub. Listen to the screams.
>

I generally discourage the use of GoSubs by beginning programmers due
to fact they are often only a Return Statement away from confusion, if
not disaster. <g>

>Whenever i do use these constructs it just tickles me to know that
>someone out there is screaming.
>

Likely the same reason I enjoy using On ... GoSub statement, the bang
operator, and colons.

>Bottom line, well commented code can stand a few GoTos.

If they are truly part of an "owner-drawn", custom, control structure,
then they had better be well commented. <g>

-ralph

mm

6/30/2012 1:30:00 AM

0


"ralph" <nt_consulting64@yahoo.com> escribió en el mensaje
news:7lfsu7lsn6dpr5a4ouivatk31u95isn78b@4ax.com...

> Actually none of those are "GOTOs" within the context of what Dijkstra
> meant when he started the brouhaha, some 40+ years ago, with the
> immortal words - "... the go to statement should be abolished from all
> "higher level" programming languages...". Your examples are all either
> conditional jumps or part of a language supplied flow control
> statements.
>
> What he, and later others are referring to, is using what might be
> called unstructured gotos within a structured programming paradigm.
> Even then Dijkstra allowed the exception for complicated control flow
> structures.

But I have read sometimes that "the only justified Goto is the one in 'On
Error'"

And I'm not sure, but I think it was also in the book of Bruce McKinney.

> The admonition is useful for beginning programmers because it helps
> them to not so quickly adopt an "escape clause" in a complex situation
> when there is likely a more viable flow control structure available in
> using a standard control structure - and they are just not aware of it
> yet.

Yes, it's a good advice for beginners to try to avoid Gotos.


Ralph

6/30/2012 1:38:00 AM

0

On Fri, 29 Jun 2012 20:22:10 -0300, "Eduardo" <mm@mm.com> wrote:

>
>"BeeJ" <nospam@spamnot.com> escribió en el mensaje
>news:jslc9f$nbf$1@speranza.aioe.org...
>
>> It's based on the complaint that GoTo's are hard to follow.
>> But you can write hard to follow code without any GoTo's.
>> Just don't format/indent it.
>
>Yes, are hard to follow and if you want to follow the code execution, and
>you start the step by step in a section of the code that has a label, you
>don't know if it the flow came from a Goto or from the normal execution.
>
>Yes, I try to avoid it like the plague, but I see that sometimes it's
>practical just to place a goto, adding three or four lines, and not to have
>to rewrite the code and to add a function with ten variables.
>

As I posted before, I generally discourage new programmers from using
gotos and the other constructs often referred to as "considered
harmful", a.k.a "Evil". <g> (such as global's).

However, for intermediate and the occasional advanced programmer who
strongly insists on using them, even after reading the volumes of
articles written by the Pros, I always say go ahead, have at it, for
one specific reason - Experience is the best teacher.

These constructs share three things in common; they are basically
benign, they all have scenarios wherein they can be the best solution;
and they all have several pitfalls just waiting. It is the latter
which will always eventually 'prove the rule' and bring about an
understanding. <bg>

-ralph

mm

6/30/2012 1:40:00 AM

0


"ralph" <nt_consulting64@yahoo.com> escribió en el mensaje
news:7lfsu7lsn6dpr5a4ouivatk31u95isn78b@4ax.com...

> Likely the same reason I enjoy using On ... GoSub statement, the bang
> operator, and colons.

I use the bang operator a lot. For me it's practical.

I think it's a matter of taste. I (almost) don't use colons to put more than
one statement in a line, I don't use underscores to split one statement in
more than one line (unless I need to post the code here), I don't declare
more than one variable in a line. It's like the code is more readable for
me. And I don't use "With".
It's about how each one is used to write the code, I'm not saying that for
someone else it should be the same way.
About Gosub, I've never used it in VB (I did in older BASIC).


BeeJ

6/30/2012 1:48:00 AM

0

Eduardo presented the following explanation :
> "ralph" <nt_consulting64@yahoo.com> escribió en el mensaje
> news:7lfsu7lsn6dpr5a4ouivatk31u95isn78b@4ax.com...
>
>> Likely the same reason I enjoy using On ... GoSub statement, the bang
>> operator, and colons.
>
> I use the bang operator a lot. For me it's practical.
>
> I think it's a matter of taste. I (almost) don't use colons to put more than
> one statement in a line, I don't use underscores to split one statement in
> more than one line (unless I need to post the code here), I don't declare
> more than one variable in a line. It's like the code is more readable for me.
> And I don't use "With".
> It's about how each one is used to write the code, I'm not saying that for
> someone else it should be the same way.
> About Gosub, I've never used it in VB (I did in older BASIC).

Has anyone ever done a speed tradeoff of GoSub vs Call (using the stack
to pass params)?

How about speed using Call (using the stack to pass params) vs globals?

--
Present and unaccounted for.


Ralph

6/30/2012 1:49:00 AM

0

On Fri, 29 Jun 2012 22:30:09 -0300, "Eduardo" <mm@mm.com> wrote:

>
>"ralph" <nt_consulting64@yahoo.com> escribió en el mensaje
>news:7lfsu7lsn6dpr5a4ouivatk31u95isn78b@4ax.com...
>
>> Actually none of those are "GOTOs" within the context of what Dijkstra
>> meant when he started the brouhaha, some 40+ years ago, with the
>> immortal words - "... the go to statement should be abolished from all
>> "higher level" programming languages...". Your examples are all either
>> conditional jumps or part of a language supplied flow control
>> statements.
>>
>> What he, and later others are referring to, is using what might be
>> called unstructured gotos within a structured programming paradigm.
>> Even then Dijkstra allowed the exception for complicated control flow
>> structures.
>
>But I have read sometimes that "the only justified Goto is the one in 'On
>Error'"
>
>And I'm not sure, but I think it was also in the book of Bruce McKinney.
>

Have always like Bruce McKinney. I believe in this case he was only
viewing a 'Goto' from the standpoint of the single keyword, and not
appreciating the difference between its use as part of a standard
control statement, and a Goto Statement itself.

-ralph