1. Conceptual problem solved by GOTO

Suppose we have GOTO and this kind of code (which I think is common):
procedure proc1()
if cond1 then
   .. some code here ..
   if cond2 then
      .. some code here ..
      if cond3 then
         .. some code here ..
         goto OUT
      end if
      .. some code here ..
   end if
   .. some code here ..
end if
OUT:
.. some code here ..
end procedure


In Eu 3.1, a possible implementation would be:
procedure proc1()
for i=1 to 1 do
if cond1 then
   .. some code here ..
   if cond2 then
      .. some code here ..
      if cond3 then
         .. some code here ..
         exit
      end if
      .. some code here ..
   end if
   .. some code here ..
end if
end for
.. some code here ..
end procedure


Now, without GOTO, we are forced to (mis)use a loop construct (for-loop,
while-loop) where there is NO loop.
Conceptually, IMHO this makes no sense.
To avoid the conceptual problem we could use flags, but IMHO this is even worst.

Regards,
   Fernando

new topic     » topic index » view message » categorize

2. Re: Conceptual problem solved by GOTO

I keep seeing people make the same false claims about GOTO over and over.

The issue regarding GOTO vs. structured code IS NOT SPEED.  Yes, calling a
routine to refactor code makes the refactored code slower... but you NEVER
have to call a sub routine.  The tradeoff without using functions is SIZE
not SPEED.  

I've identified some lines of .. some code here .. with (A) and (B)

Fernando Bauer wrote:
> procedure proc1()
> if cond1 then
>    .. some code here ..
>    if cond2 then
>       .. some code here ..
>       if cond3 then
>          .. some code here ..
>          goto OUT
>       end if
>       .. some code here .. (A)
>    end if
>    .. some code here .. (B)
> end if
> OUT:
> .. some code here ..
> end procedure

You will note in the following that line (B) is now inline in two places
(more SIZE) but only executes once (same SPEED)  It should be exactly the
same speed for the if to branch to the else rather than the end if.

procedure proc1()
if cond1 then
   .. some code here ..
   if cond2 then
      .. some code here ..
      if cond3 then
         .. some code here ..
      else
         .. some code here .. (A)
         .. some code here .. (B)
      end if
   else
      .. some code here .. (B)
   end if
end if
.. some code here ..
end procedure

> Now, without GOTO, we are forced to (mis)use a loop construct (for-loop,
> while-loop)
> where there is NO loop.
> Conceptually, IMHO this makes no sense.
> To avoid the conceptual problem we could use flags, but IMHO this is even
> worst.

You are not forced to misuse a loop.  No flags either.

If your basing your desire on GOTOs because of speed you are using a false
premise and should rethink it.

Do I prefer this refactoring?  No.  That's why I use subroutines.  But if
I need speed I just have to make the tradeoff with code size.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> I keep seeing people make the same false claims about GOTO over and over.
> 
> The issue regarding GOTO vs. structured code IS NOT SPEED.  Yes, calling a
> routine to refactor code makes the refactored code slower... but you NEVER
> have to call a sub routine.  The tradeoff without using functions is SIZE
> not SPEED.  
> 
> I've identified some lines of .. some code here .. with (A) and (B)
> 
> Fernando Bauer wrote:
> > procedure proc1()
> > if cond1 then
> >    .. some code here ..
> >    if cond2 then
> >       .. some code here ..
> >       if cond3 then
> >          .. some code here ..
> >          goto OUT
> >       end if
> >       .. some code here .. (A)
> >    end if
> >    .. some code here .. (B)
> > end if
> > OUT:
> > .. some code here ..
> > end procedure
> 
> You will note in the following that line (B) is now inline in two places
> (more SIZE) but only executes once (same SPEED)  It should be exactly the
> same speed for the if to branch to the else rather than the end if.
> 
> procedure proc1()
> if cond1 then
>    .. some code here ..
>    if cond2 then
>       .. some code here ..
>       if cond3 then
>          .. some code here ..
>       else
>          .. some code here .. (A)
>          .. some code here .. (B)
>       end if
>    else
>       .. some code here .. (B)
>    end if
> end if
> .. some code here ..
> end procedure
> 
> > Now, without GOTO, we are forced to (mis)use a loop construct (for-loop,
> > while-loop)
> > where there is NO loop.
> > Conceptually, IMHO this makes no sense.
> > To avoid the conceptual problem we could use flags, but IMHO this is even
> > worst.
> 
> You are not forced to misuse a loop.  No flags either.
> 
> If your basing your desire on GOTOs because of speed you are using a false
> premise and should rethink it.
> 
> Do I prefer this refactoring?  No.  That's why I use subroutines.  But if
> I need speed I just have to make the tradeoff with code size.

That is true in alot of cases but not always. More code can sometimes cause
additional cache misses (I just learned what caches misses actually are the other
day, thx Kat :) which actually make the optimization less efficient than the
original.

This can be seen in certain circumstances simply by rearranging a few lines of
more-or-less unrelated statements. The outcome is identical, but the execution
speed changes for what seems an inexplicable reason. I have often encountered
this type of anomoly when doing benchmarks. changing the order of functions often
produces radically different results, for example.

Chris Bensler
Code is Alchemy

new topic     » goto parent     » topic index » view message » categorize

4. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> I keep seeing people make the same false claims about GOTO over and over.
> 
> The issue regarding GOTO vs. structured code IS NOT SPEED.  Yes, calling a
> routine to refactor code makes the refactored code slower... but you NEVER
> have to call a sub routine.  The tradeoff without using functions is SIZE
> not SPEED.  
> 

I think speed has been emphasized so much because people are demanding reasons
why to add goto and are rejecting any possibility of it ever making sense that
goto may in some situations be easier to read/use/maintain.

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view message » categorize

5. Re: Conceptual problem solved by GOTO

Although I vote NO on general goto, I do vote yes on "exit(x)" whereby x in an
integer allowing you to break out of x many nested loops, which avoids the use of
flags, etc.  A "continue" or "skip" would also be nice for loops, allowing you to
jump ahead to the next iteration immediately.

These could be seen as specific cases of goto, but I still vote NO on general
goto.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Conceptual problem solved by GOTO

Chris Bensler wrote:

> That is true in alot of cases but not always. More code can sometimes cause
> additional cache misses (I just learned what caches misses actually are the
> other day, thx Kat :) which actually make the optimization less efficient than
> the original.
> 
> This can be seen in certain circumstances simply by rearranging a few lines
> of more-or-less unrelated statements. The outcome is identical, but the
> execution
> speed changes for what seems an inexplicable reason. I have often encountered
> this type of anomoly when doing benchmarks. changing the order of functions
> often produces radically different results, for example.

Absolutely.  I just wanted to address the mistaken assertion that GOTO is
faster than structure code (which under the covers often is the exact same
code.)

A poor implementation can make a difference as well.

"Science is the belief in the ignorance of experts." - Richard Feynman

new topic     » goto parent     » topic index » view message » categorize

7. Re: Conceptual problem solved by GOTO

Andy Serpa wrote:
> 
> Although I vote NO on general goto, I do vote yes on "exit(x)" whereby x in
> an integer allowing you to break out of x many nested loops, which avoids the
> use of flags, etc.  A "continue" or "skip" would also be nice for loops,
> allowing
> you to jump ahead to the next iteration immediately.

Exit(n) is quite horrible, if you are deeply nested then you have to go back and
count lines in order to figure out where you will end up.

In any case, your response does not address the original problem, which had no
loops.

> 
> These could be seen as specific cases of goto, but I still vote NO on general
> goto.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Conceptual problem solved by GOTO

Jeremy Cowgar wrote:

> I think speed has been emphasized so much because people are demanding reasons
> why to add goto and are rejecting any possibility of it ever making sense that
> goto may in some situations be easier to read/use/maintain.

I think the example I gave shows the GOTO version to be easier to understand
and that can often be the case.  The problem with GOTO is like the problem
with Nukes... proliferation.  The best way to keep them from being used is
not to have them.  We don't have the choice with Nukes, but we do have the
choice here and now with GOTOs.

"Science is the belief in the ignorance of experts." - Richard Feynman

new topic     » goto parent     » topic index » view message » categorize

9. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> Chris Bensler wrote:
> 
> > That is true in alot of cases but not always. More code can sometimes cause
> > additional cache misses (I just learned what caches misses actually are the
> > other day, thx Kat :) which actually make the optimization less efficient
> > than
> > the original.
> > 
> > This can be seen in certain circumstances simply by rearranging a few lines
> > of more-or-less unrelated statements. The outcome is identical, but the
> > execution
> > speed changes for what seems an inexplicable reason. I have often
> > encountered
> > this type of anomoly when doing benchmarks. changing the order of functions
> > often produces radically different results, for example.
> 
> Absolutely.  I just wanted to address the mistaken assertion that GOTO is
> faster than structure code (which under the covers often is the exact same
> code.)
> 
> A poor implementation can make a difference as well.
> 
> "Science is the belief in the ignorance of experts." - Richard Feynman

I think most of us know that hardcoding values is generally poor programming
practice. What happens when you reorganize your code and no longer have 2 nested
loops but 3 or 4 instead? Then you have to go back and make sure that any exit
statements you used are counting the proper number of blocks.
Not very maintainable. This is just asking for bugs.

Chris Bensler
Code is Alchemy

new topic     » goto parent     » topic index » view message » categorize

10. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> Jeremy Cowgar wrote:
> 
> > I think speed has been emphasized so much because people are demanding
> > reasons
> > why to add goto and are rejecting any possibility of it ever making sense
> > that
> > goto may in some situations be easier to read/use/maintain.
> 
> I think the example I gave shows the GOTO version to be easier to understand
> and that can often be the case.  The problem with GOTO is like the problem
> with Nukes... proliferation.  The best way to keep them from being used is
> not to have them.  We don't have the choice with Nukes, but we do have the
> choice here and now with GOTOs.
> 

I would like to see someone change the euphoria translator to output C code that
does not use C goto's. I have seen other translators as well that use goto's
extensively. I think it's a great approach. Easy on the translator, easy on the
resulting compiler.

Now, I want to take my own domain language used for hospital billings and
initial hospital claim auditing and translate that to Euphoria, but can I? Not
easily. It's far easier to just translate to C and use gotos. Now, why not just
do/keep that? Because it would be far, far easier to use Euphoria as the final
language instead of dealing with users changing the domain language, triggering a
compilation, swapping in the .so, etc...

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view message » categorize

11. Re: Conceptual problem solved by GOTO

Andy Serpa wrote:
> 
> Although I vote NO on general goto, I do vote yes on "exit(x)" whereby x in
> an integer allowing you to break out of x many nested loops, which avoids the
> use of flags, etc.  A "continue" or "skip" would also be nice for loops,
> allowing
> you to jump ahead to the next iteration immediately.
> 
> These could be seen as specific cases of goto, but I still vote NO on general
> goto.

We have a much better method already implemented called labeled loops. It was
discussed here quite a bit. General:

for a = 1 to length(lines) label "line_it" do
    line = lines[a]
    if match("/*", line) then
        while 1 do  --- we are going to eat all comment lines.
            -- read line
            -- test end of comment?
            if end_of_file then
                 exit "line_it"
            end if
        end while
    end if
end for


--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view message » categorize

12. Re: Conceptual problem solved by GOTO

Jeremy Cowgar wrote:
> 
> ken mortenson wrote:
> > 
> > Jeremy Cowgar wrote:
> > 
> > > I think speed has been emphasized so much because people are demanding
> > > reasons
> > > why to add goto and are rejecting any possibility of it ever making sense
> > > that
> > > goto may in some situations be easier to read/use/maintain.
> > 
> > I think the example I gave shows the GOTO version to be easier to understand
> > and that can often be the case.  The problem with GOTO is like the problem
> > with Nukes... proliferation.  The best way to keep them from being used is
> > not to have them.  We don't have the choice with Nukes, but we do have the
> > choice here and now with GOTOs.
> > 
> 
> I would like to see someone change the euphoria translator to output C code
> that does not use C goto's. I have seen other translators as well that use
> goto's
> extensively. I think it's a great approach. Easy on the translator, easy on
> the resulting compiler. 

Because the output of the translator is geared for speed; it is not meant to be
read by or maintained by humans.

Most code doesn't need to be so highly optimized for the machine. As posted at
one of your links "that's the compiler's job".
 
> Now, I want to take my own domain language used for hospital billings and
> initial
> hospital claim auditing and translate that to Euphoria, but can I? Not easily.
> It's far easier to just translate to C and use gotos. Now, why not just
> do/keep
> that? Because it would be far, far easier to use Euphoria as the final
> language
> instead of dealing with users changing the domain language, triggering a
> compilation,
> swapping in the .so, etc...
> 
> --
> Jeremy Cowgar
> <a href="http://jeremy.cowgar.com">http://jeremy.cowgar.com</a>


--
A complex system that works is invariably found to have evolved from a simple
system that works.
--John Gall's 15th law of Systemantics.

"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare

j.

new topic     » goto parent     » topic index » view message » categorize

13. Re: Conceptual problem solved by GOTO

Andy Serpa wrote:
> 
>I do vote yes on "exit(x)" whereby x in an integer allowing you to break
> out of x many nested loops, which avoids the use of flags, etc. 

Although v4.0 will not have "exit(x)" it does have "exit <label>" where <label>
is the name given to a loop. For example:

    while conda label "A" do
        --- stuff ---
        while condb label "B" do
            --- stuff
            if condc then
                exit "A" -- Exits the loop called 'A'
            end if
            -- stuff --
        end while
        -- stuff --
    end while
 

        

>A "continue" or "skip" would also be nice for loops, allowing
> you to jump ahead to the next iteration immediately.

Version 4.0 has a 'continue' statement now. It causes control to immediately
continue with the next iteration. It also can have an optional label name.


There is also a 'retry' statement that causes control to immediately repeat the
same iteration. This will be more useful when exception handling makes to
Euphoria one day.


-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

14. Re: Conceptual problem solved by GOTO

Jeremy Cowgar wrote:
> 
> I would like to see someone change the euphoria translator to output C code
> that does not use C goto's. I have seen other translators as well that use
> goto's
> extensively. I think it's a great approach. Easy on the translator, easy on
> the resulting compiler. 
> 
> Now, I want to take my own domain language used for hospital billings and
> initial
> hospital claim auditing and translate that to Euphoria, but can I? Not easily.
> It's far easier to just translate to C and use gotos. Now, why not just
> do/keep
> that? Because it would be far, far easier to use Euphoria as the final
> language
> instead of dealing with users changing the domain language, triggering a
> compilation,
> swapping in the .so, etc...
> 

That was suppose to say it would be far easier with Euphoria that has goto's...

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view message » categorize

15. Re: Conceptual problem solved by GOTO

Jason Gade wrote:
> 
> 
> Because the output of the translator is geared for speed; it is not meant to
> be read by or maintained by humans.
> 
> Most code doesn't need to be so highly optimized for the machine. As posted
> at one of your links "that's the compiler's job".
>  
> > Now, I want to take my own domain language used for hospital billings and
> > initial
> > hospital claim auditing and translate that to Euphoria, but can I? Not
> > easily.
> > It's far easier to just translate to C and use gotos. Now, why not just
> > do/keep
> > that? Because it would be far, far easier to use Euphoria as the final
> > language
> > instead of dealing with users changing the domain language, triggering a
> > compilation,
> > swapping in the .so, etc...
> > 

You did not address the rest of my message which was the real reason. As
Euphoria does translating to C, I *need* to do translating to Euphoria. *I* will
never look at that translated code. domain languages is a very common pattern
that saves huge amounts of time in many peoples applications.

Please tell me why I cannot make the same use of goto that C does? Do not say
that C does it for speed, it does not. goto is used for the ease of the
translator.

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view message » categorize

16. Re: Conceptual problem solved by GOTO

Andy Serpa wrote:
> 
> Although I vote NO on general goto, I do vote yes on "exit(x)" whereby x in
> an integer allowing you to break out of x many nested loops, which avoids the
> use of flags, etc.  A "continue" or "skip" would also be nice for loops,
> allowing
> you to jump ahead to the next iteration immediately.
> 
> These could be seen as specific cases of goto, but I still vote NO on general
> goto.

I don't like that at all.

for index1 = 1 to 10 do
  for index2 = 1 to 10 do
    if (condition) then
      exit(2)
    end if
  end for
end for
--exit(2) was here.

for index1 = 1 to 10 do
  for index3 = 1 to 15 do
    for index2 = 1 to 10 do
      if (condition) then
        exit(2)
      end if
    end for
  end for
  --exit(2) is now here
end for
--exit(2) was here.

t.

A reasonable change to the code changed the exit point.
exit label makes more sense.

    Lucius L. Hilley III - Unkmar

new topic     » goto parent     » topic index » view message » categorize

17. Re: Conceptual problem solved by GOTO

Jeremy Cowgar wrote:
> 
> Jason Gade wrote:
> > 
> > 
> > Because the output of the translator is geared for speed; it is not meant to
> > be read by or maintained by humans.
> > 
> > Most code doesn't need to be so highly optimized for the machine. As posted
> > at one of your links "that's the compiler's job".
> >  
> > > Now, I want to take my own domain language used for hospital billings and
> > > initial
> > > hospital claim auditing and translate that to Euphoria, but can I? Not
> > > easily.
> > > It's far easier to just translate to C and use gotos. Now, why not just
> > > do/keep
> > > that? Because it would be far, far easier to use Euphoria as the final
> > > language
> > > instead of dealing with users changing the domain language, triggering a
> > > compilation,
> > > swapping in the .so, etc...
> > > 
> 
> You did not address the rest of my message which was the real reason. As
> Euphoria
> does translating to C, I *need* to do translating to Euphoria. *I* will never
> look at that translated code. domain languages is a very common pattern that
> saves huge amounts of time in many peoples applications.
> 
> Please tell me why I cannot make the same use of goto that C does? Do not say
> that C does it for speed, it does not. goto is used for the ease of the
> translator.
> 
> --
> Jeremy Cowgar
> <a href="http://jeremy.cowgar.com">http://jeremy.cowgar.com</a>

I never said you couldn't use goto. You can see that I've been relatively
neutral in this discussion and my official vote is "abstain".

However, when I see an argument with which I disagree I still feel compelled to
answer it.

As for you DSL example? I have no idea as I've never written anything in a DSL
and have zero experience in them. Are gotos common in DSLs? If so, why?

--
A complex system that works is invariably found to have evolved from a simple
system that works.
--John Gall's 15th law of Systemantics.

"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare

j.

new topic     » goto parent     » topic index » view message » categorize

18. Re: Conceptual problem solved by GOTO

Jason Gade wrote:
>  
> As for you DSL example? I have no idea as I've never written anything in a DSL
> and have zero experience in them. Are gotos common in DSLs? If so, why?
> 

Yes, goto's are very common the reason is simplicity. I push onto the "jump"
stack a label when, say a while is started, and when a continue is hit, I access
the stack, when an end while is hit, I pop from the stack, etc...

It's much easier to translate using goto than trying to map all sorts of custom
logic to set structures. Now, you can easily map any code of my code by hand to
existing structures, but try to do it automated and maintain reliability.

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view message » categorize

19. Re: Conceptual problem solved by GOTO

Jason Gade wrote:
> 
> Jeremy Cowgar wrote:
> > 
> > You did not address the rest of my message which was the real reason. As
> > Euphoria
> > does translating to C, I *need* to do translating to Euphoria. *I* will
> > never
> > look at that translated code. domain languages is a very common pattern that
> > saves huge amounts of time in many peoples applications.
> > 
> I never said you couldn't use goto. You can see that I've been relatively
> neutral
> in this discussion and my official vote is "abstain".
> 
> However, when I see an argument with which I disagree I still feel compelled
> to answer it.
> 
> As for you DSL example? I have no idea as I've never written anything in a DSL
> and have zero experience in them. Are gotos common in DSLs? If so, why?

I think that what he's saying is that he wants to write a DSL to euphoria
translator, not that his DSL has gotos (though it might).  Just like with
the euphoria translator, you might have incompatible datatypes, for example,
which make it impossible to write a general for loop, for example, without
using goto.  It's often easier to write code that does explicitly what
higher level constructs implement (i.e., the initialization, condition
checking and iteration of a for loop).

Having goto gives lower level control to the programmer, which is basically
why it's so easy to make spaghetti code with it.

Matt

new topic     » goto parent     » topic index » view message » categorize

20. Re: Conceptual problem solved by GOTO

Derek Parnell wrote:
> 
> Andy Serpa wrote:
> > 
> >I do vote yes on "exit(x)" whereby x in an integer allowing you to break
> > out of x many nested loops, which avoids the use of flags, etc. 
> 
> Although v4.0 will not have "exit(x)" it does have "exit <label>" where
> <label>
> is the name given to a loop.

How I hate to mention this.  I really, really do hate to mention this.  But I
am compelled to for the sake of truth.  Here we are voting on GOTO and it's
already in.  It's not the name GOTO that makes it a goto.  You can call it 
banana if you want, it's having labels as targets.

So we aren't voting on GOTO; we're just calling it EXIT.

This explains my abstain vote to me.  I actually wondered why I didn't
vote no.  I guess it's just one of those things that you either get or
you don't.  Please don't take that as a shot at those that use GOTO, I
did for decades myself and understand why some might want to use it.

I guess I've just seen it abused way too often to ever use it myself.

"Science is the belief in the ignorance of experts." - Richard Feynman

new topic     » goto parent     » topic index » view message » categorize

21. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> Derek Parnell wrote:
> > 
> > Andy Serpa wrote:
> > > 
> > >I do vote yes on "exit(x)" whereby x in an integer allowing you to break
> > > out of x many nested loops, which avoids the use of flags, etc. 
> > 
> > Although v4.0 will not have "exit(x)" it does have "exit <label>" where
> > <label>
> > is the name given to a loop.
> 
> How I hate to mention this.  I really, really do hate to mention this.  But
> I
> am compelled to for the sake of truth.  Here we are voting on GOTO and it's
> already in.  It's not the name GOTO that makes it a goto.  You can call it 
> banana if you want, it's having labels as targets.
> 
> So we aren't voting on GOTO; we're just calling it EXIT.
> 
> This explains my abstain vote to me.  I actually wondered why I didn't
> vote no.  I guess it's just one of those things that you either get or
> you don't.  Please don't take that as a shot at those that use GOTO, I
> did for decades myself and understand why some might want to use it.
> 
> I guess I've just seen it abused way too often to ever use it myself.

It's astonishing you fear you will abuse it and not be able to undo it when you
notice you used a goto.
 
> "Science is the belief in the ignorance of experts." - Richard Feynman

And this is a scientific vote, right?........

Kat

new topic     » goto parent     » topic index » view message » categorize

22. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> Derek Parnell wrote:
> > 
> > Although v4.0 will not have "exit(x)" it does have "exit <label>" where
> > <label>
> > is the name given to a loop.
> 
> How I hate to mention this.  I really, really do hate to mention this.  But
> I
> am compelled to for the sake of truth.  Here we are voting on GOTO and it's
> already in.  It's not the name GOTO that makes it a goto.  You can call it 
> banana if you want, it's having labels as targets.
> 
> So we aren't voting on GOTO; we're just calling it EXIT.

Well, we have exit right now.  Should we take it out?  It's very limited
in its current implementation.  The new label capability solves a very real
problem, the only solution as of right now was to use flags and if statements
to get out of nested loops.

Your fear of labels seems almost pathological.  I can understand being afraid
of spaghetti code.  I can understand being against inclusion of goto.  I
really don't understand your apparent opposition to a *structured* goto
like exit.

Matt

new topic     » goto parent     » topic index » view message » categorize

23. Re: Conceptual problem solved by GOTO

Kat wrote:
> 
> It's astonishing you fear you will abuse it and not be able to undo it when
> you notice you used a goto.

No Kat, that is not it.  They do not slip into my code.  I do not even have
to think to not use them.  Loop, Branch and Sequence are all I will ever need.

It is not fear that motivates me.  Better to think of me as having a mind
warped by the church of L.B.S. (Loop, Branch and Sequence)   ...and warped it
is!

"I see unstructured code people..."
"...I see them everywhere..."
"...and they don't even know they are!" - sixth code sense.

"Labels are for bigots!"... "Isn't bigot a label?"... "So what's your point?"

new topic     » goto parent     » topic index » view message » categorize

24. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> Kat wrote:
> > 
> > It's astonishing you fear you will abuse it and not be able to undo it when
> > you notice you used a goto.
> 
> No Kat, that is not it.  They do not slip into my code.  I do not even have
> to think to not use them.  Loop, Branch and Sequence are all I will ever need.
> 
> It is not fear that motivates me.  Better to think of me as having a mind
> warped by the church of L.B.S. (Loop, Branch and Sequence)   ...and warped it
> is!

So you won't fear me and Jeremy using goto?

Kat

new topic     » goto parent     » topic index » view message » categorize

25. Re: Conceptual problem solved by GOTO

Matt Lewis wrote:
> Well, we have exit right now.  Should we take it out?

No.

> It's very limited in its current implementation.

Which is what structure code is, constrained for a reason.  I admit it is
not easy to accept that reason because much of it is based on intangibles.

> The new label capability solves a very real
> problem, the only solution as of right now was to use flags and if statements
> to get out of nested loops.

This only appears correct.  However, no matter how much code someone
refactors as a demonstration it seems an unshakable belief.

> Your fear of labels seems almost pathological.

I fear them not.  No phobia.  No pathology.  There is a principle involved.

> I can understand being afraid
> of spaghetti code.

Don't even fear that.  I use the Gordian Knot solution.

> I can understand being against inclusion of goto.

Being that it's an individual realization, the understanding probably
differs from person to person even among those that agree.

>  I
> really don't understand your apparent opposition to a *structured* goto
> like exit.

Exit is essential.  Look at my previous discussion of Loop...End Loop.  In
my view it is much to be preferred to a multitude of different structures.

It's difficult to impress fundamental principles on others when a
lifetime of experience molded my thinking.  People want to target labels
instead of being disciplined in using only structured code.  It is their
privilege.  In some circumstances it is unthinkable to not have the
equivalent of goto.  I can't imagine a machine language without it
(Although the forth processor they came up with in the early 80's might
be an example.)

Once you change EXIT from 'skip to the end' to 'skip to where ever' you
open pandora's box.  I don't fear it.  I believe there is a better way
and being a good neighbor wish to share it with others.  So I try to
make my case.  Perhaps I can or perhaps not.  Should I not try?

I'm not sure what more I can say.  Do I make any sense at all?

Again, I'm not telling others what to do.  I am trying to persuade.
I believe the result is better with structured code.  Others are
free to disagree.  I am not unmoved by the arguments for including
labels.  I don't think they are evil.  I know how they can be used.

Did I mention how much I like Euphoria and wouldn't waste my time
if I didn't?  If I fear anything, I fear losing the elegance that
was Euphoria.

Beauty in Euphoria is more than skin deep.  I don't want it to go
ugly to the bone!  But I'm just one guy, beholdin' with one eye.

Perhaps that's too harsh.  I can live with whatever.  If I ever find
my code needs a label I will shout it from the rooftops. YMMV.


"Science is the belief in the ignorance of experts." - Richard Feynman

new topic     » goto parent     » topic index » view message » categorize

26. Re: Conceptual problem solved by GOTO

Kat wrote:
> So you won't fear me and Jeremy using goto?

Not in the least.

new topic     » goto parent     » topic index » view message » categorize

27. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> Matt Lewis wrote:
>
> >  I
> > really don't understand your apparent opposition to a *structured* goto
> > like exit.
> 
> Exit is essential.  Look at my previous discussion of Loop...End Loop.  In
> my view it is much to be preferred to a multitude of different structures.
> 
> It's difficult to impress fundamental principles on others when a
> lifetime of experience molded my thinking.  People want to target labels
> instead of being disciplined in using only structured code.  It is their
> privilege.  In some circumstances it is unthinkable to not have the
> equivalent of goto.  I can't imagine a machine language without it
> (Although the forth processor they came up with in the early 80's might
> be an example.)
> 
> Once you change EXIT from 'skip to the end' to 'skip to where ever' you
> open pandora's box.  I don't fear it.  I believe there is a better way
> and being a good neighbor wish to share it with others.  So I try to
> make my case.  Perhaps I can or perhaps not.  Should I not try?
> 
> I'm not sure what more I can say.  Do I make any sense at all?

This does make sense to me.  I think we haven't been clear in explaining
what exit "label" does.  Here is an explanation:
while x < blah lable "x" do
    for i = 1 to 5 do
        if foo(x,i) then
            exit "x"
        end if
        -- do stuff
    end for
end while

exit "label" still goes to the end.  The question is, the end of which
loop?  The pre-4.0 exit only went to the end of the innermost loop.  The
post-4.0 exit allows the coder to specify which loop to exit.

Matt

new topic     » goto parent     » topic index » view message » categorize

28. Re: Conceptual problem solved by GOTO

Matt Lewis wrote:

> exit "label" still goes to the end.  The question is, the end of which
> loop?  The pre-4.0 exit only went to the end of the innermost loop.  The
> post-4.0 exit allows the coder to specify which loop to exit.

If the question were limited to...

  EXIT 'label'
vs.
  EXIT [number of levels]

It seems obvious to me that a label is much to be preferred to a count.


However, in both cases you are no longer strictly structured.  I would
say that EXIT when used to leave the innermost loop is structured.

SKIP (I find myself liking this better than NEXT or CONTINUE) to skip
to the end for another iteration is also structured IMHO.

If you have fallthru in a case structure EXIT to the end of the cases
is structured as well, although fallthru itself isn't.  I don't object
to it either way.  I believe fallthru adds a burden on the programmer
that isn't needed.

I would prefer that EXIT did one predictable thing only.  But that's just me.

See, I'm adaptable (in a rocks for brains kind of way blink


"Science is the belief in the ignorance of experts." - Richard Feynman

new topic     » goto parent     » topic index » view message » categorize

29. Re: Conceptual problem solved by GOTO

Derek Parnell wrote:
> 
> Andy Serpa wrote:
> > 
> >I do vote yes on "exit(x)" whereby x in an integer allowing you to break
> > out of x many nested loops, which avoids the use of flags, etc. 
> 
> Although v4.0 will not have "exit(x)" it does have "exit <label>" where
> <label>
> is the name given to a loop. For example:
> 
>     while conda label "A" do
>         --- stuff ---
>         while condb label "B" do
>             --- stuff
>             if condc then
>                 exit "A" -- Exits the loop called 'A'
>             end if
>             -- stuff --
>         end while
>         -- stuff --
>     end while
>  
> 
> >A "continue" or "skip" would also be nice for loops, allowing
> > you to jump ahead to the next iteration immediately.
> 
> Version 4.0 has a 'continue' statement now. It causes control to immediately
> continue with the next iteration. It also can have an optional label name. 
> 
> 
> There is also a 'retry' statement that causes control to immediately repeat
> the same iteration. This will be more useful when exception handling makes to
> Euphoria one day.
> 
I apologize I've missed all this stuff.  This explosion of conversation has
actually caused me to tune out because I'm no C coder and don't know what you
guys are talking about most of the time.

But those sound good -- I'll be looking forward to those changes.  [Now if only
I could get someone to take a look at memory usage problem I posted about a while
back on Windows since v3.0 and tell me why it hogs memory it is done using which
it does not in v2.5.  This causes problems for me.]

new topic     » goto parent     » topic index » view message » categorize

30. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> I keep seeing people make the same false claims about GOTO over and over.
> 
> The issue regarding GOTO vs. structured code IS NOT SPEED.  Yes, calling a
> routine to refactor code makes the refactored code slower... but you NEVER
> have to call a sub routine.  The tradeoff without using functions is SIZE
> not SPEED.  
> 
> I've identified some lines of .. some code here .. with (A) and (B)
> 
> Fernando Bauer wrote:
> > procedure proc1()
> > if cond1 then
> >    .. some code here ..
> >    if cond2 then
> >       .. some code here ..
> >       if cond3 then
> >          .. some code here ..
> >          goto OUT
> >       end if
> >       .. some code here .. (A)
> >    end if
> >    .. some code here .. (B)
> > end if
> > OUT:
> > .. some code here ..
> > end procedure
> 
> You will note in the following that line (B) is now inline in two places
> (more SIZE) but only executes once (same SPEED)  It should be exactly the
> same speed for the if to branch to the else rather than the end if.
> 
> procedure proc1()
> if cond1 then
>    .. some code here ..
>    if cond2 then
>       .. some code here ..
>       if cond3 then
>          .. some code here ..
>       else
>          .. some code here .. (A)
>          .. some code here .. (B)
>       end if
>    else
>       .. some code here .. (B)
>    end if
> end if
> .. some code here ..
> end procedure
> 
Thanks Ken for your implementation!  It solves the conceptual problem, however
it seems that it creates another problem: for each nested-if it can be necessary
to duplicate a block of code. And you have to maintain these blocks equal. So, it
seems to me that this implementation does not follow the "Don't Repeat Yourself"
principle.

[snipped]

Regards,
   Fernando

new topic     » goto parent     » topic index » view message » categorize

31. Re: Conceptual problem solved by GOTO

Fernando Bauer wrote:

> > procedure proc1()
> > if cond1 then
> >    .. some code here ..
> >    if cond2 then
> >       .. some code here ..
> >       if cond3 then
> >          .. some code here ..
> >       else
> >          .. some code here .. (A)
> >          .. some code here .. (B)
> >       end if
> >    else
> >       .. some code here .. (B)
> >    end if
> > end if
> > .. some code here ..
> > end procedure
> > 
> Thanks Ken for your implementation!  It solves the conceptual problem, however
> it seems that it creates another problem: for each nested-if it can be
> necessary
> to duplicate a block of code. And you have to maintain these blocks equal. So,
> it seems to me that this implementation does not follow the "Don't Repeat
> Yourself"
> principle.

Your welcome Fernando, and you are correct.  Thou shall not duplicate code
which is why I'd definitely put all the line (B) code into a subroutine.

It doesn't really matter how deep your nesting goes.  Just put it all into
a single routine.  Then, instead of exit to a label you simply return from
the routine.  If for some reason you have multiple many nested loops you
factor them into more routines.  No trouble.  BTW, did we just describe the
mother of all spaghetti?  Realistically, there is never a problem and
choosing good routine names makes it all pretty much self documenting.

Loop1
TOP:
  Loop2
    Loop...
      Loop9999
        go TOP
      End   
    End
  End
End

Becomes...

procedure routine1()
  Loop2
    Loop...
      Loop9999
        return
      End   
    End
  End
end proc

Loop1
  routine1
End

new topic     » goto parent     » topic index » view message » categorize

32. Re: Conceptual problem solved by GOTO

ken mortenson wrote:
> 
> Fernando Bauer wrote:
> 
> > > procedure proc1()
> > > if cond1 then
> > >    .. some code here ..
> > >    if cond2 then
> > >       .. some code here ..
> > >       if cond3 then
> > >          .. some code here ..
> > >       else
> > >          .. some code here .. (A)
> > >          .. some code here .. (B)
> > >       end if
> > >    else
> > >       .. some code here .. (B)
> > >    end if
> > > end if
> > > .. some code here ..
> > > end procedure
> > > 
> > Thanks Ken for your implementation!  It solves the conceptual problem,
> > however
> > it seems that it creates another problem: for each nested-if it can be
> > necessary
> > to duplicate a block of code. And you have to maintain these blocks equal.
> > So,
> > it seems to me that this implementation does not follow the "Don't Repeat
> > Yourself"
> > principle.
> 
> Your welcome Fernando, and you are correct.  Thou shall not duplicate code
> which is why I'd definitely put all the line (B) code into a subroutine.
> 
> It doesn't really matter how deep your nesting goes.  Just put it all into
> a single routine.  Then, instead of exit to a label you simply return from
> the routine.  If for some reason you have multiple many nested loops you
> factor them into more routines.  No trouble.  BTW, did we just describe the
> mother of all spaghetti?  Realistically, there is never a problem and
> choosing good routine names makes it all pretty much self documenting.
> 
> Loop1
> TOP:
>   Loop2
>     Loop...
>       Loop9999
>         go TOP
>       End   
>     End
>   End
> End
> 
> Becomes...
> 
> procedure routine1()
>   Loop2
>     Loop...
>       Loop9999
>         return
>       End   
>     End
>   End
> end proc
> 
> Loop1
>   routine1
> End

This is nice in top level code.
But when the loops handle private variables, you have to pass these around and
possibly update them, going against any speed or bug safety common sense. Nested
routines might alleviate the problem though.

CChris

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu