Movatterモバイル変換


[0]ホーム

URL:


do...until wisdom needed...

Andrew Dalkedalke at acm.org
Mon Apr 16 13:43:10 EDT 2001


Ken Peek wrote:>I am writing my own language based on Python for deeply embedded systems.I>am not trying to change the Python language.  I would like all of the>traditional looping constructs in my new language, and so was trying to get>your opinion as to the best way to implement a "do...until" construct  ...>So, now that you know that I really am asking what I said I was asking,>how about answering my original question?Your original question:> If Python WERE to have a "do...until" construct, what> would be the best way to implement the syntactical rules?These two questions aren't the same.  Your original one refers toPython, which means amoung other things a viewpoint that a minimalnumber of contructs - but not the absolute minimum because thereare practical reasons for non-orthogonality - is appropriate.In my C code (I've written order(100KLOCs) of production code)I use "do" about once a year.  Every time I use it I need to pullout K&R or grep existing code because I've forgotten the syntax.The pythonic view is that this construct saves at most two lineswhich does not justify the effort of having to remember howa do..until is used.BTW, in my C code I now use while(1) { code; if (cond) break;}I pulled out K&R 2nd edition, section 3.6 pp63-64 talks aboutC's Do-while loop.  It says:] Experience shows that do-while is much less used than while] and for.  Nonetheless, from time to time it is valuable, as] in the following function itoa ...The atoi code could be rewritten to use a while with overalltwo more lines of code.  If you agree that do..while is used5% of the time while is used, and while construct syntax takesup less than 1% of working code, then there is a 0.1% increasein code size at the expense of understanding.That's one fundamental reason why do..until is not Pythonic.The other one is that no one could think of a nice way todo the indentation given that it requires two control statements,and all control statements in Python are dedented, end with a :and have code following the statement.  The "until" clausebreaks one of those, unless you always follow it with a dummy"pass" statement.Now to your real question:> I would like all of the traditional looping constructs in> my new language, and so was trying to get your opinion as to> the best way to implement a "do...until" construct.By all means, usedo:  codeuntil conditionThat's not Pythonic and won't be added to Python, but youaren't talking Python.  Although I would suggest using 'while'because of the parallel with C and because it saves a keyword.                    Andrewdalke at acm.org


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp