[Patches] [ python-Patches-1191489 ] Simplify logic in random.py

SourceForge.net noreply at sourceforge.net
Fri Apr 29 08:12:48 CEST 2005


Patches item #1191489, was opened at 2005-04-28 00:31
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1191489&group_id=5470

Category: Library (Lib)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
>Assigned to: Nobody/Anonymous (nobody)
Summary: Simplify logic in random.py

Initial Comment:
Simplify the logic in several methods for better
readability, maintainability, and speed:

* while True --> while 1
* apply de'morgan's theorem to simplify compound
conditionals
* factor out repeated test:  (p>1.0) and (p <= 1.0)
* replace pow() with **


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2005-04-29 01:12

Message:
Logged In: YES 
user_id=80475

Thanks for looking at the patch.  What I really need is for
a second person to verify that the transformations are
semantically neutral (no change in overall logic).

FWIW, I was the one who did rev 1.39.  It turns out that it
was a premature modernization that cost some performance. 
Only the while 1 form is optimized by CPython, Jython, and
Pysco.

Have to disagree with you on pow(). The operator form runs
faster and corresponds more closely to the way formulas are
written in math textbooks and in other languages (except C
which doesn't have a pow operator).  This is the reason we
write a+b instead operator.add(a, b).

If you can a chance, please look closely at the logic
transformations to make sure I did them accurately.  Thanks
again.
 

----------------------------------------------------------------------

Comment By: Michiel de Hoon (mdehoon)
Date: 2005-04-29 00:42

Message:
Logged In: YES 
user_id=488897

* I don't see how "while 1" is more readable than "while
True". Note also that in older Python versions, this
actually was "while 1"; it was changed to "while True" in
revision 1.39. I can't recommend changing it back.

* This pertains to line 424. I agree that the line in the
patch is more readable and perhaps faster (though marginally
so).

* I agree with you that there is a repeated test in the
current code. In the patch, I would stick with pow() instead
of ** (see my next comment)

* Unnecessary change. Some people like pow(), others like
**. I see no reason to change.

General comment: It is usually better to have different
changes in separate patches. True, the changes in the patch
all apply to random.py, but otherwise they don't have much
in common.

(I'm just a patch reviewer, not an official Python
developer, so you don't need to take my comments too seriously.)

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1191489&group_id=5470


More information about the Patches mailing list