5 ms·
Rust is excellent overall, but is lacking in interoperability (I mean, it is capable -- but iterop is burdensome, relatively). Related to the overall topic of s
by chromatin 6y ago
Rust is excellent overall, but is lacking in interoperability (I mean, it is capable -- but iterop is burdensome, relatively). Related to the overall topic of sum types, there is ergonomic support in the form of built-in enum.
D is excellent overall (and I think sadly under-recognized for this), but it is lacking in ecosystem. Related to the overall topic of sum types, there is an excellent library, `sumtype` which recently hit 1.0 status.
I much prefer either of these to modern C++.
- api 6y agoInteroperability is generally a disaster. Most languages can interoperate with C ABI functions, but even that is painful in some cases. It seems like most languages consider this an afterthought when it should be a central consideration. There will never be a time when everything is written in just one language.
- jeltz 6y agoThe only languages I know of with good C interoperability are C++ and Zig. This is definitely an area where Rust could improve.
- touisteur 6y agoDon't forget Ada where interop with C is baked in the language spec and interop with c++ has been muuuch improved some years ago.
- Silhouette 6y agoHow would you define "good C interoperability"?
- api 6y agoCalling C functions with minimal fuss and good performance, which requires C header parsing and linking or DLL loading support. It also requires built in or standard library support for whatever convenience types and functions are needed to make using real C APIs pleasant and as safe as possible. Support for exporting functions and passing function pointers the other way is great too if it can be done. Go with CGo is okay from a usability perspective but performance is poor. I haven't looked much at Rust's implementation so I can't comment. I've also heard Python is not bad.
- Silhouette 6y agoPython was actually the reason I asked the question. There are multiple ways to integrate Python and C, depending on exactly what you want to do. The simplest is to use ctypes, which almost reduces calling C APIs in a DLL/SO to calling a function to load the shared library and then calling the APIs like any other function. The most obvious practical limitation is that ctypes can only infer so much about the required parameter and return types of the C functions from how you call them, so you have to specify the types explicitly in your Python code in any other case. That's no harder than writing a C header file, though, and I expect there is probably a tool somewhere that would automatically generate the corresponding Python/ctypes code for the common use cases. There are a few other warts that aren't quite as intrusive, including some restrictions relating to pointers and some verbose marshalling if you're passing strings around. But overall, it's a very convenient way to call out to C-style APIs from Python code that probably covers 95+% of practical use cases with only minor inconvenience compared to what you'd have written doing everything in either language on its own.
- vips7L 6y agoZig has the best C interop I've ever used. Just a simple import and it figures it out: const c = @cImport({ @cInclude("types.h"); @cInclude("stat.h"); @cInclude("user.h"); });
- agersant 6y agoYou can add Lua to this list! https://luajit.org/ext_ffi.html https://luajit.org/ext_ffi.html
- chromatin 6y agoD has crazy good and easy C interoperability. There is a near 1-1 mapping of types. C interop was a major design goal. Dstep, which uses llvm/clang as a library, can translate headers for you. dpp I believe automagically at compile time translates C++/C headers.
- vips7L 6y agoI really wish D had the ecosystem. I think it could have excelled in a lot of the places Go has been used.