Hacker News new | ask | show | jobs
by jokoon 1535 days ago
Question: I found python "bindings" for SFML, written in cython, and patched them a bit.

I guess Cython is not really made to write bindings, but is it easier to write bindings with cython or cpython?

1 comments

As someone who has been writing python bindings regularly for 10 years:

Writing bindings in Cython is much, much faster in terms of development time. It fits nicely and unintrusively in an already python packaged library. You can gently add some C functions or call C libraries in minutes.

You won't have a full control of what's happening though. Just have a look at the generated code and you'll see the mess of indirections that are generated.

Cython bindings become limited when you have to build more complex stuff though, going deeper than just calling some C functions. The typical case is when you have to actually handle the lifetime and borrowing of C native objects.

At that point, CPython will be the way to go, but it's much more code, and very error prone: you have to manually keep track of reference counting.