April 30, 2006
Walter Bright wrote:
> Rick C. Hodgin wrote:
>> int i;
>> for (i=0; i<10; i++)
>> {
>>     if (string.substr(i,1) == something)
>>     {
>>         i += some_other_function();
>>         retry;
>>     }
>>     else if (string.substr(i,1) == something_else)
>>     {
>>         i += some_other_function2();
>>         retry;
>>     }
>>     // Otherwise, simply execute the "i++" and re-test
>> }
> 
> I know goto's are evil, but I tend to write such as:
> 
> int i;
> for (i=0; i<10; i++)
> {
>   Lretry:
>     if (string.substr(i,1) == something)
>     {
>         i += some_other_function();
>         goto Lretry;
>     }
>     else if (string.substr(i,1) == something_else)
>     {
>         i += some_other_function2();
>         goto Lretry;
>     }
>     // Otherwise, simply execute the "i++" and re-test
> }

That wouldn't be the same, since for what they said, "retry" should re-test the condition (i<10), not just re-execute the block.

-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
April 30, 2006
Unknown W. Brackets wrote:
> [snip]
> 
> int pos = 0;
> while (pos < string.length)
> {
>     switch (string[pos])
>     {
>     case something:
>         pos += some_other_function(string[pos .. string.length]);
>         break;
> 
>     case something_else:
>         pos += some_other_function2(string[pos .. string.length]);
>         break;
> 
>     default:
>         pos++;
>     }
> }
> 

Does anyone else see the inconsistency with the break and continue keywords as applied to switch statements within loop constructs?

switch uses break to leave the switch statement, while continue is still used in the loop context.  I think this should be fixed so that exit leaves the switch statement and break and continue are left for the loop.

-- 
Regards,
James Dunne
April 30, 2006
Bruno Medeiros wrote:
> 
> I was thinking of an example which used continues and retries in the same for, as yours can be cleanly rewritten as the example in my later post.
> Anyway, Derek's example serves as a good example of the keyword's usage, but for "foreach", for "for" I'm still finding it a bit odd.

I think it's more useful for "foreach" because there's no way to avoid progressing with each iteration.  However, goto still works here as in Walter's example.  "retry" is handy, but it's more a convenience than anything.


Sean
April 30, 2006
Thanks Derek,

I see your point, I was just sort of going off of Kyle's quote "and the functionality is clearly the same" without realising he meant the overall functionality, and not the keywords (oops). I was also looking at the while loop example code and it seemed that the two would be the same (just for that construct though, I see). However, since we can just write the code with a different construct and/or 'goto's, then should we use extra keywords and make the language even bigger? Maybe you are suggesting that it would be easier to just let the compiler add in the correct jumps instead of making the user add in explicit 'goto's and possibly use a different construct?

I think the new keyword (or words if we include 'restart' as well) may lead to some nasty little logic bugs for new users, if they aren't careful, though. I know that can be said about many 'new' keywords/features for newer languages, but still, in this case it may be troublesome for those moving from C/C++. Maybe? Thoughts?

Thanks,
Kelly Wilson

P.S. Your example does rather pointedly show that this can all be solved easily
with some 'goto's as Walter showed/suggested earlier ;) One argument for goto's
follows:  http://www.ppig.org/papers/12th-marshall.pdf
or here:  http://www.stevemcconnell.com/ccgoto.htm


In article <op.s8tl32d56b8z09@ginger.vic.bigpond.net.au>, Derek Parnell says...
>
>On Sun, 30 Apr 2006 20:34:09 +1000, <kellywilson@nowhere.com> wrote:
>
>
>> Anyways, easy to add keyword, but in the same place as "continue", so why do it?
>
>Because 'continue' and 'retry' are not the same thing. 'continue' means go to the next iteration, and 'retry' means repeat the same iteration.
>
>....CONCEPTUAL CODE....
>
>    for_start:
>        init_code;
>    for_test:
>        if ( end_condition ) goto for_end;
>    for_body:
>        do_something;
>        if <A> goto for_index; // continue
>        if <B> goto for_test; // retry
>        if <C> goto for_start; // restart
>        if <D> goto for_end; // break;
>    for_index:
>        update_index;
>        goto for_test;
>    for_end:
>
>
>-- 
>Derek Parnell
>Melbourne, Australia


April 30, 2006
I think this is why labeling for these constructs was introduced.

-[Unknown]


> Does anyone else see the inconsistency with the break and continue keywords as applied to switch statements within loop constructs?
> 
> switch uses break to leave the switch statement, while continue is still used in the loop context.  I think this should be fixed so that exit leaves the switch statement and break and continue are left for the loop.
> 
April 30, 2006
At the risk of asking a stupid question, what is wrong with gotos?

I realize they can result in code that people with insufficient programming experience might not understand (and I'm not trying to be arrogant here, because I avoid using gotos for exactly and only this reason, I don't use or read them enough.)

But that doesn't seem reason enough for everyone to hate them.  If I see a need for one, I use it - and I add comments to make sure no one gets confused.

Is the only reason that people fear them, or is there a real legitimate reason?

-[Unknown]


> How about we all try to avoid GOTOs and you implement this keyword? :P
> 
> Regards,
> Alexander Panek
April 30, 2006
On Mon, 01 May 2006 05:18:11 +1000, Sean Kelly <sean@f4.ca> wrote:

> Bruno Medeiros wrote:
>>  I was thinking of an example which used continues and retries in the same for, as yours can be cleanly rewritten as the example in my later post.
>> Anyway, Derek's example serves as a good example of the keyword's usage, but for "foreach", for "for" I'm still finding it a bit odd.
>
> I think it's more useful for "foreach" because there's no way to avoid progressing with each iteration.  However, goto still works here as in Walter's example.  "retry" is handy, but it's more a convenience than anything.

And *expressive*. That is, it signals the coder's intent more clearly than a goto can because in theory the goto can go to anywhere but that is not the case with 'retry'. Thus the use of 'retry' is more likely to lead to less misunderstanding and bugs. So even though it is a 'goto' in disguise, it is a controlled goto.



-- 
Derek Parnell
Melbourne, Australia
April 30, 2006
Unknown W. Brackets wrote:
> At the risk of asking a stupid question, what is wrong with gotos?
> 
> I realize they can result in code that people with insufficient programming experience might not understand (and I'm not trying to be arrogant here, because I avoid using gotos for exactly and only this reason, I don't use or read them enough.)
> 
> But that doesn't seem reason enough for everyone to hate them.  If I see a need for one, I use it - and I add comments to make sure no one gets confused.
> 
> Is the only reason that people fear them, or is there a real legitimate reason?
> 
> -[Unknown]
> 
> 
>> How about we all try to avoid GOTOs and you implement this keyword? :P
>>
>> Regards,
>> Alexander Panek

I *do* understand them, and I also do know, that they are useful and whatnot. Still, I don't like them - they are a relict of early C times. But now we've got neat, mighty conditional loops - what do we need GOTOs for?

A friend of mine once wrote such code:

<code>
label:
doSomething( );

if ( condition )
	goto label;
</code>

That *is* a do-while loop.

<code>
do {
	doSomething( );
} while ( condition )
</code>

Effectively, those two construct are the same, but the second one is, IMO, far better readable (readable as in recognization of what a program is doing).

Regards,
Alexander Panek
April 30, 2006
On Mon, 01 May 2006 05:28:17 +1000, <kellywilson@nowhere.com> wrote:


> However, since we can just write the code with a
> different construct and/or 'goto's, then should we use extra keywords and make
> the language even bigger?

If one takes this argument, we should remove constructs such as 'for', 'foreach', 'switch', 'while' etc...

> Maybe you are suggesting that it would be easier to
> just let the compiler add in the correct jumps instead of making the user add in
> explicit 'goto's and possibly use a different construct?

Yes. Source code is supposed to be primarily designed for humans to read and thus we need to help humans understand the intent of the code and leave the compiler to correctly translate it for the machines.

>
> I think the new keyword (or words if we include 'restart' as well) may lead to
> some nasty little logic bugs for new users, if they aren't careful, though. I
> know that can be said about many 'new' keywords/features for newer languages,
> but still, in this case it may be troublesome for those moving from C/C++.
> Maybe? Thoughts?

So what! Let them learn D instead.

> P.S. Your example does rather pointedly show that this can all be solved easily
> with some 'goto's as Walter showed/suggested earlier ;) One argument for goto's
> follows:  http://www.ppig.org/papers/12th-marshall.pdf
> or here:  http://www.stevemcconnell.com/ccgoto.htm

My take on goto is that its usage is justified when there is no other way to add performace to a demonstably performance critical section of code. In other words, the 'cost' of using goto must be offset by some other gain.

-- 
Derek Parnell
Melbourne, Australia
April 30, 2006
On Mon, 01 May 2006 06:08:53 +1000, Unknown W. Brackets <unknown@simplemachines.org> wrote:

> At the risk of asking a stupid question, what is wrong with gotos?
>
> I realize they can result in code that people with insufficient programming experience might not understand (and I'm not trying to be arrogant here, because I avoid using gotos for exactly and only this reason, I don't use or read them enough.)
>
> But that doesn't seem reason enough for everyone to hate them.  If I see a need for one, I use it - and I add comments to make sure no one gets confused.
>
> Is the only reason that people fear them, or is there a real legitimate reason?

The use of 'goto' has an inherinent cost in terms of ongoing maintenance of code. In short, it adds to the time it takes to analyse code prior to making changes that do not have unintended side-effects. That cost must be justifed. Therefore one should only use 'goto' in situation in which the cost of its use can be offset by some other gain in the code. Such a gain is performance in a performace-critical section of code. I'm not sure if there are any other situations it is cost-justified.

-- 
Derek Parnell
Melbourne, Australia