Live data from Hacker News

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

overbring.com

21–30 of 73 posts

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

#21
post #16
post #7

Earlier quoted context omitted.

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.

Would you be willing to share your CLAUDE.md file contents? I’m vibe coding in Elixir.

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.

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

#22

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.

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.

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

#23
post #6

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-...

Not only C. Can be done in any compiled language (C, Rust, Zig, etc). Not sure if can be done with GC language.

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.

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

#24
post #13

Earlier quoted context omitted.

So hard to tell if this is parody or not.

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…

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...

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

#26
post #4

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.

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.

The issue in this case was Opus was pretty crap at C. It kept introducing segfaults.

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

#27

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.

Why does every post that mentions something other than Rust or Zig get a comment saying "Why not Rust or Zig"?

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

#28
post #27

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.

Why does every post that mentions something other than Rust or Zig get a comment saying "Why not Rust or Zig"?

Why did you write your comment in English? Why not Rust or Zig?

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

#29

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.

The author was trying to learn about https://github.com/elixir-sqlite/exqlite which uses C.

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

#30

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.

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…

> Security is a spectrum.

It's less spectrum and more that it's relative. Depends on attacker and what they seek to gain.

An unsecured server is an unsecured server. But there is a world of difference if they are attacked by CIA or local script kiddies.

Post reply on HN