Hacker News new | ask | show | jobs
by audunw 2016 days ago
> Zig is a lot more complex than C, but I think most of the language complexity came from filling in gaps rather than tacking things on.

I think it's important to keep in mind that with C you might end up using a bunch of extenions, complex pre-processor macros or pragma magic to achieve essential things.

C in itself is relatively simple, but using it in practice can end up becoming quite complex.

Zig ends up being simpler in some ways by having less magic and special ways of achieving things. "printf" is very magical in most C compilers, but the equivalent in Zig is nothing particularly special from either the language or the compilers side.

I think the only thing that truly adds complexity without being strictly necessary, is the async stuff. But you can argue that async IO is becoming a really essential thing for systems programming, and using it without explicit language suppport is a nightmare.

2 comments

"printf" isn't magical, it's a standard va_args function. There's plenty of ugliness in the implementation [1] (so many macros!) but that's to be expected from something that has to simultaneously parse a format string and format output. The only magic is around format string checking.

1. https://github.com/bminor/glibc/blob/glibc-2.32/stdio-common...

> The only magic is around format string checking

Also the compiler is likely to optimise most calls to printf, transforming them into calls to other functions like puts [0], or apparently [1] even to fwrite. Probably doesn't count as magic, but almost.

[0] https://stackoverflow.com/q/44406798/

[1] https://news.ycombinator.com/item?id=23308893

having just learned it, async is not really complex, so much as "a thing that needs to be explained to you" kind of like how "pointers need to be explained to you". Sadly I don't see any good resources on that, yet.
Disagree, async (edit: in .Net at least) is pretty complex. For instance, from my experience it seems few C# programmers know that it's possible to deadlock if you get it wrong. [0][1] Plenty of people get confused with the basics, too. [2][3]

[0] https://blog.stephencleary.com/2012/07/dont-block-on-async-c...

[1] https://docs.microsoft.com/en-us/archive/msdn-magazine/2013/...

[2] https://stackoverflow.com/a/34681101/

[3] https://stackoverflow.com/a/34799307/

Zig is not .net. async in zig is simple, you just need to understand a few things: what a frame is, what the difference is between a stack frame and a heap frame, what it means (at the machine level) to jump between frames, and the fact that you can't do it in c. That's it!

It really is just a control flow structure in zig (which is why it's a keyword)