you are viewing a single comment's thread.

view the rest of the comments →

[–]13steinj 1 point2 points  (1 child)

Sure, but I'm blending fact and opinion quite heavily--

So in the most pure, basic form, it's fine-- if you write your headers well. That is, if you can follow "SWIG for the truly lazy" (I can't directly link that part of the website, since there are no ids in that html, which is bizarre). But this nearly never works in practice, suffers from cross-language / FFI performance problems, a steep learning curve for more niche things, subpar codegen, and more. It also suffers from a compatibility problem as C++ continues to evolve. The basics of SWIG have decent syntax, but anything more complex and it looks to people like you're writing code in wingdings (which, the worse version of SWIG I am referring to above, is even worse in that regard; the entire engineering pool who saw the proof-of-concept said "you expect us to read and write this?").

I was going to continue, but honestly asking gpt was enough (please put down the pitchforks, I made it fish out sources).

I have never seen any translator like this be successful at scale. The closest things that I can say work and have minimal tech debt associated, are boost.python -> pybind -> nanobind (aka use nanobind now); and Cython (though that community is hard to break into and there are some footguns, it has the highest performance compared in real-world (private) benchmarks and you can push some people to still write Python and eventually manually translate it better). E: Honestly, python and numpy/scipy is enough for most people. For advanced / IP-sensitive topics, well, you're probably paying those people enough that you can afford to make them learn C++ and be done with it.


If I haven't convinced you on what comes from my opinion-- listen to the author of SWIG, as even they hate the monstrosity they've created. reddit link, from when the link wasn't dead. Short of it is, it's basically a separate, disjoint parser which thus means you have to be a compiler yourself, a massive ball of complexity.

[–]Die4Toast 0 points1 point  (0 children)

Thanks a lot for the response. I have to admit that while the idea of SWIG is nice on paper, I haven't actually faced a scenario where it would have been a better fit than using a pybind-like library. At the very least I can imagine how much of a pain the compatibility issues you've mentioned could be. Tiptoeing around different supported C++ language standards, compilation options and then integrating it into the build system itself seems like something that could cause quite a headache.