-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I used this instead of `null`, since `null` is deprecated, and could cause confusion with general null values from other languages. But I'm willing to change to `null` if opinion is heavily that way.
- Loading branch information
1 parent
389c909
commit c966812
Showing
4 changed files
with
13 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1377,6 +1377,7 @@ export | |
|
||
# nullable types | ||
isnull, | ||
nulled, | ||
|
||
# Macros | ||
@__FILE__, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c966812
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like calling it
nulled
:-. I'd rather call itNULL
ornull
or something. Another option would be providing conversions fromnothing
toNullable{T}
that construct null instances. Of course, that would make constructingNullable{Void}
objects ambiguous, but that's a pretty strange thing to want to do.c966812
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The votes for
null
seem to be rolling in.Using
nothing
is an interesting idea; it's very tempting to make do with less nothingness. It also makes Nullable code more interoperable with code that usesUnion(T,Void)
.Nullable
is a great example of wrapping vs. converting. If you doNullable(nothing)
under this scheme, it will still work fine and give aNullable{Void}
. Onlyconvert(Nullable, nothing)
might be surprising. However, that same issue already exists, since if you doconvert(Nullable, x)
, butx
is already Nullable and you didn't expect it to be, you get the same surprise. For exampleIf the action succeeds but returns an empty Nullable, this code makes it look like the action failed. The fix is simply to use
Nullable(action())
instead. And all of this holds true with or without conversions fromnothing
to empty Nullables, so I think there's a good chance we should go for it.c966812
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we was discussed elsewhere: with return type declarations, your example above could be automatically converted if the function was declared as returning a
Nullable{typeof(action)}
object. Thus code could usereturn null
orreturn nothing
without any typing issues.Crazy idea: could
nothing
be made equal toNullable{Union()}()
, makingVoid
an alias forNullable{Union()}
?c966812
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, there's the issue that
Nullable{Union()}()
is 16 bytes whereasnothing
is zero bytes. If we could figure out a way to makeNullable{Union()}()
zero bytes, then it could be workable.c966812
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not (yet), since Nullable is a struct with a Bool, and
Void
needs to be size 0. Good thought though.You'd have to be careful with a return type declaration, since that somewhat hides the issue of conversion vs. wrapping. But generally yes, conversion via return type declarations combines well with this, since you could return
nothing
(perhaps even by accident!) without type instability.c966812
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I'm sold on replacing this commit with a conversion from
Void
. Any objections?c966812
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.