Subsets of Python implemented in Python

C

candide

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) ?
 
R

Richard Thomas

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) ?

CPython's sets are implemented in C. Old versions of Python
implemented sets in the 'set' module which was written in Python but
that has been deprecated and removed. A lot of the standard library is
implemented in Python because it makes it more easily portable to non-
CPython implementations.

Chard.
 
S

Steven D'Aprano

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top