Live data from Hacker News

Maintain It with Zig

kristoff.it

261–270 of 286 posts

Re: Maintain It with Zig

#261

Earlier quoted context omitted.

> Let's hope this is not vaporware. I sincerely approve of the skepticism. I can assure you there is already a very large fire under my ass to get this shipped. To provide some more context, here is a snippet from the latest release notes[0]: > Having a package manager built into the Zig compiler is a long-anticipated feature. Zig 0.8.0 does not have this feature. > If the package manager works well, people will use…

Hi Andy, I'm really intrigued by Zig's features - you're definitely solving the right and hard problems for C developers like myself. If I may, my only piece of feedback (as someone who looked at Zig with fresh eyes) is that the syntax has lots of special chars (@, !void, .{}, &, etc). Is there a rationale published for these and other design choices (even if it's "I like it that way"). I would have expected a langua…

>If I may, my only piece of feedback (as someone who looked at Zig with fresh eyes) is that the syntax has lots of special chars (@, !void, .{}, &, etc). Is there a rationale published for these and other design choices (even if it's "I like it that way"). I would have expected a language with ambitious goals like Zig to take a stab at coming up with a grammar that's even simpler and cleaner than C.

That is sadly my gripe with a lot of the newer languages too. I have been looking for something to replace C for a long time, something that makes it easier to not shoot yourself in the foot. I just find most of them significantly less readable than C.

Rust seems to be going down the route of C++, hence I do not deem it a safe language at all, as I have an exceedingly hard time parsing the source and figuring out what is going on.

Zig is WAY better in that regard, but as OP mentions: all the special characters make things more difficult to parse. Calls like these (taken from the introduction page) contain so much visual clutter:

  try expect(@call(.{}, add, .{3, 9}) == 12);
I sadly doubt any of this is possible to change at this stage anymore. Zig definitely seems the most promising C replacement with regards to tooling, especially cross compiling and C interop are a breeze. Truly inspiring work!

The only new C-like language that really nailed it for me syntax wise would be Nim. Very clean and easy to reason about, which - from a programmer perspective - makes it exceedingly safe to program in. It just seemingly lacks most of the safety guarantees that the compilers of other, newer languages provide.

Re: Maintain It with Zig

#262
post #255

Earlier quoted context omitted.

Out of curiosity, have you written apps in both languages? I have written small applications in both. To be transparent: my total dev hours in D are probably somewhere around ~100, and in Zig about ~30. So I am more familiar with D than Zig, though competent enough with both to have written a few small real-world programs. > Its interoperability with C at the source and object level is first-class D has direct intero…

Is syntactical similarity or even compatibility to C a positive thing? Not taking away anything, D is a really cool language that definitely doesn’t get the fame it would rightfully deserve, I just think that breaking with some old habits (eg. postfix types with : are simply superior from a parsing perspective, and the pointer magic of C is just as terrible and the change in Zig is very welcome) when they are superse…

I do actually prefer postfix types, so I'm not against you there.

The bit about D is that while you CAN write it to look like C, (or even directly embed ASM blocks in it), it's usually written in a higher-level form without pointers that looks more like JavaScript:

  // Count line length of stdin
  void main() {
      import std.range, std.stdio;

      auto sum = 0.0;
      auto count = stdin.byLine.tee!(l => sum += l.length).walkLength;

      writeln("Average line length: ", count ? sum / count : 0);
  }

  ----

  import std.algorithm, std.conv, std.functional, std.math, std.regex, std.stdio;

  alias round = pipe!(to!(real), std.math.round, to!(string));
  static reFloatingPoint = ctRegex!(`[0-9]+\.[0-9]+`);

  // Replace anything that looks like a real number with the rounded equivalent.
  void main(){
      stdin
          .byLine
          .map!(l => l.replaceAll!(c => c.hit.round)
                                  (reFloatingPoint))
          .each!(it => writeln(it));
  }

Re: Maintain It with Zig

#263

Earlier quoted context omitted.

Keep in mind that filesystem paths aren't strings. On Linux, they are raw bytes without any fixed encoding (but usually UTF-8 on UTF-8-based locales), and on Windows, they are sequences of 16-bit codepoints which are expected to be UTF-16 but not validated. Rust's OsStr is my favorite approach so far. It stores Linux's raw bytes as-is, and stores Windows's possibly-valid UTF-16 as WTF-8. This makes path management "j…

MacOS filesystem is utf-8 strings with valid Unicode glyphs that are pinned to a certain revision of Unicode.

> MacOS filesystem is utf-8 strings

APFS is utf8, HFS+ is utf16.

> with valid Unicode glyphs

That doesn’t really mean anything.

Apple’s fs do guarantee the paths are correct, as in, valid whatever encoding this has nothing to do with glyphs.

APFS also does not perform any normalisation while HFS+ uses a custom variant if NFD. While HFS+’s normalisation has its issues and critics, APFS’s lack of normalisation is probably worse: https://eclecticlight.co/2017/04/06/apfs-is-currently-unusab...

Re: Maintain It with Zig

#264

Earlier quoted context omitted.

Any plans to go one step further towards memory safety (and even better data race freedom)? Maybe using ARC when the overhead is acceptable (like Swift), it static analysis is not possible due to the type system not supporting the concepts of ownership, borrowing, lifetimes and so on? Zig is super exciting, but without a GC or Rust type system, I’m worried about going “back” to a language where I have to think about…

As of now the tradeoff of Rust's type system is that code may leak memory and you may need to investigate all occurrences to fix it, because there is no tooling yet (testing everything is infeasible). You can have either extensive static analysis or fast compile times. Tracking ownership down to semantic analysis (where type layouts are in resolved form) requires adjusting and slowing down the complete compiler.

Did you mean Zig? I don’t understand how Rust code can leak memory?

Re: Maintain It with Zig

#265
post #261

Earlier quoted context omitted.

Hi Andy, I'm really intrigued by Zig's features - you're definitely solving the right and hard problems for C developers like myself. If I may, my only piece of feedback (as someone who looked at Zig with fresh eyes) is that the syntax has lots of special chars (@, !void, .{}, &, etc). Is there a rationale published for these and other design choices (even if it's "I like it that way"). I would have expected a langua…

>If I may, my only piece of feedback (as someone who looked at Zig with fresh eyes) is that the syntax has lots of special chars (@, !void, .{}, &, etc). Is there a rationale published for these and other design choices (even if it's "I like it that way"). I would have expected a language with ambitious goals like Zig to take a stab at coming up with a grammar that's even simpler and cleaner than C. That is sadly my…

You should take a closer look at Nim. I suspect it probably has all that you want, but said features may not be "by default/well advertised" (yet). Alternatively, you should be more specific about what you think it lacks.

Re: Maintain It with Zig

#266

Earlier quoted context omitted.

> Can you list any claims that fell apart? On home page, the very first claim: > No null However V has `nil` or any reference can be initialized to `0`. How is then claiming `no null` not false?

There's no `nil` in the language, but indeed there's a hack that allows to assign 0 to references. It's on the 0.3 roadmap, high priority.

Similarly almost every feature in V has some hacks or doesn't work outright. But authors of V don't have enough dignity to mention the in-progress/missing features on home page. And when somebody points them to their dishonesty, they block them on discord.

Re: Maintain It with Zig

#267

Earlier quoted context omitted.

As of now the tradeoff of Rust's type system is that code may leak memory and you may need to investigate all occurrences to fix it, because there is no tooling yet (testing everything is infeasible). You can have either extensive static analysis or fast compile times. Tracking ownership down to semantic analysis (where type layouts are in resolved form) requires adjusting and slowing down the complete compiler.

Did you mean Zig? I don’t understand how Rust code can leak memory?

https://doc.rust-lang.org/std/boxed/struct.Box.html#method.l...

Re: Maintain It with Zig

#268

Agreed for sure that working with C and C++ is the only way forward for systems languages. Rust's expression of this is the zero-cost C FFI, using native platform tooling, and stuff like that. Rust was never about re-writing the world, after all, its reason for existing was to eventually improve Firefox. The very first presentation about Rust ( http://venge.net/graydon/talks/intro-talk-2.pdf ) says "We are not “rewri…

Since Rust is built on top of LLVM, what's preventing it from "just" adding the Clang C/C++/ObjC frontends into the Rust compiler, and create cargo packages with cross-platform C/C++/ObjC headers and runtimes? This would make cross-compilation and C/C++/ObjC integration just as easy as with Zig (and without requiring any external C toolchain, which is the most important point). I guess the other (simpler) alternative…

If Rust compiler team members wanted to collaborate on this effort, I would be open to that. We could co-maintain a separate repository with:

* The collection of headers for various targets, and the tools to upgrade/maintain them.

* The source files for various libcs, patches, instructions/tools to upgrade/maintain them

* A declarative set of instructions to create build artifacts (not Makefiles!!)

* Instructions/patches needed to integrate Clang driver frontends into a different binary (making the "main" functions co-exist peacefully).

Would be a fair amount of overhead to collaborate, but perhaps could ultimately save both parties labor.

Re: Maintain It with Zig

#269
post #241

Earlier quoted context omitted.

Yeah I watched a couple of his talks, enjoyed every word. There is another interesting language (won't mention the name) but the creator won't let the public in and has a superiority complex, turned me off instantly. I believe Zig will blow up just because of the strong vision but without being a dick about it. It's next on my list for sure.

Ahh you mean Elm, by any chance? I feel Elm's growth has been stunted because the creator is actively hostile with whoever disagrees with him. I remember the infamous "leaving elm" post which was handled so poorly by Elm's author. If they had handled it well, elm would have definitely seen a large uptick in adoption

There really isn't any call to trash Elm and its creator like this.

There's very little evidence of ongoing hostility from Evan - I pay attention to his work and writings and find he's rarely if ever hostile. In fact he's very mild-mannered, and is painstakingly detailed about explaining the reasons for why he does things the way he does, over and over again.

Perhaps that wore thin once or twice in the face of repeated criticism and demands. We've all seen way worse.

Yes, sticking to his vision has excluded ideas and contributions, and made some people very angry. There have been several high profile blogposts and twiits painting him as some kind of despot. And when other overzealous developers swooped in to defend his work, it just fed the meme, one which people on HN like to repeat every chance they get.

Well, I for one am glad he's a 'code despot' - considering how many people keep demanding that they dilute Elm's guarantees for the sake of JS library interop or marginally less boilerplate. Any bending to these demands and Elm today would be just another framework with a slightly different syntax, with none of guarantees that allow for the innovative tooling and libraries [1] we see coming out of the community.

Whether you agree with Evan's vision or not, Elm is doing just fine meeting its stated goals and is a fantastic and delightful technology and toolchain.

So please give over with trashing other people's hard work. If you don't like it, just don't use Elm.

[1] for example, the compiler's dead code elimination capabilities, elm-review's tco detection and other amazing auto-fixes, lamdera, etc.

Re: Maintain It with Zig

#270
post #214

Earlier quoted context omitted.

Keep in mind that filesystem paths aren't strings. On Linux, they are raw bytes without any fixed encoding (but usually UTF-8 on UTF-8-based locales), and on Windows, they are sequences of 16-bit codepoints which are expected to be UTF-16 but not validated. Rust's OsStr is my favorite approach so far. It stores Linux's raw bytes as-is, and stores Windows's possibly-valid UTF-16 as WTF-8. This makes path management "j…

The difficulty of printing OsStr is nothing to do with Rust, it's really just the difficulty of printing Linux file names in any context given you don't know what the non-UTF8 bytes mean.

It's also a good rationale for why filenames should be valid Unicode - because they're data displayed to the end user.
Post reply on HN