News for hackers. Stuff that matters.
Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by bjz_ on Tuesday December 04, 2018 @09:53PM (#18605357)
I wouldn't say it's inexcusable, but I'm definitely trying to avoid any systems language that has implicit null, and allows for data races and de-referencing uninitialized memory from safe code. So that only really leaves ATS and Rust, and rules out Nim, D, Zig, Jai... (for me at least).

Zig certainly has some cool ideas - I definitely think that we should be making the phase distinction more flexible. I do wish however that its compile time function evaluation was built on a firmer foundation, ie. using dependent types.

Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by AndyKelley on Tuesday December 04, 2018 @10:22PM (#18605460)
Please don't spread misinformation. Zig does not have implicit null.

Also depending on how you define "dependent types" - there are a few competing definitions - Zig has them.

Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by vmchale on Wednesday December 05, 2018 @12:39AM (#18605918)
> Also depending on how you define "dependent types" - there are a few competing definitions - Zig has them.

How is it ambiguous? Dependent type systems/algorithms can be weaker than desired, but there's no way you can say Zig has dependent types.

Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by stateoff on Friday December 07, 2018 @01:35AM (#18625598)
I think Andy refers to this [1].

For example you can do:

  const std = @import("std");
  
  fn Int(comptime value: i32) type {
      return struct {
          pub fn value() i32 {
              return value;
          }
      };
  }
  
  pub fn main() anyerror!void {
      const int3 = Int(3);
      const int4 = Int(4);
  
      std.debug.warn("Types: {} {}\n", @typeName(int3),   @typeName(int4));
      std.debug.warn("Sum: {}\n", int3.value() + int4.value());
  }
Output being:

  Types: Int(3) Int(4)
  Sum: 7
Edit: The compiler does the right thing:

[2] https://godbolt.org/z/eLWeU2

[1] https://ziglang.org/documentation/master/#Generic-Data-Struc...

Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by bjz_ on Tuesday December 04, 2018 @10:34PM (#18605503)
Oh, I must be mistaken then. So pointers are guaranteed not to be null? Can I mark pointers as nullable, and be forced to explicitly check?

Although there are differing ways to define dependent types, and they come in different varieties (dependent functions, dependent pairs/structs, very dependent types, dependent intersections, inductive types), they are all founded on a foundation of type theory. I guess if you want me to clarify, it is 'dependent types based on a well understood foundation from type theory'.

---

Edit: seems like Zig does have optional types! That is a good thing! https://ziglang.org/documentation/master/#Optionals

Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by pjmlp on Wednesday December 05, 2018 @05:17AM (#18607029)
I love GC enabled system languages since I used Oberon, and beyond trying to fit everything into a 64KB segment, bounds checking was never an issue for the type of code that I write.

So D, Nim, C# (AOT compiled), Java (Embedded/Android Things/MicroEJ), Swift, Go are pretty much on the table as well.

Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by vmchale on Wednesday December 05, 2018 @12:41AM (#18605925)
> So that only really leaves ATS and Rust, and rules out Nim, D, Zig, Jai

I don't have a problem with GC so Nim/D are on the table. ATS is a pain in the ass but after the arrival of Rust it's pretty clear that linear/affine types can be user-friendly. There's no excuse any more.

Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by eggy on Wednesday December 05, 2018 @06:58AM (#18607491)
I find Zig much more user friendly than Rust. I have been able to do much more with Zig than Rust in one-tenth the time. I am not writing any code that requires the guarantees Rust may provide, and Zig seems to make it easier to write safer C-type code to boot.
Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by vmchale on Wednesday December 05, 2018 @09:41AM (#18608547)
Zig doesn't force you to free all your memory (which occasionally good), so there are whole classes of errors that Rust/ATS avoid that are possible in Zig.
Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by oconnor0 on Wednesday December 05, 2018 @01:00AM (#18606000)
I don't think I'd call Rust user friendly.
Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by vmchale on Wednesday December 05, 2018 @01:02AM (#18606008)
If the problem is the type system/borrow checker, it's simply a question of experience.
Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by pjmlp on Wednesday December 05, 2018 @05:13AM (#18607007)
Not when writing GUI like code, to the point that the Rust team acknowledges that additional work needs to be done after NLL lands on stable.

http://smallcultfollowing.com/babysteps/blog/2018/11/01/afte...

http://smallcultfollowing.com/babysteps/blog/2018/11/10/afte...

So while Rust is much more productive than ATS or Cyclone, there is still room of improvement for that experience.

Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by floatboth on Wednesday December 05, 2018 @05:46AM (#18607166)
There's always room for improvement, but speaking of GUI, gtk-rs is pretty usable already.
Re:Using Zig to Provide Stack Traces on Kernel Panic for a B... by pjmlp on Wednesday December 05, 2018 @06:44AM (#18607417)
It is, if you don't mind sprinkling your code with Rc<RefCell<item>> everywhere, as means to access widget struct members in callbacks.