Should I use "if" or "try" (as a matter of speed)?

John Roth newsgroups at jhrothjr.com
Sun Jul 10 08:07:31 EDT 2005


"Thomas Lotze" <thomas at thomas-lotze.de> wrote in message 
news:pan.2005.07.10.07.24.19.715644 at ID-174572.user.uni-berlin.de...
> Steven D'Aprano wrote:
>
>
> Basically, I agree with the "make it run, make it right, make it fast"
> attitude. However, FWIW, I sometimes can't resist optimizing routines that
> probably don't strictly need it. Not only does the resulting code run
> faster, but it is usually also shorter and more readable and expressive.
> Plus, I tend to gain further insight into the problem and tools in the
> process. YMMV, of course.

Shorter, more readable and expressive are laudable goals in and
of themselves. Most of the "advice" on optimization assumes that
after optimization, routines will be less readable and expressive,
not more.

In other words, I wouldn't call the activity of making a routine
more readable and expressive of intent "optimization." If it runs
faster, that's a bonus. It frequently will, at least if you don't add
method calls to the process.

John Roth
>
> -- 
> Thomas
> 




More information about the Python-list mailing list