Out of curiosity, what's the state of the world regarding Zig's stdlib? While the base language docs seem like they're in a pretty good state, the stdlib is still largely undocumented. Is this because it's unstable? Or is the lack of docs there due to lack of time/resources? Would love to get some clarification. Thanks!
[1]: https://ziglang.org/download/0.5.0/release-notes.html#toc-UE...
[0] https://twitter.com/andy_kelley/status/1176561072398098432
Perhaps I could see some toy ransomware bootkit demanding the user to pay up or face using your computer with comic neue or comic sans as the default unchangeable font.
For the uninitiated:
As far as Comic Sans-like fonts go it's quite nice
[1] https://github.com/ziglang/zig/wiki/Why-Zig-When-There-is-Al...
There is really only one thing that I would say goes beyond keeping the language simple as possible: the async stuff. But I think it will probably be totally worth it. The async implementation looks a lot more elegant than anything I've seen so far, and it could be extremely useful in the embedded world, which is one of the places where C is dominant. It might make the language a bit more complicated, but it will make the resulting code much more simpler for a lot of applications, without compromising other goals like safety and efficiency.
Zig is still much, much closer to C than C++. If you don't think so, then you're vastly underestimating the complexity of C++.
make a feature unwanted in C, worse. nice.
These kinds of claims make me so dubious for a language. Also who is trying to switch from C to get an ever-so-slightly performance improvement? That use-case goes to specialized hardware such as FPGAs.
* The reference implementation uses LLVM as a backend for state of the art optimizations.
* What other projects call "Link Time Optimization" Zig does automatically.
* For native targets, advanced CPU features are enabled (-march=native), thanks to the fact that Cross-compiling is a first-class use case.
* Carefully chosen undefined behavior. For example, in Zig both signed and unsigned integers have undefined behavior on overflow, contrasted to only signed integers in C. This facilitates optimizations that are not available in C. Zig directly exposes a SIMD vector type, making it easy to write portable vectorized code.
So the argument is "exact same compiler as C/C++, but more opportunities for optimization thanks to better semantics and better access to native instructions". This seems reasonable on its face, so care to elaborate on the doubt?
The arguments for not switching from C are often performance or target related, so a language that purports to be an alternative to C would want to point out that those issues aren't a problem.
The reasons to switch away from C are numerous and well documented.
Huh, that's a strange choice. What's the safety story for Zig? Are these always undefined, or is that only in an "unchecked" build?
https://github.com/ziglang/zig/issues/2007
I wonder though, does it already have socket support? that could be a stopgap for me. Edit, looks like it doesnt have sockets either:
https://github.com/ziglang/zig/issues/1271
Edit 2, looks like it does:
https://github.com/ziglang/zig/blob/5026db1d/lib/std/net.zig...
https://github.com/ziglang/zig/blob/5026db1d/lib/std/os.zig#...
example: https://github.com/donpdonp/zootdeck/blob/master/src/net.zig
For me this is sort of important because languages not having standard coding style end up 10000 coding styles. Rust fmt is an excellent example for avoiding that. Does anybody use Zig + fmt?
I know they have something. https://github.com/ziglang/zig/issues/1523
The end even has a link to a web-based version of it.
All of these languages seem to be statically compiled, and they all seem to promise both performance and safety. Rust and Go are discussed all the time on HN, so I expect most of us here have a reasonable notion of their relative benefits, for example, performance compared to ease of learning.
What about these lesser discussed languages Zig, Nim, and Crystal? Are their runtime performances comparable to one another? Are they equally safe to program in? What are their relative strengths? Or does it just come down to syntax preference?
I think there's value in having a lot of choices to program in, so I'm not asking which language is "best" any absolute sense. We're better off for having all of these languages coexisting. I'm just asking if anyone with experience in the three of them has any insight or impressions of their relative merits.
I think in the end it's really up to your tastes which you prefer. Have a look at the tenets of each of the languages and see which resonates with you.
- Cross-compilation is trivial (I haven't dug too deeply into the cross-compilation story on Nim and Crystal, but Zig's is front-and-center)
- Allocations are explicit (functions that require allocating memory do so by accepting an allocator as an argument)
- Windows support seems to be better than with Crystal (which means I can use Zig for desktop programming for my dayjob, since at work most of the PCs here run Windows 10; not that I would at the moment, given that it's very much not production ready yet, but still)
- I strongly dislike Python's syntax, and therefore strongly dislike Nim's syntax (I also somewhat dislike C's syntax - and therefore Zig's - but not nearly as strongly)
- Zig's build system is pretty great (albeit not exactly intelligent when it comes to finding system header and library paths, I've noticed)
That said, there are some downsides to Zig that I'm hoping can be resolved (whether by someone else or - if I get comfortable enough with it - myself):
- Profound lack of standard library documentation
- I like Crystal's syntax better
- C++ interoperability is practically nonexistent (though it might be possible to write small C++ shims that link against Zig-outputted headers; not sure if Zig's included C compiler can compile those, but if it can, then this would be easy to integrate into the build process)
I'm curious about the tools zig offers around doing asyc work while guaranteeing certain invariants, and how the @Frame builtins work with that, but I'm guessing that's going to be elaborated on in a future post.
I'm quite enjoying watching progress updates, relevant examples and Q&A :)
Can we have a consistent function notation
fn name(a: int, b: int) -> void {}
This also helps with clean functional type arguments.
swift and rust support this.
A single consistent notation will be helpful for new polyglots.
Can anyone familiar with zig tell me how well it works with more macro heavy libraries? Something like GTK (https://developer.gnome.org/gtk-tutorial/stable/c450.html) or something with generics.
function xxx()
instead of fn xxx()
what are we trying to save here?Also would be nice to do import instead of @import. More readable I think.
Afraid to dig deeper as I do not have time to play with the languages that I can not yet use in production.
Re: fn v. function (v. fun v. def v. defun v. defn v. define v. proc v. sub v. label v. the cornucopia of other options here): I don't think it's all that big of a deal. fn does happen to be short, which means more actually-useful information can fit into the same line, so I guess that's nice. The choice of keyword for function definition feels like a really weird criticism.