-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
error for ignoring return value #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is a terrible idea IMO. There are many cases where you want to have a function that returns extra information, like |
In any case where you would run into this error, you can resolve it by assigning to |
closes #291 This changes the error message "return value ignored" to "expression value is ignored". This is because this error also applies to {1;}, which has no function calls. Also fix ignored expression values in std and test. This caught a bug in debug.readAllocBytes where an early Eof error would have been missed. See #219.
@zatherz See the changes to This is a data point in favor of keeping the error for ignoring function return values. |
What about some sort of operator specifically for ignoring return values, so that you don't have to clutter code with |
I don't follow that logic. |
It's 4 characters ( |
In C you have If we introduced a 1-character operator for ignoring the return value, we'd be adding another 1-character symbolic operator for basically no purpose. Like the operator would actually do nothing. That doesn't seem worthwhile when the current solution to the problem works fine.
Obviously languages can be designed however the designer(s) want them to be designed, so this is a bit of an arbitrary decision. But Zig's design does have an emphasis on readability and being a small langauge, so I think the current solution is consistent with Zig's philosophy. Just for reference, the |
Go also uses _ = 42
_, _, _ = 1, 2, 3 |
if a function has a return value, you must handle it, at least by assigning it to
_
The text was updated successfully, but these errors were encountered: