4 ms·
Python has no advantage in this regard over any other language supported by SWIG. And perl almost certainly has more available library bindings than python.
by kingkongrevenge 18y ago
Python has no advantage in this regard over any other language supported by SWIG. And perl almost certainly has more available library bindings than python.
- ivankirigin 18y agoBut python is a pleasure to code. Also, I prefer Boost, and know the python bindings are solid.
- llimllib 18y agoctypes, cython, Boost::python and pyrex are real advantages in this regard; SWIG is extremely painful in comparison.
- SwellJoe 18y agoBoth Perl and Python have far nicer ways to link to C than SWIG. Having worked with both, I think they're about equal these days on the binding to C front (though, as always, in Perl there's far more than one way to do it, and there's only a couple of obvious ways to do it in Python).
- kingkongrevenge 18y agoDo you know of any perl & C++ solutions other than perlxs and swig?
- SwellJoe 18y agoI've never used C++ from Perl, only C, but there is a version of Inline for C++ here: http://search.cpan.org/~neilw/Inline-CPP-0.25/ http://search.cpan.org/~neilw/Inline-CPP-0.25/ The nice thing about Inline is that the bindings are obviously named (function foo() in C becomes sub foo in Perl), and it's all automagic. Of course, if your C/C++ code is big or an existing library you want to bind to rather than just a few bits and pieces, perlxs (and its related utilities) might very well still be the way to go. There is XSpp, which supposedly makes C++ and XS play nicer together. But perlxs is dramatically better than SWIG in most circumstances I can think of (I don't mean to imply that SWIG is not a wonderful tool--it's a fantastic tool, but both Perl and Python have language-specific solutions to most of the same problems that are superior). But you can't beat Inline::C (and I guess Inline::CPP) for simplicity. If you know both Perl and C/C++ their usage is absolutely obvious. perlxs requires a little more reading, and I have to consult the docs whenever I cross paths with it. Python has Weave (part of SciPy), if you like the inline model, though I'm not sure it's being maintained heavily these days. If large data sets are your problem (some of the things you might use the numeric data structure tools in Boost for), PDL might be a solution, since it has a lot of tools for manipulating large data sets without having to revert to writing your own C. Likewise NumPy in Python. And, of course, there are already Perl bindings for Boost in CPAN, though the vast majority of Boost seems to be just making C++ more like Perl, rather than adding anything that Perl coders would find interesting.
- inklesspen 18y agoSomeone hasn't heard of ctypes: http://docs.python.org/lib/module-ctypes.html http://docs.python.org/lib/module-ctypes.html It lets you use arbitrary c libraries in Python. It automatically does the wrapping for you.
- kingkongrevenge 18y agoI hadn't heard of ctypes, but the same functionality is available in perl. It seems pretty silly and crash prone to me to dynamically load object code and then wrap it with a load of error checking rather than write proper bindings.