▲ 128 r/Zig

The new Io interface makes me wanna quit Zig

I've started learning Zig just recently.
I have some background in C, so after reading and watching plenty of materials, Zig seemed like a natural transition. And this was true to a large extent, at least when it comes to syntax, most concepts made sense right away and I liked the language more and more as I learned it. I was walking over Ziglings, but got bored after finishing about a half and decided to just build something as it works better for my brain.
So I chose a small terminal text editor as a first project which felt like a good fit for Zig. The start was nice, I already started getting used to everything a struct, try statements, etc. But the moment I got to the io part, my excitement started to evaporate quickly.
Something as simple as reading from stdin is unreasoanbly hard. At first it looks like I just need a reader, so I declare one. But it turns out a reader does not expose any methods to actually read? It took me a while to figure out that it's interface is what I need:

var stdin_reader = Io.File.stdin().reader(init.io, &buf);
var stdin = &stdin_reader.interface;

I was thinking about just using std.c or std.posix everywhere, but then what's the point of using Zig?
Now I need to read from a file. I found some example on how to read from cwd, but I need to read from an arbitrary path. What do I do? I don't know. The documentation is almost non-existent. Google search doesn't help that much either.
I thought maybe I explore some codebases, so I cloned ghostty and tigerbettle, but both use earlier Zig versions with the old primitives. I can't imagine how expensive will it be to upgrade for those guys if starting a new project from scratch is that hard.
Can someone share your experience with the new Io interface? Am I the only one who struggles with it?

reddit.com
u/olzhas89 — 1 day ago
▲ 8 r/theprimeagen+1 crossposts

Built a bitcask key-value store in C

I am a self-taught backend engineer with the experience revolving mostly around Python and Go. I learnt C a few years ago, but the only project I actually finished in C was a simple Tetris game. I always wanted to dive deeper and build something more serious, but postponed it for all kinds of reasons.

I've recently quit my job, mostly because the management went insane with the pressure to use AI agents for everything, which I didn't like. So now that I have more time as a happy unemployed person, I took the opportunity to reignite my joy for programming and shift my mind from the AI psychosis by investing some time in C.

I first grabbed the K&R book to brush up my knowledge and wrote a few (maybe a dozen) small-to-medium programs. I also revisited the code of the tetris game (which was terrible) and rewrote a small TCP server that I built in C a while back.

Once I got somewhat comfortable, I chose something more challenging to build - a key-value database. In hindsight, that was probably one of the best project ideas, as it turned out that it touches a surprising amount of different concepts. As this was a learning project, I decided to build everything from scratch instead of reaching out for libraries. As a result, I implemented a hashmap, a binary search algo, learned a ton about syscalls, memory management and debugging.

I highly recommend building a key-value store or a small database for anyone looking for a project idea to improve C skills.

If anyone's interested in checking out the source code, here is the repo:
https://github.com/olzhasar/bitcask

I'm not an experienced C programmer (yet), so it might be abysmal in terms of practices. Any feedback is appreciated.

Cheers

u/olzhas89 — 5 days ago