5 ms·
If you intend to write extension for Python, Ruby, PHP, Lua, Node or most of any high level language, you need to write it in C. Want to build a library that c
by z92 8y ago
If you intend to write extension for Python, Ruby, PHP, Lua, Node or most of any high level language, you need to write it in C.
Want to build a library that can be used in any of the high level languages? Write it in C and provide binding.
A library code written in PHP can't be used by Haskell. Not without a big overhead. Or vice versa. Write it in C and your are done.
These are where C still comes handy.
- blub 8y agoUnless I'm missing something, any language offering a C FFI can be used to provide interoperability.
- humanrebar 8y agoDepends on what you are doing. You often need to pull in the other language's runtime while libc is typically already in use. You also have to be careful about ABI details like string representations, concurrency, and threading features.
- deleted 8y ago[deleted]
- __s 8y agoNode is actually a bit lack luster to write extensions for in C, as it prefers to go through v8's C++ abi. Same for LLVM: they have a half baked C interface to what's really a C++ abi. There's an alright attempt at allowing for Rust bindings in node: https://github.com/neon-bindings/neon https://github.com/neon-bindings/neon Because C is so raw bone, highly generic APIs from higher level languages can come off as rather lackluster when reduced to C's world view
- pornel 8y agoFortunately, you don't have to use C for this any more. Rust has bindings for making extensions for Ruby, Python, Lua and Node, and generally it's very well suited for making zero-cost cleaner APIs on top of C FFI. https://github.com/tildeio/helix https://github.com/tildeio/helix https://github.com/PyO3/pyo3 https://github.com/PyO3/pyo3 https://github.com/kyren/rlua https://github.com/kyren/rlua https://github.com/neon-bindings/neon https://github.com/neon-bindings/neon
- pjmlp 8y agoThankfully there are those of us that are able to understand the difference between a C compatible ABI, and having to actually use the language.