From: candide on
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) ?
From: Richard Thomas on
On Jul 17, 12:34 am, candide <cand...(a)free.invalid> 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) ?

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.
From: Steven D'Aprano on
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