Live data from Hacker News

Zig: programming language designed for robustness optimality and clarity [video]

youtube.com

1–10 of 73 posts

Re: Zig: programming language designed for robustness optimality and clarity [video]

#2
There are too many cool languages and too few weekends. It's becoming more problematic, but at the same time it would seem impractical to optimize my life around learning every single thing that I want to learn.

How do I decide which things are important enough? I am running out of time in my life also.

I watched a video a while ago about how the universe is expanding faster than light can travel, which means the portion of the universe that we can observe is an increasingly small subset of what's out there.

Sometimes my hobbies and wish-i-had-time-for-that projects feel the same way, they're expanding faster than I'll ever catch up to.

I wonder if zig will ever pursue some sort of memory safety. I find rust very difficult and unwieldy, but I can totally grok the appeal of RAII.

Re: Zig: programming language designed for robustness optimality and clarity [video]

#3
post #2

There are too many cool languages and too few weekends. It's becoming more problematic, but at the same time it would seem impractical to optimize my life around learning every single thing that I want to learn. How do I decide which things are important enough? I am running out of time in my life also. I watched a video a while ago about how the universe is expanding faster than light can travel, which means the por…

> I wonder if zig will ever pursue some sort of memory safety.

That's exactly what Zig is designed for [1].

Andrew Kelley (andrewrk) discusses this in the talk. Zig is similar to Rust, but with memory safety designed into the core, not bolted on as an afterthought. And as the SHA-256 demo tests in the talk show, Zig is as fast or faster than C.

[1] http://ziglang.org

[2] https://github.com/ziglang/zig

Re: Zig: programming language designed for robustness optimality and clarity [video]

#4
post #3
post #2

There are too many cool languages and too few weekends. It's becoming more problematic, but at the same time it would seem impractical to optimize my life around learning every single thing that I want to learn. How do I decide which things are important enough? I am running out of time in my life also. I watched a video a while ago about how the universe is expanding faster than light can travel, which means the por…

> I wonder if zig will ever pursue some sort of memory safety. That's exactly what Zig is designed for [1]. Andrew Kelley (andrewrk) discusses this in the talk. Zig is similar to Rust, but with memory safety designed into the core, not bolted on as an afterthought. And as the SHA-256 demo tests in the talk show, Zig is as fast or faster than C. [1] http://ziglang.org [2] https://github.com/ziglang/zig

I don't understand. Rust has memory safety as a core design principle. Zig has manual memory allocation like C.

Re: Zig: programming language designed for robustness optimality and clarity [video]

#5
post #3

Earlier quoted context omitted.

> I wonder if zig will ever pursue some sort of memory safety. That's exactly what Zig is designed for [1]. Andrew Kelley (andrewrk) discusses this in the talk. Zig is similar to Rust, but with memory safety designed into the core, not bolted on as an afterthought. And as the SHA-256 demo tests in the talk show, Zig is as fast or faster than C. [1] http://ziglang.org [2] https://github.com/ziglang/zig

I don't understand. Rust has memory safety as a core design principle. Zig has manual memory allocation like C.

Zig is memory-safe if you keep runtime checks enabled (e.g. with debug or release-safe optimization levels) but it does not have the compile-time guarantees of Rust. I don't think the parent comment is a fair reflection.

That being said, some other potentially interesting safety aspects that are present (or are being explored) to give some idea of the target audience:

  - compile-time alignment checks [1]
  - maximum compile-time stack usage/bounding [2]
I would expect safety at the end of the day in Zig will be more similar to modern C++ and its smart pointers, alongside (optional) runtime checks, than a full lifetime system. Will have to see what the future holds.

[1] https://ziglang.org/documentation/master/#Alignment

[2] https://github.com/ziglang/zig/issues/1006

Re: Zig: programming language designed for robustness optimality and clarity [video]

#6
This programming setup is the bomb.

Zig is designed not only for robustness, optimality, and clarity, but also for great justice.

It's great that Zig is an open source project so all your codebase belongs to us.

I hope 'Zig' takes off everywhere.

Re: Zig: programming language designed for robustness optimality and clarity [video]

#7
I've been building a toy project in zig in the last couple weeks. Zig is incredible. After only a short while working with it, it feels like deserves the title of a "better C". With no runtime overhead you get:

* Type inference - var name = "Bob";

* Maybe types (from Elm/Haskell) that prevent NULL ptr bugs and syntactic sugar encourages its use for function return values.

  if (doit()) |result| {
    // result is always a populated Struct
  } else |err| {
    // error is always a populated Error
  }
  
  // a return type of !Something means Error type or Something type
  fn doit() !Struct {
  }

* Nullable types - var ?&object = null; if you need it, and var &object = aObject; if you want the safety.

* Great C interop, though there is more work to be done here. (gtk.h for instance is too much for zig today) Zig's approach is unique here too. You specify .h files in the zig source code and the zig compiler translates C in the .h into zig. Its not a function bridge or wrapper, its zig objects and zig functions available to your zig code.

  const c = @cImport({
    @cInclude("curl/curl.h");
  });

  var curl = c.curl_easy_init();
  if(curl != null) {
    _ = c.curl_easy_setopt(curl, c.CURLoption(c.CURLOPT_URL), url_cstr.ptr);
  ...
* Standard library operations that allocate memory take an 'allocator object' parameter that should give great programmer control over memory management (I didnt get into this myself), webasm is a compiler target, and lots more

Re: Zig: programming language designed for robustness optimality and clarity [video]

#8
From the slides, these bullets struck me as things I have wanted for a while (to the extent that I have my own toy language that addresses some of them):

- compiles faster than C

- Produces faster machine code than C

- Seamless interaction with C libs

- robust/ergonomic error handling

- Compile-time code execution and reflection

- No hidden control flow

- No hidden memory allocations

- Ships with build system

- Out-of-the-box cross compilation

Re: Zig: programming language designed for robustness optimality and clarity [video]

#9
post #2

There are too many cool languages and too few weekends. It's becoming more problematic, but at the same time it would seem impractical to optimize my life around learning every single thing that I want to learn. How do I decide which things are important enough? I am running out of time in my life also. I watched a video a while ago about how the universe is expanding faster than light can travel, which means the por…

If Zig (or some other language) turns out to be the next big thing, we'll be hearing about it again and again.

Re: Zig: programming language designed for robustness optimality and clarity [video]

#10
post #7

I've been building a toy project in zig in the last couple weeks. Zig is incredible. After only a short while working with it, it feels like deserves the title of a "better C". With no runtime overhead you get: * Type inference - var name = "Bob"; * Maybe types (from Elm/Haskell) that prevent NULL ptr bugs and syntactic sugar encourages its use for function return values. if (doit()) |result| { // result is always a…

I think you mean Result or Either like Haskell etc., not Maybe.

Additionally, Swift has essentially the same approach to C FFI.

Post reply on HN