Live data from Hacker News

Swig – Connect C/C++ programs with high-level programming languages

swig.org

41–50 of 90 posts

Re: Swig – Connect C/C++ programs with high-level programming languages

#41
post #6

I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters. CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).

I don't know if it's a feature of Swig, but Swig C++ modules are also hard to use from Python, because they're missing reflection, docstrings, etc. I don't know if it was a shortcoming of the Swig module I was working with (e.g. author didn't bother to add docstrings) or the Swig itself, but it was pretty uncomfortable working with module that provides zero runtime documentation and incomplete documentation.

Also, structure of the resulting module, classes, methods was kind of unpythonic.

Re: Swig – Connect C/C++ programs with high-level programming languages

#43
post #6

I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters. CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).

I’ve used pybind11 to expose C++ to Python. Worked well for me after the initial hurdle of learning what needed to be done.

Re: Swig – Connect C/C++ programs with high-level programming languages

#44

I've used Swig to inherit from base classes in Java to implementations in C++. Swig generated the JNI and C++ bindings. Fun times.

Swig is kind of clunky. But it is so much better than writing JNI yourself. JNI is gouge-your-eyeballs-out awful; SWIG is at least tolerable, and it works.

Re: Swig – Connect C/C++ programs with high-level programming languages

#47
post #6

I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters. CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).

[deleted]

Re: Swig – Connect C/C++ programs with high-level programming languages

#48
post #6

I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters. CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).

I'd recommend pybind11 for c/c++ python bridge. Though you have to compile your wheel for every minor python version separately.

Re: Swig – Connect C/C++ programs with high-level programming languages

#49
post #6

I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters. CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).

The syntax is terse if you need to do arbitrary stuff with an arbitrary interface. But if you start off keeping SWIG in mind from the beginning and avoid funky features at API level you might be fine by just "importing" your header files in the SWIG-definition file. See https://projects.om-office.de/frans/swig_demo/-/tree/master/... (disclaimer: very old and special exception handling) IMHO this is a good practice an…

> But if you start off keeping SWIG in mind from the beginning and avoid funky features at API level you might be fine by just "importing" your header files in the SWIG-definition file.

This has been my experience as well. Just like I would argue that code which has been written to be testable is better than code which hasn’t, a “public API” which has been written to be consumed by another tool is better than one that hasn’t

Re: Swig – Connect C/C++ programs with high-level programming languages

#50
post #46

Who classifies C++ as a low-level programming language? Even C is only being called low-level relatively recently, and it's not universally accepted as such.

If it requires explicitly allocating memory, then it is low level to most contemporary programmers.
Post reply on HN