Live data from Hacker News

Zig 0.11

ziglang.org

141–150 of 193 posts

Re: Zig 0.11

#141
post #95

Earlier quoted context omitted.

> 1. It's typically at least as fast as C, unlike C++/Rust The typical urban myth that never comes with profiler proofs.

TBF, Zig with the LLVM backend may be faster than C or C++ compiled with Clang out of the box just because Zig uses more fine-tuned default compilation options. That's true even for C or C++ code compiled with 'zig cc'. But apart from that the performance should be pretty much identical, after all it's LLVM that does the heavy lifting.

That is a big may, given that it depends pretty much on what is being done in terms of code, and compile time execution (C++ and Rust), and many of the same compiler knobs are also available for C++ code, if not even more.

And was you point out, at the end of the day it is the same LLVM IR.

Re: Zig 0.11

#142

Earlier quoted context omitted.

I'm a Zig fan and all, but you should probably check if your C/C++/Rust code uses the equivalent of "-march=native", that might already be responsible for most of the performance difference between those and Zig - they all use the same LLVM optimization passes after all, so excluding obvious implementation differences (like doing excessive heap allocations) there isn't any reason why one would be faster than the othe…

The point was typical, typical Rust code is using Vec , typical Zig code is using arenas. Typical Rust code is using smart pointers, typical Zig/C code prefers plain, copyable structs. It is 100% possible to use such style in Rust/C++ (and then the performance will be same or maybe even in favor of rust, it might be the case) but people usually do not do that.

It shouldn't be hard to make Zig go to top place then, which is great opportunity to shine, given that they are still missing Zig entries,

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

https://www.techempower.com/benchmarks/

Re: Zig 0.11

#143

Earlier quoted context omitted.

All programs can be incorrect. You cannot forbid unsafe code. Its use is necessary to implement basic functionality.

You absolutely can forbid unsafe code (within a scope of a particular codebases) and some projects happily do it. "The use is necessary" = absolutely not. Lots (most) of projects wouldn't ever need to dip into unsafe code. And then there's another category where authors think they do because "that's how they would do it in C++", but in reality they don't.

> You absolutely can forbid unsafe code (within a scope of a particular codebases) and some projects happily do it.

No, you can't. The standard library contains 'unsafe', all over the place. Even if you discount that, large swathes of the library 'ecosystem' contain 'unsafe' and those that don't? They depend on libraries that do.

>"The use is necessary" = absolutely not.

Relying on some unsafe code that someone else has written is still using unsafe. The code in your dependencies is code that you use, that you depend on, and that affects you. It is meaningless to say you 'don't use unsafe code' if your code is just plumbing together a bunch of libraries that contain 'unsafe' code.

>And then there's another category where authors think they do because "that's how they would do it in C++", but in reality they don't.

This common sentiment from Rust developers is, just like all their other claims, totally unfounded. 'Oh you don't really need unsafe'. Then you explain why actually, yes, you do need unsafe and you're told that you're describing a 'special case'. Well guess what, every project is a special case in some respect. Every nontrivial project is going to have something that requires unsafe code, whether it's interfacing with hardware or using a system call that hasn't been wrapped or using a third party library or implementing a complex data structure or one of many many other various things that require 'unsafe'.

And even if you don't use 'unsafe' anywhere in your code and you somehow magically know that all of your dependencies are perfectly written and all the soundness bugs in the Rust compiler are fixed (at which point you might well ask: if you can assume all your Rust dependencies are perfect, why can't you assume all your C dependencies are perfect? And also, how can you be confident in any 'unsafe' code being safe if the rules for what is 'safe' to do in unsafe aren't even written down anywhere?), then what do you get? Almost nothing. 'Memory safety' is a very narrow category. As I said above, it means 'things Rust protects against'. It wasn't a term that was popularly used before Rust became known in the way Rust means it. Even to most Rust developers and contributors, right up until release it was widely assumed that it included leak freedom. And then a couple of weeks before release that was quietly dropped and memory-holed when it was shown that you could introduce memory leaks trivially. Large amounts of supposedly 'safe' unsafe code had to be rewritten and redesigned.

Rust just doesn't give you any the guarantees that Rust evangelists love to claim. Even in memory safety. In fact, almost every language out there is MORE safe than Rust, in the sense in which Rust claims to be memory-safe! The only ones that aren't are those without garbage collection.

Re: Zig 0.11

#144
post #72
post #5

What are the use cases for zig? The website says general purpose and tool chain but people who have used it, what it excels at?

Zig has a decent chance of being an actual embedded device (ie. no operating system) programming language. In my opinion, Zig seems likely to grow the necessary bits to be good at embedded while Rust is unlikely to figure out how to shrug off the clanky bits that make it a poor fit for embedded devices. However, I'm a personal believer that the future is polyglot. We're just at the beginning of shrugging off the C AB…

> clanky bits that make it a poor fit for embedded devices.

What do you see as "clanky bits that make it a poor fit" for such a broad range of stuff as "embedded devices" ?

Embedded goes at least as far as from "It's actually just a Linux box" which is obviously well suited to Rust, to devices too small to justify any "high level language" where even C doesn't really fit comfortably. Rust specifically has no ambitions for hardware too small to need 16-bit addresses, but much of that range seems very do-able to me.

Re: Zig 0.11

#145
post #38

Earlier quoted context omitted.

That is absolutely true. But but you can write memory-bug-free code in Zig but you cannot prevent heap allocations in most of the languages listed in the article, making it outright impossible to write certain software in them.

Sure one can write memory-bug-free code in x86 assembly too. But how can you prove it? ATS is an example of a low-level systems language where you can prove it.

You can't prove it in Rust either.

Re: Zig 0.11

#146
post #71

Earlier quoted context omitted.

Agreed, it's absurd. Jail time for writing javascript otoh...

I guffawed, and I'm not afraid to admit it.

And this attitude is why it's a serious issue in our industry. You clearly don't take security seriously, to the point that it's a laughing matter for you.

Re: Zig 0.11

#147
post #141

Earlier quoted context omitted.

TBF, Zig with the LLVM backend may be faster than C or C++ compiled with Clang out of the box just because Zig uses more fine-tuned default compilation options. That's true even for C or C++ code compiled with 'zig cc'. But apart from that the performance should be pretty much identical, after all it's LLVM that does the heavy lifting.

That is a big may, given that it depends pretty much on what is being done in terms of code, and compile time execution (C++ and Rust), and many of the same compiler knobs are also available for C++ code, if not even more. And was you point out, at the end of the day it is the same LLVM IR.

That was the point I was trying to make, Zig isn't inherently faster than the other three. It just uses different default compilation options than clang, so any gains can be achieved in clang-compiled C or C++ too by tweaking compile options (and maybe using a handful non-standard language extensions offered by clang). Other then that it's just LLVMs "zero cost abstraction via optimization passes" and this works equally well across all 4 languages.

Or: the "optimization wall" in those languages is the same, only the effort to reach that wall might be slightly different (and this is actually where Zig and its stdlib might be better, it's more straightforward to reach the optimization wall because the Zig design philosophy prefers explicitness over magic)

Re: Zig 0.11

#148

I wanted to try learning Zig, but found the resources to be incomplete and lacking in examples. Rust (or Go) in comparison has a plethora of online resources with great examples. I realize Zig is just 0.11, but wondering what resources people relied on to pick it up?

I’ve been using the language reference [0] and also just browsing the standard library source code [1] for examples.

[0]:https://ziglang.org/documentation/0.11.0/

[1]:https://github.com/ziglang/zig/tree/master/lib/std

Re: Zig 0.11

#149

Earlier quoted context omitted.

I guffawed, and I'm not afraid to admit it.

And this attitude is why it's a serious issue in our industry. You clearly don't take security seriously, to the point that it's a laughing matter for you.

If you can't see why jailing people for writing JS is a comically absurd concept…

Re: Zig 0.11

#150

I wanted to try learning Zig, but found the resources to be incomplete and lacking in examples. Rust (or Go) in comparison has a plethora of online resources with great examples. I realize Zig is just 0.11, but wondering what resources people relied on to pick it up?

I’ve been using the language reference [0] and also just browsing the standard library source code [1] for examples. [0]: https://ziglang.org/documentation/0.11.0/ [1]: https://github.com/ziglang/zig/tree/master/lib/std

That's important: don't be afraid to look into the stdlib source code when questions arise. It's easy to read and stuff is easy to find, and it's also a great teacher.
Post reply on HN