[Gambas-user] Possible suggestion/question

Emil Lenngren emil.lenngren at ...626...
Fri Mar 2 13:10:05 CET 2012


GOTO is not evil, but can, if you do it "wrong", result in code that might
be hard to read.
For example, in C you can do like this:
if (a){
  goto a_label;
} else {
  if (b){
    switch(c){
        case 1: puts("Hello"); break;
        case 2: puts("Yo"); break;
        a_label: puts("Tjena"); break;
    }
  }
}
And that is *not* a good structure of the program. In Gambas, you are not
allowed to jump into a control structure like this, but only jump out. As
long as the code has good structure, I see no problems with Gotos. And
sometimes Goto is needed to get a good structure.

/Emil

2012/3/2 M. Cs. <mohareve at ...626...>

> I red somewhere that GOTO is something that a good programer should
> avoid at all costs.
> GOTO is a host of countless bug possibilities.
>
> 2012/3/2, John Spikowski <support at ...2529...>:
> > On Fri, 2012-03-02 at 03:31 +0100, Benoît Minisini wrote:
> >> Anyway, there is a syntax problem. In Basic, GOSUB is ended by a RETURN
> >> instruction, but RETURN is already used to exit the all function. Or
> >> maybe RETURN will return from the function only if there is no pending
> >> GOSUB.
> >>
> > Most Basic languages allow exiting a GOSUB and not RETURNing. GOTO is
> > pretty smart in SciptBasic and used to prematurely exit any stack
> > tracking structure and cleans up on the way out.
> >
> > In ScriptBasic the function name is used rather then RETURN.
> >
> > FUNCTION myfunc ()
> >
> >  myfunc = 1
> >
> > END FUNCTION
> >
> >
> >
> >
> >
> ------------------------------------------------------------------------------
> > Virtualization & Cloud Management Using Capacity Planning
> > Cloud computing makes use of virtualization - but cloud computing
> > also focuses on allowing computing to be delivered as a service.
> > http://www.accelacomm.com/jaw/sfnl/114/51521223/
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list