Open AnthonyDGreen opened 7 years ago
The If(True,1, Nothing)
could be solved with an analyser.
With the message This evaluates as Integer, not Nullable(Of Integer)
Providing a possible code - fix. To produce the following code.
Dim x As Integer? = If( True, 1, New Nullable(Of Integer)() )
Yep, that's one possible solution to the problem. FYI you can actually say New Integer?
, you don't need to use Nullable(Of Integer)
in that case. We've talked about analyzers and pretty-listing fixes. I'm going to try to record all of them here in different issues.
Thing is there is code in existence today that uses :
Dim x As Int32? = Nothing
So assuming we don't cause a breaking change there, we'd end up with existing code using Nothing and some of new code using Null. We'd even have the situation where Nothing could be assigned to a variable and it would be reported as equal to Null and vice versa
As this is only an issue with overload resolution and compiler resolution for if expressions, might be nicer to keep the solution limited to those areas rather than spread the overlap.
I'm still in favour of Nothing? to force to the nullable. Seems in keeping with Integer? et al
@Bill-McC That code wouldn't be effected. This isn't proposing any change to what Nothing
does and Nothing
is doing exactly what is expected there.
Re: Overlap between Null
and Nothing
.
The proposed Null
would replace Nothing
in contemporary use in the way that structured loops replace unstructured Goto
statements. C# has null
and default(T)
and now default
(which is exactly Nothing
). The advice a la StackOverflow is simple "Use Null
unless you can't". I don't have a problem phasing something out all together or significantly minimizing it. I just prefer to avoid changes where it's like 50/50.
Re: Nothing?
as alternate syntax. Explain to me what it does without using the word "null".
FYI, @Bill-McC I'm not adding a new proposal tracking Nothing?
specifically because I think it's the same approach to solving the problem just an alternate syntax proposal. If you disagree we can break it out.
@AnthonyDGreen The proposal is to introduce a new Null literal
to either a null reference or a null nullable value
That's not a structural change such as GoTo versus structured loops, it's just a different shade of paint. So for a stylistic change we'd have for ever ever overlap of Nothing and Null.
RE Nothing? it forces the nullable type to be Nothing rather than the type the nullable wraps being in its default zero state . Now explain what Null is without using the terms Nothing or "not anything" ;)
moved from #95
@rskar-git I had forgotten about VB6 use of Null vs Nothing (vs Empty vs vbNullString et al). That was one of those language things that use to cause a lot of forum traffic, with what's the difference between Nothing and Null. So if we did re-introduce Null, (some 20 years later), and gave it a new meaning away from it's Variant past, I think we'd be opening up that can of worms and putting it in a vitamiser without a lid on.
I kind of agree with your comment on, as to it adding confusion:
Dim y as Integer? = Nothing?
The question we should be asking is do we want any duplication. Do we want to have
Dim y As Integer? = Nothing
Dim y As Integer? = Nothing?
Dim y As Integer? = Null
Dim y? As Integer = Nothing
Dim y? As Integer = Nothing?
Dim y? As Integer = Null
We've already got two of those six. I think if we add Null, it'd definitely set off an era of "what's the difference questions" as well as bring out the "redefining keywords is evil" pontifications. I see Nothing? as the lesser of two evils. It could be limited to the overload resolution cases (perhaps ?) , and perhaps the IDE could suggest it where there are common mistakes: the beauty there is it is easily added/removed as it is just a ? suffix.
@AnthonyDGreen Not sure on splitting Nothing? out from this. It is a different scope as well as syntax, but I think the Null suggestion should also be open to scope limiting such as only for Nullable types. Splitting all variations would seem unwieldy and hard to keep track of relevant comments from different forks.
I looked at Python’s “None” expression and they define it referencing both null AND nothing. I think you’re right that it’s impossible to avoid the circularity. The advantage “Null” has is that it's all over the framework in NullReferenceException and ArgumentNullException and all over the docs. It's an unavoidable concept in .NET. You do have a point that our word is less esoteric (as do the Python docs). I'm leaning back toward the warning or some IDE trickery now.
Sent from my Windows 10 phone
From: Bill-McCmailto:notifications@github.com Sent: Thursday, June 1, 2017 5:51 PM To: dotnet/vblangmailto:vblang@noreply.github.com Cc: Anthony D. Greenmailto:adgreen@microsoft.com; Mentionmailto:mention@noreply.github.com Subject: Re: [dotnet/vblang] 'Null' literal (as opposed to 'Nothing' literal) (#94)
@AnthonyDGreenhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fanthonydgreen&data=02%7C01%7Cadgreen%40microsoft.com%7Ce2788aef65c747599d8208d4a9517aef%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636319614809310692&sdata=nCBCpgntJQCKBtqwscwN29OFyJdp81RGeKnUxZiBhlI%3D&reserved=0 The proposal is to introduce a new Null literal
to either a null reference or a null nullable value
That's not a structural change such as GoTo versus structured loops, it's just a different shade of paint. So for a stylistic change we'd have for ever ever overlap of Nothing and Null.
RE Nothing? it forces the nullable type to be Nothing rather than the type the nullable wraps being in its default zero state . Now explain what Null is without using the terms Nothing or "not anything" ;)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Fvblang%2Fissues%2F94%23issuecomment-305659401&data=02%7C01%7Cadgreen%40microsoft.com%7Ce2788aef65c747599d8208d4a9517aef%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636319614809310692&sdata=0sdiRVtYLvI99JVc5WkBWKs4Tn%2FNf2y%2BL6rZKrbqbSY%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKDTyotKlQBzGFMOD316SejeHKz8Svjyks5r_1yFgaJpZM4Nq3mr&data=02%7C01%7Cadgreen%40microsoft.com%7Ce2788aef65c747599d8208d4a9517aef%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636319614809310692&sdata=p8uRpNCRsVxuvi8TLovG3V5WvMZYmcKBWKt%2FLjNv9iU%3D&reserved=0.
This idea addresses scenario #95.
A new
Null
literal in VB which always evaluates to either a null reference or a null nullable value.Advantages
Would be more intuitive. Addresses the problem without changing the semantics of Nothing or the If operator.
Drawbacks
There's no way to enforce this at run-time because there's no difference between a null reference created by
Null
and a null reference created byNothing
. All conversion run-time operators will continue to convert a null reference to the default value of the target type.