3 ms·
Another default that Zig got right: every non-void result must be handled. https://github.com/ziglang/zig/issues/219 https://github.com/ziglang/zig/issues/219
by ivanjermakov 10mo ago
Another default that Zig got right: every non-void result must be handled.
https://github.com/ziglang/zig/issues/219 https://github.com/ziglang/zig/issues/219
- kyralis 10mo agoI 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.
- m-schuetz 10mo agoTerrible for atomic functions where you are often only interested in atomically writing something, but not interested in the return value they also provide.
- leecommamichael 10mo agoThis 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.
- drnick1 10mo agoIt’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.
- peesem 10mo agoyou can discard with `_ = returningFn();`