Subsets of Python implemented in Python

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Jul 16 21:06:27 EDT 2010


On Sat, 17 Jul 2010 01:34:48 +0200, candide wrote:

> I don't understand why some parts of the Python language (or the Python
> standard library too) are implemented in C while some other parts are
> implemented in the Python language itself. For instance, lists and
> dictionnaries are implemented in C but sets are not.
> 
> Wouldn't be better to implement all in C (for efficiency reasons for
> example) ?

Efficiency for who? The person writing the code? The CPU?

There's currently a thread about the difficulty of finding volunteers 
willing *and able* to fix bugs in Python. If all of the Python code base 
was written in C, this would be a thousand times worse. There are many 
Python developers who can patch Python code, but not even read C code, 
let alone write it effectively.

Most of the Python standard library is written in Python because 

(1) it's easier
(2) it's fast enough
(3) it allows experimentation and rapid prototyping

E.g. the sets module was written in Python to start with, then replaced 
with a C built-in once it had proven itself.

In other words, the Python standard library is written in Python for the 
exact same reasons that *any* software project might be written in Python.


-- 
Steven



More information about the Python-list mailing list