goto

S

Steven D'Aprano

1 GOTO 17
2 mean, GOTO 5
3 could GOTO 6

[snip]

That's great, but not a patch on the power of COMEFROM!

Or, to put it another way:

1
2 readability COMEFROM 4
3 that's COMEFROM 6
4 hurt COMEFROM 7
5 to COMEFROM 10
6 but COMEFROM 2
7 might COMEFROM 9
8 nothing COMEFROM 3
9 goto COMEFROM 12
10 compared COMEFROM 8
11 comefrom COMEFROM 5
12 using COMEFROM 1
 
G

George Sakkis

rbt said:
Shouldn't that be "to the horror of all your goto-snob friends."

IMO, most of the people who deride goto do so because they heard or read
where someone else did.

Many of the world's most profitable software companies (MS for example)
have thousands of goto statements in their code... oh the horror of it
all. Why aren't these enlightened-by-the-gods know-it-alls as profitable
as these obviously ignorant companies?


It should not really come as a shock that the same fellow who came up with a brilliant efficient way
to generate all permutations (http://tinyurl.com/dnazs) is also in favor of goto.

Coming next from rbt: "Pointer arithmetic in python ?".

George
 
R

rbt

It should not really come as a shock that the same fellow who came up with a brilliant efficient way
to generate all permutations (http://tinyurl.com/dnazs) is also in favor of goto.

Coming next from rbt: "Pointer arithmetic in python ?".

George

I have moments of brilliance and moments of ignorance. You must admit
though, that was a unique way of generating permutations... how many
other people would have thought of that approach? It did solve my
problem ;)
 
R

rbt

Sorry rbt, but your algorithm isn't unique, nor was it clever, and in fact
your implementation wasn't very good even by the undemanding requirements
of the algorithm. It is just a minor modification of bogosort (also known
as "bozo-sort") algorithm:

http://en.wikipedia.org/wiki/Bogosort

I quote:

"...bogosort is 'the archetypal perversely awful algorithm', one example
of which is attempting to sort a deck of cards by repeatedly throwing the
deck in the air, picking the cards up at random, and then testing whether
the cards are in sorted order."

Bogosort is nothing to be proud of, except as a joke.

It *was* a joke.
 
S

Steven D'Aprano

I have moments of brilliance and moments of ignorance. You must admit
though, that was a unique way of generating permutations... how many
other people would have thought of that approach? It did solve my
problem ;)

Sorry rbt, but your algorithm isn't unique, nor was it clever, and in fact
your implementation wasn't very good even by the undemanding requirements
of the algorithm. It is just a minor modification of bogosort (also known
as "bozo-sort") algorithm:

http://en.wikipedia.org/wiki/Bogosort

I quote:

"...bogosort is 'the archetypal perversely awful algorithm', one example
of which is attempting to sort a deck of cards by repeatedly throwing the
deck in the air, picking the cards up at random, and then testing whether
the cards are in sorted order."

Bogosort is nothing to be proud of, except as a joke. Put it this way: of
all the many ways to generate a list of permutations, you managed to find
perhaps the least efficient algorithm possible.

This is especially ironic when you think back to your first question,
which was how to generate the combinations most efficiently.
 
F

Fernando Perez

Steven said:
Yeah, it's pretty slick. I think most people who see the link don't
realize that it's actually *working code* for gotos in Python.

For a second I didn't think it was, but the page looked too serious to be just
a mockup (regardless of the April's fool warning at the top). So I actually
donwloaded the code to see how he did it, because it wasn't quite obvious to
me after the standard 3 seconds of thought. It was quite fun the read how he
got it to work.

Cheers,

f
 
M

Mike Meyer

Rocco Moretti said:
I dislike gotos because it is too easy to inadvertently create
infinite loops. <10 WINK; 20 GOTO 10>

And it's impossible without them? <while True: pass>

<mike
 
S

Sybren Stuvel

Mike Meyer enlightened us with:
And it's impossible without them? <while True: pass>

I thought the same thing, but then I read it again and thought about
the "inadvertently". As soon as you see a "while True", you _know_
it's going to loop forever. As soon as you see a "goto 10", you don't.

Sybren
 
P

Peter Hansen

Sybren said:
Mike Meyer enlightened us with:



I thought the same thing, but then I read it again and thought about
the "inadvertently". As soon as you see a "while True", you _know_
it's going to loop forever.

Unless it doesn't, of course:

while True:
break
 
M

Mike Meyer

Peter Hansen said:
Unless it doesn't, of course:

while True:
break

My "favorite" infinte loop with while is:

i = 0
while i < 20:
do_process(i)

Note the prominent *lack* of any change to i here?

Oh, for:

from i = 0
invariant 0 <= i <= 20
variant 21 - i
until i > 19
loop
do_process(i)

which throws an exception at the beginning of the second loop.

<mike
 
R

Rocco Moretti

My "favorite" infinte loop with while is:

i = 0
while i < 20:
do_process(i)

Note the prominent *lack* of any change to i here?

Oh, for:

from i = 0
invariant 0 <= i <= 20
variant 21 - i
until i > 19
loop
do_process(i)

which throws an exception at the beginning of the second loop.

What language is that from?

I take it the exception is from the "21-i" not changing as it goes
around the loop, right? (But why can't "variant i" work just as well?)
 
M

Mike Meyer

Rocco Moretti said:
What language is that from?
Eiffel.

I take it the exception is from the "21-i" not changing as it goes
around the loop, right? (But why can't "variant i" work just as well?)

Because that's the way variant is defined. You actually want the
variant to move in a specific direction, so that you don't wind up
incrementing it when you should be decrementing it. Eiffel chose down,
so you you need -i at the very least. It also insists that the
invariant be positive. I'm not sure why; it makes the variant more
complicated, resulting in exceptions from bugs in the variant as well
as bugs in the loop.

<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top