4 ms·
> Is there actually anything different about python here? I say this as a big fan of Python: I think the main difference is that the CPython C APIs are much mo
by woodruffw 4y ago
> Is there actually anything different about python here?
I say this as a big fan of Python: I think the main difference is that the CPython C APIs are much more of a pain to use :-)
I don't know about Node's C APIs, but I've written both Python and Ruby extensions and find the MRI APIs much nicer than the CPython ones.
- immmmmm 4y agohave you tried pybind11? if you accept going from C to C++, all the dirty job is done for you, exposing a C++ function is one line and can use numpy arrays directly in the function.
- woodruffw 4y agoI've contributed to extensions that are written against pybind11, but never written my own. It was pretty nice, and it does indeed cover some of my grievances (at the expense of making me write C++?).
- toyg 4y agoThat's literally the opposite feedback of the rest of the world. There is a reason the scientific community standardized on Python, and bindings for all sorts of things from Blender to KDE were more successful on Python than other languages.
- woodruffw 4y agoMy understanding of the "why" for Python in the scientific community is that it's twofold: it's very easy to get started in (and slowly build up expertise in), and (2) that a key set of packages (pandas, numpy) were created early and obtained critical mass. But neither of these implies that the CPython API is exceptionally good: (1) can be an overriding factor during the implementation of (2), and (2) means that the average scientific Python user doesn't actually need to touch the CPython APIs that much (all the work is already done!). So I don't think my feedback ("Ruby extensions are easier to write than CPython extensions") is actually incongruous with the rest of the world; the rest of the world picked Python because it's a better language in the ways that matter.
- toyg 4y agoMaybe, and maybe there was also a timing issue - in the sense that at the time it mattered, which was about 10-15 years ago, the Python api was better than most alternatives.
- woodruffw 4y agoSure, that seems likely to me as well! Edit: Well, maybe 20 years ago -- 10 years ago, Ruby's C API was about the same and still (IMO) better.
- deleted 4y ago[deleted]
- UncleEntity 4y agoIf you’re just calling C functions or wrapping some C++ classes CPython isn’t very hard — unpack the arguments, call the function, pack up the return value(s). Iterator support is a little trickier but not too bad once you have it figured out. Same with overloaded functions. Array access is a bit annoying because there’s two ways to do it and you have to guess the right one if you want slices and other craziness. Memory management can be a pain but I’d imagine it is like that whenever you’re combining two languages. I’ve done some pretty complex wrappers and have yet to find something that just isn’t possible (within the limitations of python). I usually get the boilerplate generated from pybindgen and then start on the serious hacking. Actually… I did find something that wasn’t possible and that was because someone thought it was a good idea to commit the raw buffer interface (whatever it’s called) before it was finished and I wasted a whole lot of time on that before I dug into the python source to figure out why it wasn’t working.