logoalt Hacker News

gethlyyesterday at 12:33 PM2 repliesview on HN

For allocation, Zig and Odin. Zig is explicit and Odin is implicit.


Replies

prxmyesterday at 2:53 PM

> Zig is explicit

i never got this point. whats stopping me from writing a function like this in zig?

  fn very_bad_func() !i32 {
      var GPA = std.heap.GeneralPurposeAllocator(.{}){};
      var gpa = GPA.allocator();
      var s = try gpa.alloc(i32, 1000);
      s[0] = 7;
      return s[0];
  }
the only thing explicit about zig approach is having ready-to-use allocator definitons in the std library. if you excluded std library and write your own allocators, you could have an even better api in rust compared to zig thanks to actual shared behaviour features (traits). explicit allocation is a library feature, not a language feature.
show 1 reply
thegeekpirateyesterday at 9:22 PM

You can require allocations in Odin to be explicit using `#+vet explicit-allocators`