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

Is Not Nothig, should be something! #581

Closed
VBAndCs opened this issue Oct 27, 2020 · 12 comments
Closed

Is Not Nothig, should be something! #581

VBAndCs opened this issue Oct 27, 2020 · 12 comments

Comments

@VBAndCs
Copy link

VBAndCs commented Oct 27, 2020

What is wrong with: If Obj Is Not Nothing Then?

I think IsNot was a bad decision to make in the first place. Is Not Nothing doesn't compile now, so, it is possible to allow it and convert it under the hood to IsNot Nothing. The first is the natural readable syntax, and there is nothing confusing about it, both for human and compiler. I am aware that some will argue that 'Not Nothingis not a Boolean expression, but it is a normal English expression, that VB tries to be as close as possible to it. And as long there is no other possible meaning toIs Not Nothing`, so, there is no need at all to forbid it. Again: This is VB not C#, where the compiler should out smart us!

@VBAndCs
Copy link
Author

VBAndCs commented Oct 27, 2020

I can also debate that Is Not Object is also OK. But let's take it one step at a time. :)

@pricerc
Copy link

pricerc commented Oct 27, 2020

SQL allows this:

Column Is Not Null
Not Column Is Null

It's kind of a pity that:

If Obj Is Something Then

would be a breaking change.

@VBAndCs
Copy link
Author

VBAndCs commented Oct 27, 2020

would be a breaking change.

Not necessarily. VB introduced the concept of a smart non breaking keywords with IinQ and Iterator, and Async. This is a valid syntax:
Dim x = From from In {1, 2}

LinQ Keywords are bound only to their context. So, It is possible to have the new Something keyword, that is treated as a keyword only after the Is keyword, otherwise it is a normal token. The precedence will be for var names and member names, so, no old code will break.
This should allow us to add to the lang many wonderful things without breaking anything.

@VBAndCs
Copy link
Author

VBAndCs commented Oct 27, 2020

Besides, we don't need the something keyword. This is a perfect statement:
If Obj Is Then
If this seems confusing, there is another approach:
If TypeOf obj Is Object Then
This will be true for all types except when Obj is Nothing. So, We just want to shorten this expression:
If obj Is Object Then
This is a perfect expression, and can't conflect with any var name, since we can't use the keyword object as a var name, unless using [object]. This us not the same for other classes (not keywords) so, the TypeOf is necessary. So, VB can allow this special case with intrinsic (keyword) types:
If Obj is String Then
And as I described, this will gave us the opportunity to check for nulls by checking against Object:
If obj Is Object Then
This is how a smart VB should be.

@gilfusion
Copy link

Consistency is important, though.

Today, x Is Not y means x Is (Not y). It would be bad for it to sometimes mean x Is (Not y) and sometimes x IsNot y, depending on what is entered for y. So, for VB, I would consider it a no-go.

For a brand new language, where consistency doesn't have to fight with compatibility, I wouldn't mind it. My hobby BASIC compiler actually parses Is Not the same as IsNot (and Else If the same as ElseIf, ForEach the same as For Each, and DoWhile the same as Do While, for the sake of flexibility and consistency).

@VBAndCs
Copy link
Author

VBAndCs commented Oct 27, 2020

Sure it is consistent. Is is used only with objects and types, so, there is no way here to deal with a value. Even if VB did implicitly convert objects to Booleans (as I wish), it is still impossible in this context, because both sides are objects/types. So, Is forces its context here, as happens in any human language. This is the core definition of Consistency to me.

@gilfusion
Copy link

Actually, thanks to late-bound and boxing, you can write this:

Dim x As Object = True
Dim y As Object = False
Console.WriteLine(x Is Not y)

(Perhaps strangely, the result is False, since they are different boxed Booleans.)

Also, you can overload the Not operator (I tried this in some of my prototypes for #517 to negate pattern objects.), so that also means the result of a Not expression could be just about anything, including an object that would be valid for the existing Is operator.

Again, not saying I dislike the syntax, but backward compatibility with scenarios like these probably makes it impossible for VB.

@VBAndCs
Copy link
Author

VBAndCs commented Oct 28, 2020

(Perhaps strangely, the result is False, since they are different boxed Booleans.)

In fact you just reported a bug that needs a fix. This is insane behaviour of VB and no one would ever write code with this nonsense. If Is is involved, Not can't be a logical operator, since this boxing reference checking is totally useless.
If one person of millions of developers had ever overloaded Not to return an object to check it as a reference (and I doubt that), it will not be a heavy cost for him to fix that!
I can't blame C# fanatics if they hold this against VB. It is defiantly a bad design.

@salelele
Copy link

See.issue.no 546.of August 3. I tend.to.agree.that 'Something' is shorthand.for 'Is.Not Nothing'

@VBAndCs
Copy link
Author

VBAndCs commented Oct 29, 2020

@salelele
I am not proposing to use something as a keyword here. Something in the title is just a rhetorical expression as the opposite of is not nothing. My alternative to something here is to:
' If obj Is Object Then'

This is a perfect expression, and can't conflict with any var name, since we can't use the keyword object as a var name, unless using [object]. This us not the same for other classes (not keywords) so, the TypeOf is necessary. So, VB can allow this special case with intrinsic (keyword) types:
'If Obj is String Then'
And as I described, this will gave us the opportunity to check for nulls by checking against Object:
'If obj Is Object Then'

@paul1956
Copy link

What and I missing "IsNot Nothing" works as expected? What does adding a space do?

If node.ParameterList IsNot Nothing Then
    Parameters = CType(node.ParameterList?.Parameters, SeparatedSyntaxList(Of CSS.ParameterSyntax))
End If

@CyrusNajmabadi
Copy link
Member

Closing this out as this is already legal and has sane semantics for vb. We're definitely not going to take a breaking change here that could impact real programs that have already shipped.

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

No branches or pull requests

6 participants