-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Simplified printing of Nullable objects #9356
Conversation
Just realized I didn't update the tests. Will do that later today. |
I worry that this could cause confusion about how nullables work. And |
I'd be fine with renaming |
I'm ok with anything that makes printing less cluttered. On the flip side of C, this usage of NULL matches SQL. (Which also would accept null.)
|
|
Using both Does the use of |
The difference is that this NULL is not a missing value at the language level: it is a perfectly good object reference, pointing to an object that represents the lack of a value of a certain type. |
To expand on that, C/Java NULL is an instance of every type, but this one is not. Given
you cannot do |
This seems like a potential source of confusion: julia> f()
1
julia> 1 + 1
2
julia> f() + f()
ERROR: `+` has no method matching +(::Nullable{Int64}, ::Nullable{Int64}) I think there should be some indication that the value is a nullable in the printed text. Failing that, we should improve the MethodError to suggest calling |
We could adopt the C# convention and use 1?. Sent from my iPhone
|
That will break the ternary operator, unless we make it space-sensitive. |
|
Works for me, but I'd really like to make sure that the output can be put into the REPL to reproduce the same object. I think we have enough places in the language where we should be using Nullable that having dedicated syntax might make sense. |
Since C# and Swift use |
I'd love to take Swift's lead, but I believe @StefanKarpinski has told us we'll have to pry the ternary operator out of his cold dead hands. |
#8892 ? |
|
@StefanKarpinski Is @johnmyleswhite right about your cold dead hands? @tkelman The problem with custom brackets is that they evoke arrays more than a single value to me, and they are hard to type from the keyboard. |
I think I was talking about something else when I used the cold, dead hands phrase, but I do like the ternary operator. I would, however, be fine with requiring whitespace before the |
Cool. Though I agree we should wait for the dust to settle before deciding whether |
Before:
After:
I'm not sure how we should Nullables, but this simplified printing makes working with Nullables much more enjoyable (when you already know that you're dealing with a potential source of Nullables).