Zig vs Nim for audio programming

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
capocasa
Established Member
Posts: 6
Joined: Thu Jun 19, 2025 4:07 pm
Been thanked: 3 times

Zig vs Nim for audio programming

Post by capocasa »

I just released a small MIDI tool written in Nim and it turned into a conversation about whether Zig or Nim would work better for music software! I feel this is actually quite an interesting conversation so I made a thread here. The gist: Zig user thinks Zig is great for audio- I agree, but I think Nim is even better because you can do anything you can do with Zig- plus I like the ergonomics and you get a lot of high level stuff out of the box so you can work faster without sacrificing performance.

sjomae
Established Member
Posts: 17
Joined: Wed Aug 09, 2023 11:15 am
Been thanked: 4 times

Re: Zig vs Nim for audio programming

Post by sjomae »

I think Zig will be a better language then Nim. Given that, it's also better for audio programming. :wink: Where being able to use c libraries directly in Zig as a major selling point, as many audio libraries are available in c. It's creator wrote Zig to write a Daw. For audio programming you don't want a garbage collector, which Zig hasn't. Nim has multiple strategies for memory it seems, which makes it's goals less focused and specific, which I see as disadvantage. If you need a garbage collector, there are other languages available.

capocasa
Established Member
Posts: 6
Joined: Thu Jun 19, 2025 4:07 pm
Been thanked: 3 times

Re: Zig vs Nim for audio programming

Post by capocasa »

So what the GC and all the NIm stuff does it brings you programming speed- which is kind of unheard of in the audio world. If you can't forget to clean up because the language does it for you, you have fewer bugs.

What makes Nim special is that there isn't any overhead to that- the GC doesn't run willy nilly, it runs when stuff goes out of scope, right away. It's pretty easy to control, just by how you visually structure your code.

C integration is super important. There's an automated tool to write Nim wrappers, but lately I've gotten lazy and just had an AI do it- works fine. It's really quite trivial. The hard part isn't writing the wrapper, the hard part is using it the C way and not blowing things up. That's where Nim shines- you write a small idiomatic layer on top of your C library and you never have to worry about C problems again. For example, you could have a Nim iterator to loop through chunks of audio. That would be zero-copy- under the hood, you're still reading C pointer arrays, it's just safe.

So Nim for audio is a fairly new idea- just like I think Nim is best suited for everything :)

I like Zig quite a bit though, where I think it falls short is bringing along all the high-level stuff that you can get in dynamic languages to help you get things done quickly. The nice thing is in Nim if you don't use those- you don't import the stdlib files- they don't end up in the binary, so you can go low level, but the high level is always there if you need it and is of truly excellent quality.

What does intrigue me is that the Zig guy wrote a DAW :) Which one is that?

Pleased to have a discussion about this :)

Carlo

sjomae
Established Member
Posts: 17
Joined: Wed Aug 09, 2023 11:15 am
Been thanked: 4 times

Re: Zig vs Nim for audio programming

Post by sjomae »

Andrew the lead dev.

What you've to learn for Zig is maybe harder initially then Nim, but you've to learn less, cause there are less features. Also this knowledge has great transfer value to C (and C++ ?). If you know Zig, you more or less know C, as you learn about memory management. Zig is a bit harder then C I think as a language, but easier to learn, because of the tooling, the error handling, the improvements over C preventing you to make certain mistakes, the std library, the libraries and the community. I also think the chance of making good software is greater with Zig then C in general, all though the integration of C libraries into Zig doesn't come without pitfalls. Downside of Zig, is that it's quite heavily in development, so sometimes there are breaking changes.

User avatar
SpotlightKid
Established Member
Posts: 303
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 112 times
Been thanked: 97 times

Re: Zig vs Nim for audio programming

Post by SpotlightKid »

capocasa wrote: Fri Jul 04, 2025 1:40 pm

What does intrigue me is that the Zig guy wrote a DAW :) Which one is that?

sjomae wrote: Fri Jul 04, 2025 2:39 pm

Andrew the lead dev.

I think Andrew wanted to write a DAW and for that project he developed a cross-platform audio I/O layer, which is libsoundio, now sadly languishing in a, what looks to me, unmaintained state. But I don't think he ever finished or even made significant progress on the DAW.

sjomae
Established Member
Posts: 17
Joined: Wed Aug 09, 2023 11:15 am
Been thanked: 4 times

Re: Zig vs Nim for audio programming

Post by sjomae »

He has one as a hobby project.
https://codeberg.org/andrewrk/daw/

User avatar
Michael Willis
Established Member
Posts: 1515
Joined: Mon Oct 03, 2016 3:27 pm
Location: Rocky Mountains, North America
Has thanked: 82 times
Been thanked: 211 times
Contact:

Re: Zig vs Nim for audio programming

Post by Michael Willis »

How about Rust, all y'all?

User avatar
SpotlightKid
Established Member
Posts: 303
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 112 times
Been thanked: 97 times

Re: Zig vs Nim for audio programming

Post by SpotlightKid »

50+ dependencies per project, long build times, and build directories with 1+ GB quite normal. Yay!

OTOH, people do release useful plugins written in Rust, whereas with Nim, most of the stuff is still rather experimental.

Post Reply