8 ms·
The Zig Programming Language
- FraaJad 7y agoThe website has been refreshed. The feature highlights section on the front page gives many examples of the features with code samples. 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.
- AndyKelley 7y agoShoutouts to Shritesh Bhattarai who has been spearheading that work. Some cool demos he has produced in the last couple weeks: * [interacting with the DOM from Zig](https://shritesh.github.io/zig-wasm-dom/ https://shritesh.github.io/zig-wasm-dom/) * [zig fmt in the browser](https://shritesh.github.io/zigfmt-web/ https://shritesh.github.io/zigfmt-web/) * [implementing the WASI target](https://twitter.com/shritesh/status/1123049218086666246 https://twitter.com/shritesh/status/1123049218086666246)
- gmfawcett 7y agoThe Web site redesign is looking really good. Clean and minimalist. One point I noticed: under "Small, simple language", you mention that Rust and C++ have operator overloading. But D does as well: https://dlang.org/spec/operatoroverloading.html https://dlang.org/spec/operatoroverloading.html
- hathawsh 7y agoWhat is "optimality", described as one of the three primary goals of the language? Zig is intended to be "optimal" in what dimension?
- dinglejungle 7y agoFrom the Documentation page[1]: > 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. [1] https://ziglang.org/documentation/master/ https://ziglang.org/documentation/master/
- hathawsh 7y agoThanks. Based on that definition of optimal, it sounds like Zig intends to be optimally predictable and performant. Other languages would define "optimality" differently: Python aims to optimize readability, Lisp aims to optimize expressiveness, Erlang aims to optimize availability, and so on. I don't mean to nitpick, but choosing an excessively general term as one of the three primary goals seems like a missed opportunity to focus the Zig language community on specific goals.
- ryanworl 7y agoI've been supporting this project on Patreon for $30/month for 10(?) months now and it is remarkable how much progress has been made. Replacing C would be quite a revolution, but I hope it happens.
- asdfman123 7y agoI really hope it takes off.
- mschwaig 7y agoI am amazed how much money and effort goes into building software on top of the ancient wasp nest that is C. People boldly taking on that issue deserve our support.
- loeg 7y agoAs a C (not C++!) programmer, Zig looks more like what I want in a C-replacement than something like Rust.
- ggambetta 7y agoI really, really hope every time they are preparing to push a release, the process involves someone saying "RELEASE ZIG" and someone else voicing their approval by saying "FOR GREAT JUSTICE".
- AnIdiotOnTheNet 7y agoZig is released constantly if you count the master builds that are published to the site every time a change is merged. In other words, you could say they TAKE OFF EVERY ZIG.
- overgard 7y agoThey're really missing an opportunity to have panics say "WHAT HAPPEN ?"
- gravypod 7y agoDoes zig have tooling to serve a language server? It would be cool to get IDE support.
- AndyKelley 7y agoIt's [planned](https://github.com/ziglang/zig/issues/615 https://github.com/ziglang/zig/issues/615). The feature will only be present in the self-hosted compiler, not the "stage1" C++ compiler, which is what is currently shipped. 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 https://www.youtube.com/watch?v=b_Pm29crq6Q).
- gravypod 7y agoThat's a very interesting architecture for compiler. Is that code in your github repo?
- AndyKelley 7y agoYes: https://github.com/ziglang/zig/tree/master/src-self-hosted https://github.com/ziglang/zig/tree/master/src-self-hosted Right now progress is blocking on [The Coroutine Rewrite Issue](https://github.com/ziglang/zig/issues/2377 https://github.com/ziglang/zig/issues/2377).
- vxNsr 7y agoJust so you know HN doesn't support reddit markup for links, you can only post the url for the link directly, not highlight text. That's why most ppl here use a footnote index to post links [0][1][2]etc [0] [1] [2]
- deathanatos 7y agoIt's not "reddit markup", it's just Markdown. A rather common format, not specific to Reddit. And honestly, I wish HN would grow a few features in this area — links and blockquote would be really nice. It'd be good to have common formatting s.t. common formatting can just get out of the way, so that we can all focus on the discussion, instead of parsing text with our eyeballs. (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.)
- cats_ 7y agomove zig
- dmuth 7y agoUpvote for username.
- DiseasedBadger 7y agoI actually have never wondered before: is it ever valid to use pointer 0?
- AndyKelley 7y agoYes, and here is an example: https://github.com/andrewrk/clashos/blob/91f45cff49128b3322f98cc78ed08df5bcec35cb/src/main.zig#L81 https://github.com/andrewrk/clashos/blob/91f45cff49128b3322f... 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!
- __turbobrew__ 7y ago> @intToPtr([]allowzero const u8, 0 [0..@ptrToInt(&__end_init)] vs > (int*)0 They sure make you pay though the nose to cast in zig -- maybe a good thing?
- AnIdiotOnTheNet 7y agoZig's type system tries to be aware of what its pointing to. Is it an array of comptime known length? An array of unknown length? An array of runtime known length? or a single item? Is it mutable? What's its alignment requirement? etc. It even has a pointer type for "something that came from C, who the hell knows". There is an accepted proposal to have pointer types for null-terminated blocks of memory too. 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.
- jforberg 7y agoIn a system with virtual memory, you would typically ensure that address 0 (i.e. the lowest page) is unmapped. This causes an error condition if the address is ever read or written, which is useful because 0 is used as a placeholder value (i.e. NULL) in many situations. But this is a conscious decision by the system not to use this page, there's nothing technically stopping you from mapping it and putting some data at virtual address 0. 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.
- revskill 7y agoI'm glad that Zig doesn't use <,> characters. To me <,> is the most annoying things to read in source code. Zig's program source code is extremely readable. I love it !!
- skocznymroczny 7y agoI don't mind < > , especially when it's generics/templates. For example, D chose !() for it, and it's much harder for me to read. I'll take S<T, U<int, long>, W<int>> over S!(T, U!(int, long), W!int) any day.
- julesnp 7y agoFor some reason, I've always preferred OCaml's style of generics notation: (T, (int, long) U, int W) S I'm pretty sure I'm in the minority with that opinion though.
- axaxs 7y agoSame. I can't explain why, but when I see angle brackets I lose interest in a language.
- chadcmulligan 7y agoThere seems to be a new programming language every day on HN, it raises many questions
- steego 7y agoAre you new here? 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)
- chadcmulligan 7y agodidn't mean to ruffle any feathers, it seems like the ones that have appeared lately are "new language like language X but does Y". Maybe I'm getting old and grumpy 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 :-).
- steego 7y agoYou didn't ruffle my feathers, but I can easily see how you'd ruffle the feathers of someone who's invested a tremendous amount of time into a new language. > 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.
- otras 7y agoGlad to see you still going strong! I’ve been a supporter on Patreon since your job-quitting announcement 10 months ago. How has it been working full time on Zig? Did you end up relocating from NYC?
- AndyKelley 7y agoI'm happier than ever before. When I had a day job, I worked on Zig nights & weekends, and I was pretty stressed out. 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.
- hestefisk 7y agoInteresting language. I do find the statements a bit ‘absolute’, eg higher performance than C. In terms of what? Floating point, concurrent processing, ...?
- mschwaig 7y agoIn their phylosophy C and zig both aim to do very little behind the scenes beyond what you explicitly express in your code. On a technical level Zig re-uses fancy C compiler infrastructure in the form of LLVM. So that gets them pretty close. The advantage tha zig has over C is that it gets designed decades later when we have learned so much about what is good or bad or fast or slow about C.
- hestefisk 7y agoThe same could be said for Go. And it still doesn’t explain the statement on performance. I see nothing close to objective benchmarks. I think the language is interesting though and hope this will be published.
- nine_k 7y agoC's simplicity leads to fewer guarantees, this makes some optimizations impossible. E.g. Fortran used to be faster than C in numerical code, because the guarantee of no aliasing allows for more aggressive optimizations. Maybe Zig has something in this department, too.
- AndyKelley 7y agoCross posting from https://www.reddit.com/r/programming/comments/bjwhm5/introduction_the_zig_programming_language/emc30to/ https://www.reddit.com/r/programming/comments/bjwhm5/introdu... Parameters can have `noalias` on them. This is [currently undocumented](https://github.com/ziglang/zig/issues/1521 https://github.com/ziglang/zig/issues/1521) and [not yet safety checked](https://github.com/ziglang/zig/issues/476 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 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).
- retrobox 7y agoReading through some of the examples in the documentation, I love the look of this. It really does feel easy to read.
- jforberg 7y agoThe section about overflow put me off. Undefined semantics is one of my least favourite parts of C. It seems from the article that Zig is leaving not only signed overflow but also unsigned overflow as undefined (or runtime crash in "safe" mode, which is equally as bad). In C at least unsigned arithmetic is well-defined so I could get away with some casting back and forth. 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.
- roblabla 7y agoYou can use +% to have a fully defined wraparound addition: https://ziglang.org/documentation/master/#Wrapping-Operations https://ziglang.org/documentation/master/#Wrapping-Operation.... For lshift, there is @shlWithOverflow.
- jforberg 7y agoNice! That's something I often wish GCC had.
- MaxBarraclough 7y agoI google'd this - GCC comes close. There are built-ins for overflow-checking add/sub/mul arithmetic. [0] There are also compiler flags to enable explode-on-overflow or wrap-on-overflow, except for division and remainder. [1] [0] https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins... [1] https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Signed-Overflow-Advice.html https://www.gnu.org/software/autoconf/manual/autoconf-2.63/h...
- jforberg 7y ago
- Improvotter 7y ago> C++, D, and Go have throw/catch exceptions, so foo() might throw an exception, and prevent bar() from being called. Since when can you throw exceptions in Go?
- pokstad 7y agoProbably referring to panic and recover.
- joshbaptiste 7y agoAndrew does post YouTube videos of his coding sessions which teaches me a lot of Zig and gives me pointers on using Vim as an overall IDE https://www.youtube.com/user/superjoe30 https://www.youtube.com/user/superjoe30
- dang 7y agoGreat project, but it has had more than one major discussion on HN in the last year, which makes this submission a dupe (see https://news.ycombinator.com/newsfaq.html https://news.ycombinator.com/newsfaq.html). Most recently: https://news.ycombinator.com/item?id=19610199 https://news.ycombinator.com/item?id=19610199 Other big ones: https://hn.algolia.com/?query=Zig%20points%3E30&sort=byDate&dateRange=all&type=story&storyText=false&prefix&page=0 https://hn.algolia.com/?query=Zig%20points%3E30&sort=byDate&...
- dinglejungle 7y agoFYI, the main page of ziglang.org was completely overhauled, which is why this was submitted. Here it is from a few days ago: https://web.archive.org/web/20190430121340/https://ziglang.org/ https://web.archive.org/web/20190430121340/https://ziglang.o...