while (a=b()) ...

Michael P. Reilly arcege at shore.net
Mon May 10 15:49:12 EDT 1999


scott cotton <scott at chronis.pobox.com> wrote:
: On Mon, 10 May 1999 14:30:52 GMT, Andrew Csillag <andrew at starmedia.net> wrote:
: [..]
:>Is this so bad?
:>
:>c=curs.fetchone()
:>while c:
:>    do something with c
:>    c=curs.fetchone()
:>
:>Is it a little redundant? Yes.  Error prone?  No.

: Error prone it is - by virtue of being redundant. changes to
: the loop may require changing two code lines, and it's easy
: to forget to update redundant code.

It is less error prone than adding commonly mistyped (within the
industry) syntax which isn't necessary to the language.

The idiom that Andrew shows is common enough within Python (for many
years) that many people expect it (or it's "break" sibling idiom).. and
so will know to look for it.  Not only that but it is common in some
circles of C programming (and other languages).

Face it folks: if you want the functionality, make it.  This debate has
born much fruit (and many of us nuts) on how to do this efficiently and
effectively within the existing syntax.

Guido wisely decided a long time ago that assignments in expressions
were bad and gave us the tools to get around it.  Unless someone can
make a _real_ case for previously declared (and maybe even proven) bad
syntax, let it rest.

And now for something not so different...

: while (c=curs.fetchone(); c):

: is not redundant, nor does it have the '=' != '==' problem.

How so?  Expressions are statements, so in your syntax
  while (c==curs.fetchone(); c):
is valid and probably incorrect (in this application of the syntax).

\begin{sarcasm}
Maybe we should make everything an assignment statement or begin with a
reserved word?\end{sarcasm}

  -Arcege





More information about the Python-list mailing list