how to avoid checking the same condition repeatedly ?

rusi rustompmody at gmail.com
Tue Oct 29 12:13:21 EDT 2013


On Tuesday, October 29, 2013 7:14:51 PM UTC+5:30, Neil Cerutti wrote:
> On 2013-10-28, Nobody  wrote:
> > If you're sufficiently concerned about performance that you're
> > willing to trade clarity for it, you shouldn't be using Python
> > in the first place.
> 
> 
> When you detect a code small, as Wolfgang did, e.g., "I'm
> repeating the same exact test condition in several places," you
> should not simply ignore it, even in Python.

Yes
It is an agenda of functional programming that such programs should be modularly writeable without loss of performance:
http://homepages.inf.ed.ac.uk/wadler/topics/deforestation.html
[the trees there include lists]

Unfortunately for the imperative programmer, some forms of modularization are 
simply not conceivable that are natural for functional programmers (or as 
Steven noted shell-script writers). eg The loop:

while pred:
  statement
is simply one unit and cannot be split further.

Whereas in a FPL one can write:
iterate statement  >>>  takeWhile pred
-- the >>> being analogous to | in bash



More information about the Python-list mailing list