Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

johnmyleswhite
Copy link
Member

Before:

julia> Nullable{Int}()
Nullable{Int}()

julia> Nullable{Int}(1)
Nullable(1)

After:

julia> Nullable{Int}()
NULL

julia> Nullable{Int}(1)
1

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).

@johnmyleswhite
Copy link
Member Author

Just realized I didn't update the tests. Will do that later today.

@JeffBezanson
Copy link
Member

I worry that this could cause confusion about how nullables work.

And NULL of course conflicts with C and Java use. I'd much rather use null (ala nothing). I see linear algebra has already claimed it; could we rename that to nullspace? (cc @ViralBShah @andreasnoack @jiahao )

@andreasnoack
Copy link
Member

I'd be fine with renaming LinAlg.null to nullspace.

@johnmyleswhite
Copy link
Member Author

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.)

On Dec 14, 2014, at 12:44 PM, Jeff Bezanson [email protected] wrote:

I worry that this could cause confusion about how nullables work.

And NULL of course conflicts with C and Java use. I'd much rather use null (ala nothing). I see linear algebra has already claimed it; could we rename that to nullspace? (cc @ViralBShah @andreasnoack @jiahao )


Reply to this email directly or view it on GitHub.

@jiahao
Copy link
Member

jiahao commented Dec 14, 2014

LinAlg.null -> nullspace is fine with me, although the former is MATLAB's name for that function.

@nalimilan
Copy link
Member

Using both NULL and null to mean something different doesn't sound so great. Nothing was removed precisely for this reason.

Does the use of NULL here really conflict with C? NULL is precisely used with C pointers to signal that there's no value to access via dereference. I see that as the equivalent of Nullable.

@JeffBezanson
Copy link
Member

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.

@JeffBezanson
Copy link
Member

To expand on that, C/Java NULL is an instance of every type, but this one is not. Given

type Bar
  x::Foo
  Bar() = new()
end

you cannot do Bar().x = NULL, nor can you do Bar().x == NULL to see if the x field is undefined.

@simonster
Copy link
Member

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 get on the nullables.

@johnmyleswhite
Copy link
Member Author

We could adopt the C# convention and use 1?.

Sent from my iPhone

On Dec 14, 2014, at 2:42 PM, Simon Kornblith [email protected] wrote:

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 get on the nullables.


Reply to this email directly or view it on GitHub.

@JeffBezanson
Copy link
Member

That will break the ternary operator, unless we make it space-sensitive.

@amitmurthy
Copy link
Contributor

nulled and angular brackets - <1> ?

@johnmyleswhite
Copy link
Member Author

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.

@nalimilan
Copy link
Member

Since C# and Swift use ?, it looks like being case-sensitive is not completely unreasonable. (But I'm not familiar with those language at all...)

@johnmyleswhite
Copy link
Member Author

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.

@tkelman
Copy link
Contributor

tkelman commented Dec 15, 2014

#8892 ?

@nolta
Copy link
Member

nolta commented Dec 15, 2014

¿1?
¯\_(ツ)_/¯(1)

@nalimilan
Copy link
Member

@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.

@StefanKarpinski
Copy link
Member

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 ? in the ternary operator. Back when we were considering allowing ? in identifier names for predicates, I was ok with that solution. I'm not super thrilled with adding syntax for nullables, however. I still think we need to see if this approach pans out well or not.

@nalimilan
Copy link
Member

Cool. Though I agree we should wait for the dust to settle before deciding whether ? should be used for nullables or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants