logoalt Hacker News

ivanjermakovyesterday at 2:37 PM4 repliesview on HN

Another default that Zig got right: every non-void result must be handled.

https://github.com/ziglang/zig/issues/219


Replies

leecommamichaelyesterday at 7:56 PM

This is one of those preferences that will never fail to split the room. I appreciate both routes depending on the domain, but I do have a preference. As a games and UI app developer, I find required-handling-by-default adds too much friction and disrupts my flow. Rust and Zig (through different means) create friction like this in an effort to make low-level code "easier", but only if the code is "correct" according to the language. As a dev that spent a lot of time with Swift, and loving the language's ability to express APIs, I came to appreciate compilers with the quality that "if the code runs, it's probably correct," and yet my preference did not land on Rust or Zig, but with Odin. I sat down with Odin 5 or so years ago and it felt like the friction was exactly where I wanted it to be for the software I write.

kyralisyesterday at 3:52 PM

I would not agree. There are plenty of times I've written and used functions that have informational return values that are beneficial in certain cases and unnecessary in most. This is why most languages have chosen annotations to allow for the function author to indicate intent.

drnick1yesterday at 10:16 PM

It’s a terrible idea, what if you aren’t interested in the return value and can’t rewrite the function because it is in a third party library? Assigning that to a variable that won’t be used is terribly inefficient and inelegant.

m-schuetzyesterday at 5:29 PM

Terrible for atomic functions where you are often only interested in atomically writing something, but not interested in the return value they also provide.