2009/3/3 Stefan Behnel email@example.com
Gustavo Carneiro wrote:
And Cython *is* a wrapper generator.
Well, no, but PyBindGen is, now that you mention it. It looks a bit like a FFI (like ctypes), but it generates the corresponding wrapper code, if I'm not mistaken. Using it for anything but wrapping C/C++ code to make it callable in Python would be futile.
Cython is (literally) not a wrapper generator as it will not generate a wrapper for you. You have to write it yourself. Cython is a programming language to write extension modules for CPython, as generic as that. It focuses on Python-like simplicity, C-like speed and easy interfacing with both CPython and C (while better C++ and Fortran support is still being fledged out). It is being used to write wrappers, but it is also being used to write high-performance computational code, with or without interfacing to external C libraries. In the second line, it's also heading to become a fully-compliant Python compiler (a 1.0 goal), but that doesn't belong here (just like the automatic-compile-on-import support for Python files *wink*).
OK, but surely we can say that Cython is a code generator, or compiler. So it's more generic than a wrapper generator. But it can fulfill the role of wrapper generator, even if it means writing more code than other tools for describing the same API. For me, wrapper is any C/C++ code that bindings Python to a C/C++ library. If Cython can generate that code, then Cython can also be considered a wrapper generator, or at least the engine for a wrapper generator. It is more or less at the same level as Boost.Python. You also have to write the wrapper code using Boost.Python yourself...
I clearly remember seeing (ugly) C code generated by Cython, before I decided to write PyBindGen.
Let's not start a discussion about taste here. Readable, commented, easy to debug C code is an obvious goal of the Cython project, simply because its developers are those who debug it most of the time. That said, we generally tell our users to look at the highlighted HTML page that Cython generates of their source code, so that they can focus more easily on those parts of the generated C code that are worth optimising. Having to read the entire C code file just to see where things go wrong is not a good idea.
OK. I won't comment except to mention that I am glad the Cython project wants to generate readable code.
Gustavo Carneiro wrote:
2009/3/3 Stefan Behnel wrote:
Cython is (literally) not a wrapper generator as it will not generate a wrapper for you. You have to write it yourself. Cython is a programming language to write extension modules for CPython, as generic as that.
OK, but surely we can say that Cython is a code generator, or compiler. [...] It is more or less at the same level as Boost.Python. You also have to write the wrapper code using Boost.Python yourself...
Except that Boost.Python does not optimise the code for you, simply because it is a library, not a compiler. It doesn't know what called it with what intention. The Cython compiler can extract a lot of information from your code and it *will* use it to make your code run fast. For example, calling a Cython implemented function is very fast compared to normal Python, simply because we can adapt the generated code to the specific signature of a function, instead of relying on generic argument unpacking code.