Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37507
| From | John Gordon <gordon@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Arent these snippets equivalent? |
| Date | 2013-01-23 22:06 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <kdpmsv$ec6$1@reader1.panix.com> (permalink) |
| References | <d7191cec-d963-42c8-90ba-db6d1359ceeb@googlegroups.com> |
In <d7191cec-d963-42c8-90ba-db6d1359ceeb@googlegroups.com> Coolgg <gauravj123@gmail.com> writes:
> Is this:
> while True:
> data = fp.read(4096)
> if not data:
> break
> ...
> not equivalent to this:
> data = fp.read (4096)
> while data:
> ...{handle the chunk here}
> data = fp.read (4096)
It looks equivalent to me (in terms of control flow).
But in the second example the fp.read() statement is duplicated, which is
undesirable. It would be all too easy for a maintenance programmer to go
into the code a year from now and change the first one but miss the second
one.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Arent these snippets equivalent? Coolgg <gauravj123@gmail.com> - 2013-01-23 13:56 -0800
Re: Arent these snippets equivalent? John Gordon <gordon@panix.com> - 2013-01-23 22:06 +0000
Re: Arent these snippets equivalent? Chris Angelico <rosuav@gmail.com> - 2013-01-24 09:13 +1100
Re: Arent these snippets equivalent? Roy Smith <roy@panix.com> - 2013-01-23 17:47 -0500
Re: Arent these snippets equivalent? Tim Chase <python.list@tim.thechases.com> - 2013-01-23 17:29 -0600
Re: Arent these snippets equivalent? Chris Angelico <rosuav@gmail.com> - 2013-01-24 10:29 +1100
Re: Arent these snippets equivalent? Terry Reedy <tjreedy@udel.edu> - 2013-01-23 21:38 -0500
Re: Arent these snippets equivalent? Coolgg <gauravj123@gmail.com> - 2013-01-23 21:01 -0800
Re: Arent these snippets equivalent? Coolgg <gauravj123@gmail.com> - 2013-01-23 21:01 -0800
Re: Arent these snippets equivalent? Evan Driscoll <driscoll@cs.wisc.edu> - 2013-01-23 17:17 -0600
csiph-web