Re: Good Use of GOTO

new topic     » goto parent     » topic index » view thread      » older message » newer message

Derek Parnell wrote:
> 
> Kat wrote:
> 
> > I gave code for that also. It involved:
> > goto exit
> > goto retry
> > goto restart
> > goto next
> > goto cleanup&return
> > etc.
> > 
> > The only way that's not clear is if you don't read english.
> 
> For example:
> 
>    ----- fileA.e ----
>    function qwerty( integer b)
>    integer a
>    a = b
>    label start:
>    if a < 10 then
>      a = foo(b)
>      if a < 0 then
>         goto exit  -- Which exit does this go to?
>      end if
>      b = bar(a)
>      goto start    -- which start?
>    end if
>    label exit:
> 
>    label start:
>    a = 5
>    while a < 10 do
>      a = bar(b)
>      if a < 0 then
>         goto exit
>      end if
>      b = foo(a)
>      foto start
>    end if
>    label exit:
> 
>    return a
>    end function
> 
> Oh hang on, all labels in the scope must be unique. So now I have to
> numbering?
> them.
> 
>    function qwerty( integer b)
>    integer a
>    a = b
>    label start:
>    if a < 10 then
>      a = foo(b)
>      if a < 0 then
>         goto exit
>      end if
>      b = bar(a)
>      goto start
>    end if
>    label exit:
> 
>    label start1:
>    a = 5
>    if a < 10 do
>      a = bar(b)
>      if a < 0 then
>         goto exit1
>      end if
>      b = foo(a)
>      goto start1
>    end if
>    label exit1:
> 
>    return a
>    end function
> 
> So now not only do I have more to type and more to read I also have to create
> unique label names. 
> 
> Then we've got this sort of problem....
> 
>    a = b
>    label exit:
>    if a < 10 then
>      a = foo(b)
>      if a < 0 then
>         goto start
>      end if
>      b = bar(a)
>      goto exit
>    end if
>    label start:
> 
> Identical syntax from Euphoria's point of view, but very misleading for humans
> to read. Yes, I know is a silly example but the point is that it is possible
> to use label names that are actually misleading in terms of informing the
> reader
> about the coder's intentions.
> 
> 
> The solution we have chosen is this ...
> 
>    function qwerty( integer b)
>    integer a
>    a = b
> 
>    while a < 10 do
>      a = foo(b)
>      if a < 0 then
>         exit
>      end if
>      b = bar(a)
>    end while
> 
>    a = 5
>    while a < 10 do
>      a = bar(b)
>      if a < 0 then
>         exit
>      end if
>      b = foo(a)
>    end while
> 
>    return a
>    end function
> 
> There is no misleading control flow statements now. They are shorter. They
> inform
> you of the coder's intentions. And this is already in Euphoria 3.1

Yeas, sure if you are going to intentionally screw things up. 
meuw miaow miaol maol miaol raoul moew mewl moew mew moul miaow rowl reul reu
miao merou?
 miaow meul maouw moau merow rewl maouw rewl rew moew reul miaow meul
 miao mowl merow miao reu merw riaow
 merou. Merou maou rowl
 rew maou moau meul rowr mewl meow rew moew meow mewl
 miaow merw mew merw
 mew reu rowr meuw rowl moul merow maouw miaow miao merou maol
reul moul raoul merw meuw meul miao mew rowl meuw meow rewl miaow moew reu meuw
 meow merw rowr rowl
 maol rowr moau merow miaow riaow meul maol moul merou?
 maou meow moew maou miaow
 miao merw mowl rewl miaow miaol rew meow merw meul moul rowr maol merw miaow
miaow mew merou mowl merow rewl maol miaow moul meul miao riaow mowl maol moul
 riaow meow moau rowl
 moau raoul miaow moul moew merow moew rew riaow
 rew meow maou miaow moul
miaow miaol miaow moau miaow maouw meul miaow meul mewl moul meuw meul moul
 rewl merw mewl riaow
 merou merow maou miaol maouw
 reu moul rew moul meow moau rowr moau rowr mew moew reu maou moew rewl?
 miaow merou meul
raoul merow mowl miao maou mew rowr miaow raoul moul reu miao raoul reul rowr
 maol meow rewl
 mowl rowr mew rew
mewl miao meow merw miaow moul merou rew maouw reul riaow miaol reu rew miaow
 rew

Kat

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu