Which language among C, C++, Rust or Nim is better suited for creating Erlang/Elixir NIFs?

I didn’t include Crystal or Go in the list of languages, because those two languages have a GC and I think adding an extra GC when Elixir already have its own GC won’t be a good idea. Nim also have a Garbage collector, but that can be turned off AFAIK (and Nim compiles to C, C++ or JavaScript).

2 Likes

With Rustler there is a powerful toolbox available to use Rust for NIFs, also with C and C++ you can directly access the provided headers that come with Erlang.

I’m not aware of any projects like rustler for any other language, also I do not know how easy it is in other languages to use the macro-heavy C-headers.

Therefore I think you’ll have to choose among those 3 (Rust, C, C++) according to how good you know that language.

Because of memory safety I’d prefer Rust though.

4 Likes

Rust no GC. Nim has really nice syntax but has GC (it can be turned off but most of the libs assume GC) is not very mature. I really liked Nim when I tried it out though.

2 Likes

Yeah I would definitely say Rust, not just because it is fast, but the macro’s in Rustler make the API easy to use, as well as it is much harder to screw up and crash the entire node unlike C/C++. ^.^

9 Likes