Remix.run Logo
▲ dava96 2 days ago

I've been toying with the idea of learning zig and weirdly enough I was looking at this guys book. I don't have any experience with low level languages. The closest I've gotten is Go.

I was debating between C and Zig, but I still don't really know what I want to choose. Feels like C is probably the right choice given the languages age and it could technically be more useful (not that I'd be looking for a job doing C work).

For those that know both, what would you pick?

▲kev009 2 days ago | parent | next [-]

C is still supreme for working on the majority for a Linux/BSD system stack. It also imparts skill that transcend to most other spaces where you may eventually need an FFI to interact with a library anyway or understand how it actually runs on a system.

▲meerita 2 days ago | parent | prev | next [-]

It depends for what you want it. If you're going to do an API, well, Golang is more practical here in my opinion. For TUI apps, I would dare to say Rust was more pleasant than Golang. My experience with Zig was limited, I would not say is not a good fit.

▲mmilunic 2 days ago | parent | prev | next [-]

I would say from a pedagogical perspective, learning C is hugely useful for understanding how programming works at a much lower level.

This has the benefit of you learning about manual memory management and how to deal with all the issues that come with such a rules free language like C that will basically let you do anything. This understanding means lot of the constraints and features that safer languages like Zig and Rust add start to make a lot more sense. For example, going from Python to Rust, the borrow checker will probably seem rather arbitrary, but going from C to Rust, you will find the borrow checker is just automating a lot of checks you were already doing yourself.

TLDR: Learn C. I would recommend the 15122 CMU course as a pretty good foundation. You can find it online here https://www.cs.cmu.edu/~15122/schedule.shtml .

▲SoftTalker 2 days ago | parent | next [-]

For that matter, assembly is useful as well. Not that you have to become an expert in it, but do enough that you understand it from a practical standpoint. It doesn't even have to be on x86, use an emulator of something simple like a 6809 or 6502. I never had trouble understanding pointers in C once I had some experience writing assembly code.

▲pjmlp 2 days ago | parent | prev [-]

Another quite good one is Modern C from Jens Gustedt.

https://www.manning.com/books/modern-c-third-edition

This is the kind of book to learn C from nowadays, not a dusty copy from K&R C, leave that one for historical purposes only.

▲pastel8739 2 days ago | parent | prev [-]

I think you should know C if you want to do low level stuff. It will help understand why zig (or rust) is built the way it is and what is useful about it, too.