I let LLMs write an Elixir NIF in C; it mostly worked

30 overbring_labs 23 8/15/2025, 4:02:25 PM overbring.com ↗

Comments (23)

drumnerd · 1h ago
I would never ever let an LLM anywhere near C code. If you need help from LLM to write a NIF that performs basic C calls to the OS, you probably can’t check if it’s safe. I mean, it needs at least to pass valgrind.
true_religion · 52m ago
Security is a spectrum. If you totally control the input going into a program, it can be safe even if you didn't test it for memory leaks. The only errors that occur will be truly erroneous, not malicious and for many solutions that's fine.

At the very least, it's fine for personal projects which is something I'm getting into more and more: remembering that computers were meant to create convenience, so writing small programs to make life easier.

flax · 2h ago
"it mostly worked" is just a more nuanced way of saying "it didn't work". Apparently the author did eventually get something working, but it is false to say that the LLMs produced a working project.
jgalt212 · 2h ago
I dunno. Depending on the writer and their particularly axe to grind the definition can vary widely. I would like it to mean, "any fixes I needed to make were minimal and not time intensive."
lawik · 1h ago
I've done this. The NIF worked as in that it ran and was a correct enough NIF. It did not work in terms of solving what I needed it to do. Iteration was a bit painful because it was tangled with a nasty library that needed to be cross-compiled. So when I made a change it seg faulted and I bailed.

I essentially ran out of patience and tried another approach. It involved an LLM running C code so I could check the library output compared to my implementation to make sure it was byte-for-byte.

The C will never ship. I don't have practice writing C so I am very inefficient at it. I read it okay. LLMs are pretty decent help for this type of scrap code.

cultofmetatron · 1h ago
built my startup in elixir. love it but nifs are one of the few ways you can crash the VM. I don't trust myseld to write a nif in production. no way I'd do it with AI in c. Thank god theres projects like rustler which can catch panics before it crashes the main VM.
simonw · 2h ago
For anyone wondering, the article clarifies that "A NIF is a function that is implemented in C instead of Erlang".

I had a bunch of fun getting ChatGPT Code Interpreter to write (and compile and test) C extensions for SQLite last year: https://simonwillison.net/2024/Mar/23/building-c-extensions-...

victorbjorklund · 1h ago
Not only C. Can be done in any compiled language (C, Rust, Zig, etc). Not sure if can be done with GC language.
toast0 · 44m ago
BEAM loads a shared object, that opens the door to anything.

If you want to use a GC language for NIFs, you'd need to hook up your runtime somehow.

IMHO, it makes more sense to lean into the BEAM and use its resource management... my NIFs have all been pretty straight forward to write. All the boiler plate is what it is, and figuring out how to cooperate with the scheuduler for long running code or i/o can be a bit tricky, but if you can do a lot in a BEAM language, the native code ends up being like

Check the arguments, do the thing, return the results.

bcardarella · 2h ago
I tried to do this a few weeks ago, I tried to build a NIF around an existing C lib. I was using Claude Opus and burned over $300 (I didn't have Pro) on tokens with no usable results.
cpursley · 2h ago
Get Pro, 4 is quite good at Elixir now but you have to stay on it. 3.5 was not, so I imagine next version of Claude will be able to handle the more esoteric things like NIFs, etc.
bcardarella · 3m ago
The issue in this case was Opus was pretty crap at C. It kept introducing segfaults.
ipaddr · 2h ago
Get Pro 5.. it will work I promise
cpursley · 2h ago
I've completely refactored my Elixir codebase with Claude 4, expanded the test suite by 1,000 more tests, and released a few more features faster than I ever have to actual paying customers. Tidewave MCP is helpful as are some custom commands and a well tunded CLAUDE.md But you do you.
jtbayly · 1h ago
Would you be willing to share your CLAUDE.md file contents? I’m vibe coding in Elixir.
cpursley · 59m ago
I somewhat followed this:

https://elixirforum.com/t/coding-with-llms-conventions-md-fo...

It's not perfect - you often have to remind it not to write imperative style code and to lean on Elixir conventions like "with" statements, function head matching, not reassigning vars, etc.

cschep · 1h ago
So hard to tell if this is parody or not.
cpursley · 1h ago
Here's one Claude-vibed project that makes me money that I run in addition to my saas, which is Elixir. I'm not strong in TypeScript and this is an Astro static site, so Claude has been really helpful. Backend is Supabase (postgres) and a few background jobs via https://pgflow.dev (pgmq) that fetch and populate job openings and uses some AI steps to filter then classify into the correct categories (among other things, there's also an job application flow and automated email newsletter): https://jobsinappraisal.com

I also "vibed" up this: https://livefilter.fly.dev/todos (https://github.com/cpursley/livefilter) and this: https://star-support-demo.vercel.app/en/getting-started (https://github.com/agoodway/star-support-demo)

I hand wrote very little of this code, but can read most of it - the SQL and Elixir at least ;)

cess11 · 20m ago
Is there a reason why you're using 'when is_struct/2' instead of pattern matching here?

https://github.com/cpursley/livefilter/blob/main/lib/live_fi...

Sinidir · 1h ago
Its not really hard to tell.
weatherlight · 1h ago
Why C instead of Rust or Zig? Rustler and Zigler exist. I feel like a Vibecoded NIF in C is the absolute last thing I would want to expose the BEAM to.
qualeed · 2m ago
Why does every post that mentions something other than Rust or Zig get a comment saying "Why not Rust or Zig"?
leansensei · 10m ago
Why not C? It made no difference, we're talking about a few function calls.