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…
Failing to Learn Zig via Advent of Code
171–180 of 338 posts
Re: Failing to Learn Zig via Advent of Code
#172Earlier quoted context omitted.
What is a case where floating-point addition is more complicated than a string concatenation? Are you referring to some obscure architecture?
One example would be an architecture on which hardware floating point is not implemented, and has to be emulated in software. This isn't uncommon in embedded, many ARM Cortex-M cores are like this AFAIK.
Things are less primitive these days but the memory still brings a smile to my face.
Re: Failing to Learn Zig via Advent of Code
#173Nice 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…
The first one is good because its what most people are used too - there's little that can be objectively said about notation once you reach a big enough audience. I could invent a word editor that produced documents from top to bottom rather then left to right and I could invent a million reasons what it's better, but that hardly matters.
Personally I don't think Polish notation is all that revolutionary for humans, it's just easier for computers; however just like anything else the human brain is quite malleable, and if you spend a year doing equations in polish notation you will come to prefer it.
Re: Failing to Learn Zig via Advent of Code
#174Earlier quoted context omitted.
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.
Speaking as somebody who mostly codes for *n?x but has some windows users of their libraries, I've run face first into "everything I know about build optimisation is inapplicable on windows" more than once.
('everything' is admittedly slightly hyperbolic but I'm sufficiently bad at windows tooling that it always feels that way)
Re: Failing to Learn Zig via Advent of Code
#175Re: Failing to Learn Zig via Advent of Code
#176Earlier quoted context omitted.
Why does something as basic as uppercasing a string or decoding latin1 require a third-party library? I would expect that to be part of stdlib in any language. Also, why does that third-party library come with its own string implementation? What if my dependency X uses zigstr but dependency Y prefers zig-string https://github.com/JakubSzark/zig-string >? Basically all languages designed in the past 30 years have at l…
Those are all valid points. At the moment I believe Zig has decided to leave full unicode support out of std because they don't want language releases dependent on unicode updates.
I'm sorry, what do you mean by this?
Re: Failing to Learn Zig via Advent of Code
#177Earlier quoted context omitted.
I like this idea quite a lot. If you can write the tutorial itself in a "literate code" sort of way, the test harness should be able to consume the entire tutorial and run tests against it. Presuming, of course, that there's a way to tangle/weave using standard comments in Zig. Sounds like it could be a fun project. Could also serve as a way to auto-doc (like JavaDocs or similar using documentation generators).
Zig already does this with its current documentation and example code.
Re: Failing to Learn Zig via Advent of Code
#178Earlier quoted context omitted.
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
#179Earlier quoted context omitted.
> `a+b` will have the same value as `b+a` No, as IEEE754 doesn't even guarantee that `a + b` == `a + b`. You always need to compare the absolute difference of two values against an ε. So a == b |a - b| But for sensible comparison of floats, the addition is commutative.
> No, as IEEE754 doesn't even guarantee that `a + b` == `a + b` What? I'm pretty sure that is plain incorrect. Can you back that claim up with references?
Re: Failing to Learn Zig via Advent of Code
#180I 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…
Reading the source code is very helpful if you are an experimented programmer that already grasped the basics of the language. It helps you to see what are the idioms, what does optimized production code look like. Compare C++ and Go std lib and it’s easy to constate the difference in language goals that they have.