Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!news.panservice.it!feeder.news.tin.it!spool.news.tin.it!not-for-mail Date: Sat, 17 Mar 2012 18:55:14 +0100 From: Kiuhnm User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.python Subject: Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Lines: 181 Message-ID: <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> Organization: TIN.IT (http://www.tin.it) X-Comments: Please send technical notifications to newsmaster@tin.it NNTP-Posting-Host: 80.181.194.128 X-Trace: 1332006922 reader1.news.tin.it 1390 80.181.194.128:10765 X-Complaints-To: Please send abuse reports to abuse@retail.telecomitalia.it Xref: csiph.com comp.lang.python:21826 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 then go to Phase A5, otherwise continue. A2. (Do some work.) If go to Phase A4. A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. ==> A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If go to Phase A4. A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. ==> A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. ==> while (True): A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : break A5. (Something more). If then go to Phase A2 ==> while (True): A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If then go to Phase A2 break ==> again = TRUE while (again): A1. (Do the work of Phase A1.) If not : while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If : continue again = FALSE; break ==> def f: while (True): A1. (Do the work of Phase A1.) If not : while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If : continue return ==> def f: while (True): A1. (Do the work of Phase A1.) If : continue while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If : continue return ==> def f: while (True): A1. (Do the work of Phase A1.) If : continue while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If : continue A5. (Something more). If : continue return ==> def f: while (True): A1. (Do the work of Phase A1.) If : continue while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If : continue A5. (Something more). If not : return Etc... until you're satisfied with the result. If the code is more complex, divide et impera. Kiuhnm