I was reading the Swift 6.3 release, and better C interoperability was one of the main new features. As a Swift developer, I know that a lot of people love Swift because of how great it is to work with alongside C. So this brings forward the question: why doesn't Swift also work with Rust, or Python, or many other languages?
(Specifically with Swift, I don't know how useful interoperability with Rust or Python would be (probably not very useful), and it certainly wouldn't be a trivial engineering challenge, but aside from that: why not?)
More generally, why isn't interoperability between languages a bigger thing? There are of course challenges, like interpreted vs compiled, or JIT vs AOT compilation, but I think there are serious benefits to be had. Perhaps in a perfectly setup project you wouldn't need interoperability, but in the real world plumbing between languages is a constant problem. To demonstrate this, if one language could easily communicate with many others, here are some possible use cases.
- All libraries of all languages become compatible; this is the big one. It would be pretty freeing (although perhaps not always architecturally wise) if when searching for libraries to do what you want, you could pick from literally anything. - Certain languages are suited to certain applications, with interoperability, you could be incredibly versatile. If one language is really good at one thing, and another language is really good at another thing, and you're project needs to do both thing, you don't have to compromise if both languages are interoperable. - Multi-language projects could not only be possible, but even easy. If you could do backend in Go and frontend in TypeScript, it would be phenomenal if you could freely import abstracts in-between languages. Imagine end-to-end type safety even, with no additional work. - Performance. Simple languages are faster to write, though sometimes run into problems later when performance becomes a bottleneck. This would be solved if say, Rust and Python could work together. You could write everything in Python, then when you need the power, switch to Rust. This already exists with Maturin and PyO3, and as a frequent user of this structure, it's pretty great. Imagine if it was available for all languages.
There are just some of the overlapping benefits, but I am sure there are more. In any case, these are things that would be great to have! Why hasn't somebody, perhaps in a performant low-level language, built a plumbing layer which connects many different programming languages? We live in an age with really powerful IDEs, that, if given the right tools, could definitely support much deeper interoperability.
What if programming with two languages in one project didn't feel different from just using one? Sure, some people just want to get from point A to point B, but I think the freedom to use anything could really create a lot of productivity.
While I am well aware that this would be a behemoth engineering project, I think a small group of ambitious developers could make significant headway. It wouldn't need to be all the way, and you'd be wise to take it slow, but I feel the benefits of such a project would be well worth the considerable effort.
As an example... why would I want to call python from C? If I'm writing in C, its because I want high performance with low-level control of resources. To call a python function, I suddenly need to spin up the python virtual machine including its baggage like its garbage collector -- there goes my performance and low-level control, I'm suddenly running a massive stack that I didn't write!
Alternately, you could compile the python code into a bytecode (different than PVM bytecode) that C can call performantly... but to do that you lose the benefits of python. Suddenly your python code needs to be compiled after every change (slowing down development, one of Python's greatest benefits) and you're required to declare and enforce strict types (no more easy duck typing!) so that C can count on getting back data in the expected format.
In contrast, calling C from Python does make sense and can already be done.
And writing plumbing to handle generic interoperability between 2 languages would be a lot of work. Writing parts of a project or system in different languages and then having them communicate through a standard interface like an API is much less work.