Live data from Hacker News

Failing to Learn Zig via Advent of Code

forrestthewoods.com

151–160 of 338 posts

Re: Failing to Learn Zig via Advent of Code

#151

I don't understand people recommending reading the source code to learn. Source codes can be really daunting because there are so many things going on. There can also be "tricks" using advanced language features, which defeats the purpose if you're trying to learn as a first timer. Also, "read the source" is, at least to me, an admission that there is no valid documentation 90% of the time. Reading the source of a to…

Blog author here! I read the source quite a few times.

Almost every language has a dynamic array of some sort. They all do the same thing. They all have slightly different names. push / push_back / add / append. size / length / len / count. If you don't already know the name of a function then finding it is in a sea of text is very difficult and not fun.

Zig ArrayList: https://github.com/ziglang/zig/blob/master/lib/std/array_lis... C++ Vector: https://en.cppreference.com/w/cpp/container/vector Rust Vec: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html

Sometimes I just want to see a list of functions. I can skim a list of 40 functions in seconds. Scrolling 800 lines of code and trying to pick out every single function takes much longer and is much more error prone.

Re: Failing to Learn Zig via Advent of Code

#152
To me the biggest difference between Rust and Zig in practical terms is that Zig does not offer statically safe resource management like Rust does, and as far as I know they have no intentions of doing so in the future because they think it’s less important than all this stuff about control flow. There are a lot of interesting ideas in the language but my disagreement with them on this issue is so fundamental that I don’t feel compelled to investigate it further.

Nonetheless I had gotten the impression from many posts on here before that Zig was a lot closer to finished than it really is, it seems like they’re not quite half way to something as polished as Rust 1.0. It is probably unfair to judge the language against Rust in its current state. Hopefully in a few years they will have figured out the memory safety problems and the stdlib documentation will stabilize more.

Re: Failing to Learn Zig via Advent of Code

#153
post #136

The author is not excited about "No hidden control flow", but as a code reader it's really nice. It means that the only context you need in order to understand the control flow of a given line of code is that line itself. You don't need to check for overloaded operators, exceptions, virtual functions, etc. It's this property of Zig that I think makes "read the stdlib source" actually a viable strategy for learning ho…

What did you think of the example in the article about vector math? Seems like that's an area where operator overloading actually makes the code more readable. Maybe it depends on the problem domain you're working in.

I agree that with vector math, overloaded arithmetic operators are easier to read. However, I don't see how you could add "overloading, but only for actual math" - once it's in, people will repurpose it for all kinds of cursed purposes.

The implementation would probably be ugly, but I wonder if it could be implemented by using a comptime string to represent the operation, e.g. something like:

    fn doMath(comptime op: []const u8, args: anytype) MathReturnType(op, args) {
        // TODO: implement me
    }

    const result = doMath(
        \\a + b
        ,
        .{ .a = a, .b = b }
    );
Where the implementation would call `.add` etc on the parameters when infix operators were used.

Re: Failing to Learn Zig via Advent of Code

#154
post #89

Earlier quoted context omitted.

Why? This doesn't make sense to me, for a few reasons reasons: 1) I'm looking for the best, not the best by programmer hours or growth. Zig has accomplished a lot and I'm impressed by the work of people on it. But it's still a strictly worse option than many others. I think it's poised to be great in the future, but right now it's not good enough. 2) Organizations always become less effective as they grow, Zig being…

> I'm looking for the best, not the best by programmer hours or growth. You seem to be ignoring that the thread you are replying stems from people challenging this statement: “Zig is 6 years old. Rust had much better documentation at this stage of development.”

Rust was announced in 2010. Rust in 2016 had documentation in better shape than current Zig, and was past 1.0. The difference seems to be that Zig was announced earlier in development. Considering how much I hear about Zig, I expected it to be futher along its development. Maybe not a 1.0, but at least good documentation to get started, to get lots of newcommers and thus lots of feedback. That's not the case, partially because the people behind Zig want to take a different approach, partially because it was announced earlier. This is perfectly fine, it's just surprising and a bit disappointing for people like me that watch Zig from afar. I understand that I'm not the main audience for Zig and have no problem with that.

Re: Failing to Learn Zig via Advent of Code

#155
post #107

Earlier quoted context omitted.

What are you talking about? We're talking about the current state of Zig. From this thread of comments, on your messages: > It's important to consider that for zig at this stage, "not having valid documentation" is expected. At some point not having valid docs will become considered to be unacceptable. > Seriously, comparing by timeline like that is an unfair comparison. The article is about failing to learn right no…

> The vast majority of people, when faced with a language that looks not great at the moment but could have a bright future, will react with "I'll take a look again in a year or two". You argue for the opposite, that people should contribute to Zig instead. I'm trying EXACTLY to do that, and it's not logically inconsistent. I'm not sure why you are deliberately conflating "using a language" with "putting a (small) am…

> The exact point is "if you can't afford be present-focused in one way, be future-focused in a different way".

That would work if Zig was the only language in development in that space. It isn't.

Re: Failing to Learn Zig via Advent of Code

#156
post #24

I like zig, but agree with many of the points here. A couple of thoughts below, > Zig reference documentation badly needs examples. Can't figure out how to use std.fmt.parseInt. While yes, Zig documentation badly needs examples, I'm not sure this particular criticism is justified. I would have thought that the usage of parseInt, was fairly obvious from the type-signature: parseInt(comptime T: type, buf: []const u8, r…

> I would have thought that the usage of parseInt, was fairly obvious from the type-signature:

Blog author here. In hindsight yes it's obvious.

I think my problem was a lack of understanding of comptime types. They're a little different from C++ / Rust since they're passed as args. Looking back I think I found the Zig docs less "sticky" than other languages. The concepts are familiar but just new enough I don't understand and don't fully remember them.

There's a point while working on AoC that I wasn't sure if Zig had first-class runtime types or not. It has comptime types and it also has a TypeInfo built-in with some degree of reflection? Is that runtime reflection maybe? I think partially? I honestly don't know.

Either way I was confused. :)

Re: Failing to Learn Zig via Advent of Code

#157
post #38

> [Compiling] takes about ~3 seconds minimum which is frustratingly slow I feel old, I know that any time is an opportunity to get distracted but 3 seconds doesn't strike me as a long compile time. Or is that a typo for 30, which would make more sense, which is definitely long enough to be a frustration?

That complaint was weird, here's my day 7 solution in zig built in release mode: $ time zig build-exe ./a.zig -O ReleaseSmall real 0m1.728s user 0m1.544s sys 0m0.292s Which is actually slower than running the entire solution in debug mode: $ time zig run a.zig -- input.txt min 337 342641 min 470 93006301 real 0m1.138s user 0m0.789s sys 0m0.270s Totally possible that it's much slower on the dev's machine, but if he's…

Blog author here. I'm an Intel i7-8700k desktop. A few years old at this point, but quite beefy.

Maybe this is a Windows issue? If I run "zig build" and then immediately run "zig build" again it still takes 3 seconds.

Re: Failing to Learn Zig via Advent of Code

#158
post #146
post #127

Earlier quoted context omitted.

Quite the opposite. The very broad-brush overview is that zig aims to replace C and rust aims to replace C++... but among other issues with that analogy, that can't happen unless zig and rust have a dead-simple integration story.

I've only ever really seen it in Zig communities that Rust is closer to C++ In Rust communities, it's often pitched as alternates to both, but closer to C. I suppose it's all relative, but the comparison of rust to c++ seems external

Yes, I also had the impression Rust is a C replacement.

Re: Failing to Learn Zig via Advent of Code

#159
post #152

To me the biggest difference between Rust and Zig in practical terms is that Zig does not offer statically safe resource management like Rust does, and as far as I know they have no intentions of doing so in the future because they think it’s less important than all this stuff about control flow. There are a lot of interesting ideas in the language but my disagreement with them on this issue is so fundamental that I…

Yeah, I've tried out zig and it's about at the point where Rust was when there were like 5 different pointer sigils and a GC was still included.

Re: Failing to Learn Zig via Advent of Code

#160
post #50

Earlier quoted context omitted.

I beg to disagree with you. I'm newbie and I still found that zig standard library still daunting to read. When people said it's very accessible, I'm curious what people mean by that? What makes it very accessible?

> I'm newbie and I still found that zig standard library still daunting to read If you're a newbie, why are you learning an experimental language?

Even noobs can love languages. I'm a noob at compilers and I routinely beat my head against implementation. I do this, not because I will succeed, but because I enjoy the challenge.
Post reply on HN