[Python-Dev] SF patch 864863: Bisect C implementation

Raymond Hettinger python at rcn.com
Tue Dec 30 23:27:03 EST 2003


[Raymond]
> Dmitry Vasiliev has submitted a C implementation for the bisect 
> module.
> 
> My thoughts are to accept it with the following changes:
> 
> * leave the original code intact for teaching purposes
> * import the C version from _bisect
> * make sure the C code is not list specific and will work with any 
>   container supporting __len__(), __getitem__(), and insert().  
> 
> Do you guys have any objections?

> [Guido]
> > Only that I wished you had done the same for heapq.py.

[Tim]
> It's not too late.  IIRC, neither you nor I could make time to review
the
> heapq plans before the C code got checked in.  I was able to make a
little
> time after, and mourned the loss of the educational value of the
Python
> version (to Raymond, in pvt).

I would be happy to bring back the python version and make it coexist
with
the C version.  IMO, it was a programming pearl unto itself and efforts
were already made to preserve the extensive module docstring and make
the
code match the original line for line with the variable names and logic
intact.

The bisect module warrants even more consideration because it is more
basic 
and more venerable. 
 


[Tim]
> Nobody can sanely accuse me of not
> caring about speed (see a decade of speed-obsessed Python checkins for
> counterexamples <wink>), but I cry a little each time a piece of the
> system
> gets recoded in C.  Keeping the original Python code around is a nice
> compromise (pioneered, IIRC, by string.py, a loooong time ago).

Also, with the PyPy project, there is a chance that cleanly coded pure
python modules will survive the test of time longer than their C
counterparts.  In the itertools module, I documented pure python 
equivalents to make the documentation more specific, to enchance
understanding, and to make it easier to backport.  For the most 
part, that effort was successful.

The only downside is the double maintenance problem of keeping the two
in sync.  Given the stability of bisect, that is not much of an issue.


Raymond Hettinger


#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################



More information about the Python-Dev mailing list