Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32302
| References | <a533d812-480e-479b-9210-7097c2d70d73@a4g2000pbo.googlegroups.com> <mailman.2934.1351343030.27098.python-list@python.org> <508c810f$0$29967$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| From | Devin Jeanpierre <jeanpierreda@gmail.com> |
| Date | 2012-10-28 01:57 -0400 |
| Subject | Re: attaching names to subexpressions |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2950.1351403908.27098.python-list@python.org> (permalink) |
On Sat, Oct 27, 2012 at 8:49 PM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > On Sat, 27 Oct 2012 15:03:38 +0200, Gelonida N wrote: > >> line = complex_exression >> while line: >> do something with(line) >> line = complex_expression >> >> violates clearly the DRY principle and the risk to change one line but >> not the other is high. -- snip -- > while True: > line = function(x, y, z) > if not line: > break > big ugly block of code > > > There you go. DRY. >> The 'canonical way' >> while True: >> line = complex_expression >> if not line: >> break >> do_something_with(line) >> >> avoids this problem, but I was never really convinced about the beauty / >> readbility of this construct. >> >> In >> my opinion I shouldn't be obliged to read any of the indented lines of >> the while statement on a first 'visual' pass through somebody elses code >> and still be able to see what the loop iterates through. > > Fine. Then write your code as: > > line = function(x, y, z) > while line: > do something with(line) > line = function(x, y, z) > We have a problem, and two solutions. Solution 1 has downside A, and solution 2 has downside B. If he complains about downside A, you say, well, use solution 2. If he complains about downside B, you say, well, use solution 1. What if he wants to avoid both downsides A and B? What solution does he use then? -- Devin
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
attaching names to subexpressions Steve Howell <showell30@yahoo.com> - 2012-10-26 19:42 -0700
Re: attaching names to subexpressions Gelonida N <gelonida@gmail.com> - 2012-10-27 15:03 +0200
Re: attaching names to subexpressions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-28 00:49 +0000
Re: attaching names to subexpressions rusi <rustompmody@gmail.com> - 2012-10-27 18:57 -0700
Re: attaching names to subexpressions Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-28 01:57 -0400
Re: attaching names to subexpressions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-28 06:59 +0000
Re: attaching names to subexpressions Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-28 04:12 -0400
Re: attaching names to subexpressions Neil Cerutti <neilc@norwich.edu> - 2012-10-29 11:53 +0000
Re: attaching names to subexpressions Chris Angelico <rosuav@gmail.com> - 2012-10-28 17:01 +1100
Re: attaching names to subexpressions "F.R." <anthra.norell@bluewin.ch> - 2012-10-28 08:12 +0100
Re: attaching names to subexpressions Chris Angelico <rosuav@gmail.com> - 2012-10-28 21:44 +1100
csiph-web