The Zig Programming Language
ziglang.org
ziglang.org
Most recently: https://news.ycombinator.com/item?id=19610199
Other big ones: https://hn.algolia.com/?query=Zig%20points%3E30&sort=byDate&...
Here it is from a few days ago: https://web.archive.org/web/20190430121340/https://ziglang.o...
Even as someone who follows zig closely (from a distance), I was glad to read that front page again to day to refresh my memory about:
* Cross-compiling is a first-class use case
* Zig Build system
Also, IMO Zig has some of the most exciting WASM related stuff going on in my limited experience as an outsider (to WASM). Following Zig's development of WASM capabilities has taught me more things with less confusion.
* [interacting with the DOM from Zig](https://shritesh.github.io/zig-wasm-dom/)
* [zig fmt in the browser](https://shritesh.github.io/zigfmt-web/)
* [implementing the WASI target](https://twitter.com/shritesh/status/1123049218086666246)
One point I noticed: under "Small, simple language", you mention that Rust and C++ have operator overloading. But D does as well:
In other words, you could say they TAKE OFF EVERY ZIG.
This irks me especially badly since the underlying hardware operations are almost always well-defined, but in my "high-level" language I constantly have to worry that I missed something and maybe the compiler will "optimise" my + into something other than addition.
Is there a fully well-defined addition operator in Zig? What about a well-defined shift operator? This might make me, as a professional C programmer, more interested in a new C-like language.
[0] https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins...
[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.63/h...
I don't imagine it's possible to check using a static assert, either.
Would you feel better if it was called "illegal behavior"? In the safe build modes of Zig, integer arithmetic, shifting, wrong union field access, etc is 100% well-defined. Integer overflow is defined to panic. Unless of course you use one of the wrapping arithmetic operators; in these cases it is defined to do wrapping arithmetic.
Integer overflow is usually a bug. If it weren't illegal behavior, zig wouldn't be able to help you catch the bug. That's why clang's integer arithmetic sanitizer only works for signed ints. It's much better for programmers to specify their intent precisely, which is why Zig has different operators for wraparound and assert-it-doesnt-overflow.
Undefined behavior in the unsafe modes is what lets the optimizer make code go fast. C has given undefined behavior a bad reputation, but it's a tool. Zig lets you decide exactly where to opt in or out of the speed/safety tradeoffs.
I'm not immediately seeing how non-wrapping arithmetic can enable significant optimisation. What could be faster than an integer add? If you have an example, I would be very interested (the classic "infinite loop" example is not particularly meaningful in my view).
I always assumed that C left this undefined mostly to support non-two's complement machines, which should probably not be a concern anymore. That's the only explanation I can come up with that explains why unsigned arithmetic is well-defined, but not signed arithmetic.
> Robust - behavior is correct even for edge cases such as out of memory.
> Optimal - write programs the best way they can behave and perform.
> Maintainable - precisely communicate intent to the compiler and other programmers. The language imposes a low overhead to reading code and is resilient to changing requirements and environments.
Now, I work on Zig during the day and I'm training with my brother for our first marathon on nights & weekends. I'm really thankful for you and others' support so that I can do this.
Still in NYC for 1 more year, but my girlfriend is finishing up her master's and looking for Ph.D. programs in California.
Maybe Zig has something in this department, too.
Parameters can have `noalias` on them. This is [currently undocumented](https://github.com/ziglang/zig/issues/1521) and [not yet safety checked](https://github.com/ziglang/zig/issues/476) and there is an [open area of research considering doing it the opposite way](https://github.com/ziglang/zig/issues/1108). Provided that it could be safety-checked, opt-in aliasing has the potential to make Zig even faster. As far as I'm aware, this is currently the only way in which Rust could potentially outperform Zig (and C).
I know that's the theory, but with few exceptions this doesn't seem to have panned out in reality anywhere and C is usually still the gold standard when it come to performance. How many more decades until we get these sufficiently smart compilers?
It'll be especially well suited for this kind of thing because the self-hosted compiler is a long running process that watches files for changes and rebuilds incrementally. [1 minute demo of early progress](https://www.youtube.com/watch?v=b_Pm29crq6Q).
Right now progress is blocking on [The Coroutine Rewrite Issue](https://github.com/ziglang/zig/issues/2377).
[0]
[1]
[2]
(FWIW, M↓ is supposed to be lightweight enough that it's readable inline. The links can get a little long, but I think it's not too hard to skip, and it does have the upshot of not making you have to match up citation numbers. But you're right that the numbered format is more common among posters.)
Personally I like the lightweightness of HN comments, it forces the content to be good over everything else.
Since when can you throw exceptions in Go?
When the raspberry pi 3 hardware boots, it jumps to 0x0. So this is the part where the bootloader loads the new kernel image into memory... starting at address 0!
vs
> (int*)0
They sure make you pay though the nose to cast in zig -- maybe a good thing?
So when you create a pointer out of thin air, you have to inform the type system precisely what kind of pointer it is. That's why it is so much more gnarly than C, it wants you to be explicit.
In a bare-metal environment, there's nothing saying that physical address zero must be unused by the hardware designer.
So I think it's quite the opposite: There's no requirement that address 0 must be unoccupied in any situation, it just so happens that many operating systems choose to leave it unmapped as a debugging aid for developers.
In all seriousness, what questions does it raise? HN has a long history of featuring old and new languages on the front page and often you'll bump into language designers and researchers.
I could be wrong, but I recall the front page featuring more esoteric languages/ideas in its early days. (My username doesn't reflect how long I've been here BTW)
> but can't help but think the time would be better spent adding feature Y to language X, but didn't mean to start anything :-)
When people create new languages, the premise is rarely along the lines of: "I like this language, but if it only had this feature." The truth is there are a whole slew of very legitimate reasons for creating a new language. Many of those reasons are predicated on the idea that the mainstream alternatives have too many wrong features and/or it would be difficult-impossible to fix those flaws by adding new features. As you already know, it's a lot harder to remove a feature from a mainstream language than it is to introduce a new feature, so languages tend to become more complicated as time goes on. New languages tend to provide a clean slate and opportunity to learn from the mistakes of its predecessors.
Another reason to create new languages: New languages often act as the test bed for ideas that eventually end up in mainstream languages. As mainstream languages mature, they rely on more experimental languages to introduce ideas so they can be tested. The only way to test these ideas is to have people write programs in these languages and study the outcome. With that being said, if it wasn't for the experimental languages, mainstream languages would not likely have things like objects, or lambda functions, continuations, type inferencing, polymorphic type systems, etc.
So, if you find yourself being down-voted for asking questions like, "why don't you just add feature Y to language X", it's because you're in the wrong venue. You're not the first to ask the question. I'm not the first to answer it, so you're bound to ruffle feathers.
Zig's program source code is extremely readable. I love it !!
I'll take S<T, U<int, long>, W<int>> over S!(T, U!(int, long), W!int) any day.
I'm pretty sure I'm in the minority with that opinion though.