• Corbin@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 months ago

    Extension modules are implemented in C because the interpreter is written in C. If it were written in another language, folks would write extension modules for that language instead. Also, it would be less relevant if people used portable C bindings like cffi, which are portable to PyPy and other interpreters… but they don’t.

    • BatmanAoD@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      Extension modules can be, and are, written in Rust and C++. And PyPy has a compatibility layer to run extensions (such as numpy) that are written for CPython.

      The reason extension modules are typically in C is of course the API is in C, but that’s true of cffi as well (though you’re right that cffi is more portable). And the reason the API is in C is more fundamental than “CPython is written in C”.