Live data from Hacker News

How I turned Zig into my favorite language to write network programs in

lalinsky.com

141–150 of 150 posts

Re: How I turned Zig into my favorite language to write network programs in

#141
post #66

Earlier quoted context omitted.

IMO, it's very wrong. Zig's language is not drastically changing, it's adding a new, *very* powerful API, which similar to how most everything in zig passes an allocator as a function param, soon functions that want to do IO, will accept an object that will provide the desired abstraction, so that callers can define the ideal implementation. In other words, the only reason to not use zig if you detest upgrading or im…

Zealotry in almost every paragraph.

I mean, zig has made writing code something I enjoy again, instead of being something I hate. So I don't mind the title of zealot, I'm sure you meant it as an insult, but I have no intention to apologize for finding some lost joy, and being excited about it.

Re: How I turned Zig into my favorite language to write network programs in

#142
post #47

Earlier quoted context omitted.

IMO, it's very wrong. Zig's language is not drastically changing, it's adding a new, *very* powerful API, which similar to how most everything in zig passes an allocator as a function param, soon functions that want to do IO, will accept an object that will provide the desired abstraction, so that callers can define the ideal implementation. In other words, the only reason to not use zig if you detest upgrading or im…

> Code you write today will still work tomorrow. Haha no! Zig makes breaking changes in the stdlib in every release . I can guarantee you won’t be able to update a non trivial project between any of the latest 10 versions and beyond without changing your code , often substantially, and the next release is changing pretty much all code doing any kind of IO. I know because I keep track of that in a project and can see…

> But TBH, in 0.15 only zig build broke IIRC. However, I just didn’t happen to use some of the things that changed, I believe.

I idle on IRC a lot, and try to help out with questions. From that view, this is the experience of over 90% of users. Minor namespace changes, or calling a function with a different named option. . root_source_file became . root_source_module (and required an additional function call)

Complex changes are almost never required, and IMO shouldn't be expected by most people using zig. Those who might need to make them, already know they're coming because they're already paying attention to the language as a prerequisite for writing such complex code. (Complex here meaning depending on the more esoteric zig stdlib internals)

Re: How I turned Zig into my favorite language to write network programs in

#143
post #54

Earlier quoted context omitted.

Go has tricks that you can't replicate elsewhere, things like infinitely growable stacks, that's only possible thanks to the garbage collector. But I did enjoy working on this, I'm continually impressed with Zig for how nice high-level looking APIs are possible in such a low-level language.

Also, it is about time to let go with GC-phobia. https://www.withsecure.com/en/solutions/innovative-security-... https://www.ptc.com/en/products/developer-tools/perc Note the > This video illustrates the use case of Perc within the Aegis Combat System, a digital command and control system capable of identifying and tracking incoming threats and providing the war fighter with a solution to address threats. Aegis, deve…

I don’t have an issue with garbage collectors. Most code I write is GC’d.

The thing that actually convinced me to learn Rust was for something that I wanted to use less memory; my initial Clojure version, compiled with GraalVM, hovered around 100 megs. When I rewrote it in Rust, it hovered around 500kb.

It’s not completely apples to apples, and the laptop running this code has a ton of RAM anyway, but it’s still kind of awesome to see a 200x reduction in memory without significantly more complicated code.

A lot of the stuff I have to do in Rust for GC-less memory safety ends up being stuff I would have to do anyway in a GC’d language, e.g. making sure that one thread owns the memory after it has been transferred over a channel.

Re: How I turned Zig into my favorite language to write network programs in

#144

Earlier quoted context omitted.

The research Microsoft engineers did on stackful vs stackless coroutines for the c++ standard I think swayed this as “the way” to implement it for something targeting a systems level - significantly less memory overhead (you only pay for what you use) and offload the implementation details of the executor (lots of different design choices that can be made).

> significantly less memory overhead On an OS with overcommit, you might also only pay for what you use (at a page granularity), but this may be defeated if the stack gets cleared (or initialized to a canary value) by the runtime.

Not just cleared. Each stack would get dirtied to the largest depth and that memory never gets reclaimed even if you only hit that deep of stack once. And the OS’s only way to reclaim that is if the allocator frees that page (in practice rarely particularly for glibc) or it gets swapped to disk (expensive since unused pages end up getting swapped too)

Re: How I turned Zig into my favorite language to write network programs in

#145
post #66

Earlier quoted context omitted.

Zealotry in almost every paragraph.

I mean, zig has made writing code something I enjoy again, instead of being something I hate. So I don't mind the title of zealot, I'm sure you meant it as an insult, but I have no intention to apologize for finding some lost joy, and being excited about it.

Well I called it a zealotry not as an insult but to redirect your attention to how this style of expression is seen by others. For instance:

> In other words, the only reason to not use zig if you detest upgrading or improving your code

So you were saying that my own ways of upgrading or improving my code are ruled out, because the only way is via rewriting it for every new language release, right? That's the kind if religious statement I am against.

> Code you write today will still work tomorrow

No it will not and wasn't so far. Where is the room for exchanging the views and experiences if statements are contradicting the facts?

Re: How I turned Zig into my favorite language to write network programs in

#146
post #11

Move Zig, for great justice.

One of the very first internet memes. The zig team should adopt it as the slogan. https://en.wikipedia.org/wiki/All_your_base_are_belong_to_us

There's also https://github.com/allyourcodebase/

Re: How I turned Zig into my favorite language to write network programs in

#147

Earlier quoted context omitted.

> significantly less memory overhead On an OS with overcommit, you might also only pay for what you use (at a page granularity), but this may be defeated if the stack gets cleared (or initialized to a canary value) by the runtime.

Not just cleared. Each stack would get dirtied to the largest depth and that memory never gets reclaimed even if you only hit that deep of stack once. And the OS’s only way to reclaim that is if the allocator frees that page (in practice rarely particularly for glibc) or it gets swapped to disk (expensive since unused pages end up getting swapped too)

> Each stack would get dirtied to the largest depth and that memory never gets reclaimed even if you only hit that deep of stack once

Right, but the issue under discussion was that "right sizing" stacks is hard. You always need to have a stack sized to at least the largest depth.

Pages that get swapped out to disk and never accessed again aren't that expensive. Disk is cheap.

Re: How I turned Zig into my favorite language to write network programs in

#148
post #145

Earlier quoted context omitted.

I mean, zig has made writing code something I enjoy again, instead of being something I hate. So I don't mind the title of zealot, I'm sure you meant it as an insult, but I have no intention to apologize for finding some lost joy, and being excited about it.

Well I called it a zealotry not as an insult but to redirect your attention to how this style of expression is seen by others. For instance: > In other words, the only reason to not use zig if you detest upgrading or improving your code So you were saying that my own ways of upgrading or improving my code are ruled out, because the only way is via rewriting it for every new language release, right? That's the kind if…

> So you were saying that my own ways of upgrading or improving my code are ruled out, because the only way is via rewriting it for every new language release, right? That's the kind if religious statement I am against.

No, you misunderstood the idea I was trying to explain. Skill issue, almost certainly more mine than anybody else, but I try very hard to ask more questions than throw around judgements.

In the context of the question "Am I wrong that because things will change soon, today is a bad day to learn zig" The answer is no, because all the code you wrote, and all the stuff you learned about zig, will still apply when 0.16 is released. There will be no meaningful changes in 0.16 that invalidate everything from 0.15.

do note; I'm omitting details like needing to rename ArrayList to ArrayListManaged (an example change from the previous release) Because I'm trying to practice giving more attention to the pragmatics, over the semantics, because there's more opportunity for growth there contrasted with online pedantry.

So given the most significant change between 0.15.2 and 0.16.0 Will be a new, better API, that I believe from experience (e.g. the previous Readed/Writer change that I originally was skeptical about) will result in my code becoming better.

Thus, the idea is: If you don't enjoy constantly improving code, you won't enjoy Zig throughout it's 0.x cycle. The rate of improvement is very rapid. But as someone who enjoys the pride from committing a change where I see the new code as objectively better. I enjoy improving my code, so this isn't a reason not to, please note, I made my original comment with "In My Opinion". I could probably invent other arguments I could coerce into this context, but that feels disingenuous.

Thus I stand behind my assertion, given the changes you'll likely see, you don't have to upgrade your code, the raw API will still exist, but why wouldn't you? (please keep in mind the pedantry I'm intentionally ignoring as not interesting, I'm not afraid of using sed -i, or editor macros)

> Where is the room for exchanging the views and experiences if statements are contradicting the facts?

how about: This grayhatter fellow seems to be lacking the perspective of reality that I feel is obvious, I should ask why he's ignoring it, omitting it, or ignorant to it. Perhaps he knows something I don't and is bad at explaining it.

vs

I disagree, so I'll instead make a driveby judgement and call him a zealot, instead of being curious.

> Well I called it a zealotry not as an insult but to redirect your attention to how this style of expression is seen by others.

How'd that work? Because I thought you were just trying to be an asshole. For the record, I still don't believe this, it feels much more likely to me this is you trying to retcon an unkind comment you made casually without much thought, rather than taking ownership of the regret over poor communication. Roles reversed, would you believe I meant to encourage exchanging views had I called you a zealot?

Re: How I turned Zig into my favorite language to write network programs in

#149

Isn't this a bad time to be embracing Zig? It's currently going through an intrusive upheaval of its I/O model. My impression is that it was going to take a few years for things to shake out. Is that wrong?

I am working on a ~15K loc project in Zig and have been for over 3 years. Most times a new version comes out there is nothing to do. A half dozen times I've spent as long as half a day updating references to the standard library.

There have been 3 significant problems (2 of them LLVM changes that Zig hasn't adapted to) that have been multi-day frustrations.

We are currently holding at 0.15.1, partly because of the I/O changes (although we're not heavy users of I/O), and partly waiting for the native backend implementations to stabilize.

All that said, we remain very happy with the choice of Zig - it has so many advantages over C/C++ and even (for our application) Rust (we have about 3K LOC in our original Rust implementation).

Is Zig fully mature? Certainly not! Is it mature enough to be highly productive? Certainly!

Re: How I turned Zig into my favorite language to write network programs in

#150
post #145

Earlier quoted context omitted.

Well I called it a zealotry not as an insult but to redirect your attention to how this style of expression is seen by others. For instance: > In other words, the only reason to not use zig if you detest upgrading or improving your code So you were saying that my own ways of upgrading or improving my code are ruled out, because the only way is via rewriting it for every new language release, right? That's the kind if…

> So you were saying that my own ways of upgrading or improving my code are ruled out, because the only way is via rewriting it for every new language release, right? That's the kind if religious statement I am against. No, you misunderstood the idea I was trying to explain. Skill issue, almost certainly more mine than anybody else, but I try very hard to ask more questions than throw around judgements. In the contex…

You don't have any reasons to call me a zealot.. yet. Symmetrism doesn't work.

You wrote so many paragraphs but at the end it's clear for me that you're talking about improving the code for the sake of improving the code - and not where you decide but where language authors decided (because they have changed something).

Post reply on HN