4 ms·
What's an example of a language with "good" FFI?
by culi 4y ago
What's an example of a language with "good" FFI?
- davedx 4y agoRust's seems pretty good. I've been doing some Rust/C interop and it works very smoothly
- zyx_tony 4y agoNim is quite enjoyable to use. I do a decent amount of scientific computing, interfacing with various c/cpp libs
- williamstein 4y agoCalling C functions from zig is very nice, partly because zig uses llvm to parse C header files and uses that information.
- beagle3 4y agoLuaJIT has a pretty great FFi which was later ported to standard Lua; Python’s ctypes provides a decent FFI. Nim, Zig and Rust do too, but they have semantics much closer to C, so it’s almost free (especially when they can all use llvm directly for code generation, and Nim’s preferred way is to compile through C in the first place)
- WalterBright 4y agoWith the D programming language, to interface with C's stdio.h: import stdio; void main() { printf("hello from D!\n"); } is all that's necessary, as D has a built-in C compiler that reads stdio.h, compiles it, and presents its interface to the D code.
- cercatrova 4y agoI hear about D often on HN but I never see it being used in the wild so to speak. When I looked at it, it seemed, like C++, a hodgepodge of features built up over time rather than being a more deliberately focused language. I hate to compare and contrast but Rust comes to mind as one of the latter, probably because it has a somewhat more intensive and extensive RFC process for adding new features.
- WalterBright 4y agoD has made its mistakes (there's no way to evolve a language over 20 years and not make a mistake here and there), but we also have a deprecation process to remove them. The people who use D tend to like it very much.
- andrewmcwatters 4y agoThis is even more impressive than LuaJIT's FFI in my opinion, which I previously thought was state of the art. You basically pass in a preprocessed header, and LuaJIT does the rest. All this to say, I feel that any FFI that requires you to manually write bindings is rubbish.
- WalterBright 4y agoWe lived with manual bindings to interface with C for years. Building in direct support for C itself is a huge leap forward in usability. In several ways it's even better than C++'s support for C.
- girvo 4y agoHow does it deal with the macro-in-macro-in-macro soup that a non trivial amount of headers are? c2nim does a decent job but struggles with some of those types. gcc -E on the header works around it, so I wonder if c2nim could be made to operate similarly to what you’re describing.