4 ms·
> I can’t think of any other language in my 45 years long career that surprised more than Zig. I can easily say that Zig is not only a new programming language,
by ForHackernews 1y ago
> I can’t think of any other language in my 45 years long career that surprised more than Zig. I can easily say that Zig is not only a new programming language, but it’s a totally new way to write programs, in my opinion. To say it’s merely a language to replace C or C++, it’s a huge understatement.
I don't understand how the things presented in this article are surprising. Zig has several nice features shared by many modern programming languages?
- raincole 1y ago> One may wonder how the compiler discovers the variable type. The type in this case is *inferred* by the initialization. That the author feels the need to emphasize this means either that they haven't paid attention to modern languages for a very long time, or this article is for people who haven't paid attention to modern languages for a very long time. Type inference has left academy and proliferated into mainstream languages for so many years that I almost forgot that it's a worth mentioning feature. > One is Zig’s robustness. In the case of the shift operation no wrong behavior is allowed and the situation is caught at execution time, as has been shown. Panicking at runtime is better than just silently overflowing, but I don't know if it's the best example to show the 'robustness' of a language...
- creata 1y ago> Type inference has left academy and proliferated into mainstream languages for so many years that I almost forgot that it's a worth mentioning feature. I'm not even sure I'd call this type inference (other people definitely do call it type inference) given that it's only working in one direction. Even Java (var) and C23 (auto), the two languages the author calls out, have that. It's much less convenient than something like Hindley-Milner.
- sarchertech 1y ago> Type inference has left academy and proliferated into mainstream languages for so many years that I almost forgot that it's a worth mentioning feature. It’s not common in lower level languages without garbage collectors or languages focused on compilation speed.
- foobar1726 1y agoC++ added auto 14 years ago. Swift had it since day 1 back in 2014 if I remember right. What else is there?
- sarchertech 1y agoC, Ada, Fortran, Pascal.
- jolux 1y agoCompilation speed — OCaml, Go, D, C#, Java “Low-level” languages — Rust, C++, D
- sarchertech 1y agoI meant for focused on compilation speed to apply only to lower level languages. And when I say lower level I don’t really include D because it has a garbage collector (I know it’s optional but much of the standard library uses it I believe).
- jibal 1y agoThat a language has a garbage collector is completely orthogonal to whether it has type inference ... what the heck does it matter what "much of the standard library uses" to this issue? It's pure sophism. Even C now has type inference. The plain fact is that the claim is wrong.
- sarchertech 11mo agoThe x axis is orthogonal to the y axis, so I can’t be interested in the area where x < 1 and y = 5? > what the heck does it matter what "much of the standard library uses" to this issue? It matters in that most people looking for a low level manually memory managed language won’t likely choose D, so for the purposes of “is this relatively novel among lower level, memory managed languages” D doesn’t fit my criteria. > Even C now has type inference. The plain fact is that the claim is wrong. Almost no one is using C23 yet.
- jibal 1y agoAnd it's not caught in ReleaseFast builds ... which is not at all unique to Zig (although Zig does do many innovative things to catch errors in debug builds).
- fuzzy_biscuit 1y agoOf which, perhaps, the author isn't aware? Perhaps the author has very narrow experience in programming languages. Or it's hyperbolic.
- moralestapia 1y ago>Perhaps the author has very narrow experience in programming languages. I got that impression as well. Xi's impressed about types being optional because they can be inferred. That's ... hardly a novelty ...
- forgotpwd16 11mo ago>Only the first and third part are compulsory in Zig, which is kind of puzzling, coming from Java or C. Funny they mention Java that has got type inference few years now. Even C got a weaker version of C++'s auto in C23.
- tialaramex 11mo agoOne of the many things I don't like about C++ is that auto isn't type inference but instead C++ has type "deduction" which is a little different, in some cases a type will be "deduced" even though what you wrote was ambiguous and you may have wanted a different type.
- blahgeek 1y agoThis. Is Zig an interesting language? Yes sure. But “a totally new way to write programs”? No, I don’t see a single feature that is not found in any other programming languages.
- chrisco255 1y agoI feel like the article didn't really hit on the big ones: comptime functions, no hidden control flow, elegant defaults, safe buffers, etc. What Zig really does is make systems programming more accessible. Rust is great, but its guarantees of memory safety come with a learning curve that demands mastering lifetimes and generics and macros and a complex trait system. Zig is in that class of programming languages like C, C++, and Rust, and unlike Golang, C#, Java, Python, JS, etc that have built-in garbage collection. The explicit control flow allows you as a developer to avoid some optimizations done in Rust (or common in 3rd party libraries) that can bloat binary sizes. This means there's no target too small for the language, including embedded systems. It also means it's a good choice if you want to create a system that maximizes performance by, for example, preventing heap allocations altogether. The built-in C/C++ compiler and language features for interacting with C code easily also ensures that devs have access to a mature ecosystem despite the language being young. My experience with Zig so far has been pleasurable. The main downside to the language has been the churn between minor versions (language is still pre-1.0 so makes perfect sense, but still). That being said, I like Zig's new approach to explicit async I/O that parallels how the language treats Allocators. It feels like the correct way to do it and allows developers again the flexibility to control how async and concurrency is handled (can choose single-threaded event loop or multi-threaded pool quite easily).
- fleventynine 1y ago> This means there's no target too small for the language, including embedded systems. It also means it's a good choice if you want to create a system that maximizes performance by, for example, preventing heap allocations altogether. I don't think there's is any significant different here between zig, C and Rust for bare-metal code size. I can get the compiler to generate the same tiny machine code in any of these languages.
- chrisco255 1y agoThat's not been my experience with Rust. On average produces binaries at least 4x bigger than the Zig I've compiled (and yes, I've set all the build optimization flags for binary size). I know it's probably theoretically possible to achieve similar results with Rust, it's just you have to be much more careful about things like monomorphization of generics, inlining, macro expansion, implicit memory allocation, etc that happen under the hood. Even Rust's standard library is quite hefty. C, yes, you can compile C quite small very easily. Zig is like a simpler C, in my mind.
- bsder 1y agoWinning at chess is more "avoid gigantic blunders" than "make brilliant moves". Zig feels like one of the few programming languages that mostly just avoids gigantic blunders. I have some beefs with some decisions, but none of them that are an immutable failure mode that couldn't be fixed in a straightforward manner.