-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
nullable syntax update #1023
Comments
Will there be anything for null function call chaining like Kotlin’s ?. ifnull is rather verbose, Kotlin uses ?: which is short and simple. |
Feel free to propose something in a separate issue. I don't remember if this one has been proposed so far. |
I really like the Perhaps something simpler like I'm not particularly against it but I'm not all for it. |
|
What about reusing
|
I like @hcff’s idea but nullable booleans might get confusing. |
Should Also not a huge fan of
|
My personal favourite would be |
Would there be an issue with using a straight |
yes. it would cause ambiguity in |
@thejoshwolfe - Damn, I should have seen that. One of the proposals in #760 mentioned the possibility of removing the parentheses around the condition of Your example would have to be expressed as either
or
|
Another bikeshed proposals (sorry if something conflicts with existing keywords/...):
|
If using something like
|
See #1023 This also renames Nullable/Maybe to Optional
That would indeed follow the pattern. However, I removed the error I think I would advocate for removing I'm choosing
|
See #1023 This also renames Nullable/Maybe to Optional
use the `zig-fmt-optional-default` branch to have zig fmt automatically do the changes. closes #1023
use the `zig-fmt-optional-default` branch to have zig fmt automatically do the changes. closes #1023
Does this also remove prefix |
prefix |
I've never heard about zig until a few minutes ago, and I already like it! 👍 |
I apologize if this is the wrong place to leave this comment, I've searched other issues and haven't found anywhere else more appropriate. Should var a: i32 = undefined;
var nullable: ?i32 = null;
var non_nullable: i32 = 20;
a = nullable orelse 1; // works
a = non_nullable orelse 1; // doesn't work This example results in the following compile error:
Although perhaps useless, it's still a safe operation. |
@avrittrohwer This restriction is surely by design. Zig generally takes a rigid standpoint on syntax. There may be other reasons, but at the very least this is for the sake of some of its mottos: "Only one obvious way to do things" and "Communicate intent precisely". In this case, Just speaking for myself, I've come to love that property — the compiler guides me into making the cleanest and most correct code possible. |
For me |
a ?? b
binary operator witha ifnull b
. After this change, all control flow occurs with keywords only.ifnull
are welcome.ifnull
is nice because it is 2 lowercase words squished together so nobody will miss the identifier name.??x
prefix operator. Replace it withx.?
. After this change and Pointer Reform #770, this symmetry exists:*T
is used to make a pointer type, andx.*
derefs?T
is used to make a nullable type, andx.?
de-nullifies.*
asserts the pointer is valid among other things and.?
asserts the value is non-null.Anecdotally, this will look a lot better syntactically, especially with C-translated code.
The text was updated successfully, but these errors were encountered: