Live data from Hacker News

Failing to Learn Zig via Advent of Code

forrestthewoods.com

11–20 of 338 posts

Re: Failing to Learn Zig via Advent of Code

#11
post #5
post #3

Earlier quoted context omitted.

> I see what went wrong here. You tried to lean on documentation and Google, you should have just go for the source code. That sounds rather like a different thing was wrong - not where the author tried to lean: Zig has crap documentation.

Zig documentation isn't crap; the documentation *does not exist* yet. There's an important difference between the two which seems to be ignored. Zig is young. They're spending their time maturing the core ecosystem --- the compiler, the standard library, and so forth. It's perfectly reasonable to expect early adopters to "RTFS/read the fucking source". *When* they start writing documentation, I'd be perfectly happy t…

>Zig documentation isn't crap; the documentation does not exist* yet. There's an important difference between the two which seems to be ignored.*

Well, crap as an offering (what you get atm), not necessarily as in the quality of what little it is. It does though have a reference and documentation page:

https://ziglang.org/learn/

Re: Failing to Learn Zig via Advent of Code

#12
post #6

Yes, error messages in zig needs improving but that's not surprising. Rust error messages where pretty terrible back in the day. I found zig language reference pretty good[0]. It is simple, lot of example. I would find 80% on there and had to google the rest. And as another commenter said, looking at zig source code is actually not a bad idea. The std lib is pretty clear and with comments. My biggest beef with zig is…

I think zigs documentation is wonderful and explains most seemingly esoteric syntax and language options really well.

But if you hit a roadblock it's hard to track down more info. Some of that is due to the lack of adoption, though.

Re: Failing to Learn Zig via Advent of Code

#13
I appreciate the honesty and thoroughness that the author is displaying here.

There are too many posts that focus on successes and embellish the state of affairs.

That said nothing was too surprising about a language that hasn't hit 1.0 yet.

Re: Failing to Learn Zig via Advent of Code

#14
Nice to see a "brain dump" as someone who learned many languages and can easily relate with most of the issues the author faced.

But I take issue with this:

    // Obviously good and easy to read
    return a*(1.0-t) + b*t;

    // Obviously bad and hard to read
    return add(mul(a, 1.0 - t), mul(b, t));
Sorry, but the first one is not obviously good, it's just what you're used to (the second one is indeed bad).

Here's what I would consider obviously good :) for the objective reason that it does not require difficult to track implicit rules about operator precedence:

    1, - t, * a, + (t, * b)
I invented this syntax myself :) but it's extremely obvious once you know how it works.

It should be clear that this is similar to concatenative languages, where you push values onto a stack then apply operations on the stack. The `,` is used for pushing to the stack, basically. But then, it also allows you to "mix" more standard function notation into it... so when you write `a b` that means calling the `a` function with `b` as an argument (think LISP).

Now putting everything together

    1, - t
Should read as `1 minus t` as `- t` is the function `-` being called with one value from the stack, `1`, and one from the "function call" (as if it was LISP `(- 1 t)`).

Next:

    1, - t, * a
Reads as "1 minus t times a" and has no ambiguity: the result of `1, - t` is the first argument to ``, the second argument is `a`, so you get LISP's `( (- 1 t) a)` but reads much more naturally.

Finally, at the end, for readability, we use parens to group the final part of the equation:

    1, - t, * a,  + (t,  * b)
Hopefully it's obvious what happens now?

Does anyone like this form of expression or is just me? I tried to mix the best of LISP with the best of FORTH :) and I really like this.

Re: Failing to Learn Zig via Advent of Code

#15
post #2

I see what went wrong here. You tried to lean on documentation and Google, you should have just go for the source code. It's quite readable, and it's the recommended way to learn for now. Zig has a few peculiarities, it's not stable yet, you kind of have to follow it's development. https://github.com/ziglang/zig/tree/master/lib/std

Yeah I did AoC a few years ago in Zig and found sticking the std path in my project so I could quickly search it was the best tool to figuring out how to do various bits and pieces.

I did the same! Cuz at the time there was no language server available beyond syntax highlighting and linting. But now there is a pretty good language server package available which is really helpful giving autocompleting

Re: Failing to Learn Zig via Advent of Code

#16
post #14

Nice to see a "brain dump" as someone who learned many languages and can easily relate with most of the issues the author faced. But I take issue with this: // Obviously good and easy to read return a*(1.0-t) + b*t; // Obviously bad and hard to read return add(mul(a, 1.0 - t), mul(b, t)); Sorry, but the first one is not obviously good, it's just what you're used to (the second one is indeed bad). Here's what I would…

I think there's a compromise between being recognisable as a mathematical formula and removing operator precedence which is what APL and other array languages do. (a×1-t)+b×t is how you'd write it in APL, no operator precedence but still more familiar.

Re: Failing to Learn Zig via Advent of Code

#17
post #2

I see what went wrong here. You tried to lean on documentation and Google, you should have just go for the source code. It's quite readable, and it's the recommended way to learn for now. Zig has a few peculiarities, it's not stable yet, you kind of have to follow it's development. https://github.com/ziglang/zig/tree/master/lib/std

Recommended way to learn for now? Any sources for that?

Re: Failing to Learn Zig via Advent of Code

#18
> Rust is trying to be a better C++

> Zig is trying to be a better C

I recently started learning Rust by adding snippets to The Quick Snippet Reference [0]. Without any previous knowledge of the language I knew there had to exist a data type for dynamic arrays. After several Stack Overflow searches I found it: Vec. It was very interesting to compare to Python's Array. Getting to understand the drain() method was a refreshing experience. I'm still hesitating about the best way to handle errors (Rust has no exceptions, just panic!), but that will probably become clearer when working with threads. And Rust compiler's warnings and errors are really nice. I'll certainly give Zig a try.

[0]: https://github.com/snippetfinder/The-Quick-Snippet-Reference

Re: Failing to Learn Zig via Advent of Code

#19
As a seasoned Zig programmer, this is good information, though painful to read. A lot of the problems seem to be from a fundamental misunderstanding of Zig's philosophy and very basic things about how the language works. Possibly Zig needs more emphasis on those things in its documentation.

I also have to wonder about a fundamental misalignment of thinking when someone says downloading and replacing a single .exe is tedious, and isn't at all excited about 'Why Zig' list. If none of those things seem like compelling ideas to you then yeah, the language probably isn't for you.

Re: Failing to Learn Zig via Advent of Code

#20
post #14

Nice to see a "brain dump" as someone who learned many languages and can easily relate with most of the issues the author faced. But I take issue with this: // Obviously good and easy to read return a*(1.0-t) + b*t; // Obviously bad and hard to read return add(mul(a, 1.0 - t), mul(b, t)); Sorry, but the first one is not obviously good, it's just what you're used to (the second one is indeed bad). Here's what I would…

> Sorry, but the first one is not obviously good, it's just what you're used to.

That's also what everybody who as been in primary school is used to. Infix notation have its quirks but at least its ubiquitous.

Post reply on HN