Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21826
| Date | 2012-03-17 18:55 +0100 |
|---|---|
| From | Kiuhnm <kiuhnm03.4t.yahoo.it> |
| Newsgroups | comp.lang.python |
| Subject | Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct |
| References | <gR09r.22645$I33.16090@uutiset.elisa.fi> <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <mailman.758.1331996530.3037.python-list@python.org> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <mailman.759.1331999612.3037.python-list@python.org> |
| Message-ID | <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> (permalink) |
| Organization | TIN.IT (http://www.tin.it) |
On 3/17/2012 16:53, Michael Torrie wrote:
> On 03/17/2012 09:12 AM, Kiuhnm wrote:
>> On 3/17/2012 16:01, Michael Torrie wrote:
>>> On 03/17/2012 08:45 AM, Kiuhnm wrote:
>>>> Your way is easy, but the result is poor.
>>>
>>> In what way?
>>
>> The resulting code is inefficient, difficult to comprehend and to mantain.
>>
>>> What is your recommended way?
>>
>> One should rewrite the code. There is a reason why Python doesn't have
>> gotos.
>
> We appear to have a language barrier here. How should one rewrite the
> code? Everyone knows python doesn't have gotos and state machines have
> to be created using other mechanisms like loops, state variables, and
> such. Your suggestion to "rewrite the code" is unhelpful to the OP if
> you're not willing to suggest the best method for doing so.
Why should I write a treatise on decompilation techniques on this ng?
> Saying, "be
> like a decompiler" doesn't say anything.
That looks like a glaring contradiction to me...
I'm sure the interested reader will think of some ways of getting additional information on the subject.
Here's an example of rewriting:
A1. (Do the work of Phase A1.) If <zap> then go to Phase A5,
otherwise continue.
A2. (Do some work.) If <zorp> go to Phase A4.
A3. (Some more work.)
A4. (Do something.) If <condition ZZZ> go to Phase A1.
A5. (Something more). If <foobar> then go to Phase A2, otherwise
end.
==>
A1. (Do the work of Phase A1.)
If not <zap>:
A2. (Do some work.) If <zorp> go to Phase A4.
A3. (Some more work.)
A4. (Do something.) If <condition ZZZ> go to Phase A1.
A5. (Something more). If <foobar> then go to Phase A2, otherwise
end.
==>
A1. (Do the work of Phase A1.)
If not <zap>:
A2. (Do some work.)
If not <zorp>:
A3. (Some more work.)
A4. (Do something.) If <condition ZZZ> go to Phase A1.
A5. (Something more). If <foobar> then go to Phase A2, otherwise
end.
==>
while (True):
A1. (Do the work of Phase A1.)
If not <zap>:
A2. (Do some work.)
If not <zorp>:
A3. (Some more work.)
A4. (Do something.)
If not <condition ZZZ>:
break
A5. (Something more). If <foobar> then go to Phase A2
==>
while (True):
A1. (Do the work of Phase A1.)
If not <zap>:
A2. (Do some work.)
If not <zorp>:
A3. (Some more work.)
A4. (Do something.)
If not <condition ZZZ>:
A5. (Something more).
If <foobar> then go to Phase A2
break
==>
again = TRUE
while (again):
A1. (Do the work of Phase A1.)
If not <zap>:
while (True):
A2. (Do some work.)
If not <zorp>:
A3. (Some more work.)
A4. (Do something.)
If not <condition ZZZ>:
A5. (Something more).
If <foobar>:
continue
again = FALSE; break
==>
def f:
while (True):
A1. (Do the work of Phase A1.)
If not <zap>:
while (True):
A2. (Do some work.)
If not <zorp>:
A3. (Some more work.)
A4. (Do something.)
If not <condition ZZZ>:
A5. (Something more).
If <foobar>:
continue
return
==>
def f:
while (True):
A1. (Do the work of Phase A1.)
If <zap>:
continue
while (True):
A2. (Do some work.)
If not <zorp>:
A3. (Some more work.)
A4. (Do something.)
If not <condition ZZZ>:
A5. (Something more).
If <foobar>:
continue
return
==>
def f:
while (True):
A1. (Do the work of Phase A1.)
If <zap>:
continue
while (True):
A2. (Do some work.)
If not <zorp>:
A3. (Some more work.)
A4. (Do something.)
If <condition ZZZ>:
continue
A5. (Something more).
If <foobar>:
continue
return
==>
def f:
while (True):
A1. (Do the work of Phase A1.)
If <zap>:
continue
while (True):
A2. (Do some work.)
If not <zorp>:
A3. (Some more work.)
A4. (Do something.)
If <condition ZZZ>:
continue
A5. (Something more).
If not <foobar>:
return
Etc... until you're satisfied with the result.
If the code is more complex, divide et impera.
Kiuhnm
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-03-17 16:03 +0200
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Mel Wilson <mwilson@the-wire.com> - 2012-03-17 10:39 -0400
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-17 15:45 +0100
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Michael Torrie <torriem@gmail.com> - 2012-03-17 09:01 -0600
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-17 16:12 +0100
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Michael Torrie <torriem@gmail.com> - 2012-03-17 09:53 -0600
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-17 18:55 +0100
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Michael Torrie <torriem@gmail.com> - 2012-03-17 17:28 -0600
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-18 01:54 +0000
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-18 11:03 +0000
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-19 02:02 +0100
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-03-19 01:02 -0400
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-19 11:24 +0100
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Roy Smith <roy@panix.com> - 2012-03-17 11:47 -0400
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-03-17 18:31 +0200
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct John Nagle <nagle@animats.com> - 2012-03-17 11:44 -0700
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Evan Driscoll <driscoll@cs.wisc.edu> - 2012-03-17 21:59 -0500
Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-18 11:08 +0000
csiph-web