-
Notifications
You must be signed in to change notification settings - Fork 64
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 ... OrIs #519
Comments
My syntax would be:
|
Pattern matching is a better solution than this. #337 |
I would prefer composable types: If item Is XmlSchemaElement Or XmlSchemaComplexType Then because it's something that can be used generally, and not just in the context of type-checking. |
@tverweij |
@Happypig375 There's still a problem, even with pattern matching: how can you refer to the item in question: Select item
Case XmlSchemaElement, XmlSchemaComplexType
' What should the programmer do here?
' Cast item to XmlSchemaElement? to XmlSchemaComplexType? It might be the other one.
End Select Without composable types, VB has no way of describing something that "might be either |
@Happypig375 |
Or already has two functions (logical and bitwise), and adding a third one will complicate things if the three ORs appeared in the same context, which will need some |
I compare this proposal to string handling:
I normally write this as:
But it could also be written as:
Composable types require some magic Boolean operations as far as I can see. |
This is an abomination and wrong, if for some reason aString = "ab". |
Explain I am willing to learn. |
There is a prototype of #481 |
Using |
@zspitz I also implemented a version that used operators like Note: |
I like this solution. |
Is (Of) is OK. It doesn't need new keywords, but have more symbols than using OrIs, which will be more readable when splitting long lines. |
@VBAndCs It also preserve the meaning of old albeit broken code. |
@VBAndCs |
This looks like chicking a generic type params, which would be nice if done instead of using reflection. So I advic to modify your proposal to do that. |
I don't like the syntax of this one. Trending toward C# type syntax. Much like tverweij's version. VBAndCs original suggestion or zspitsz simplified version "read" much better. |
@WolvenRA @VBAndCs's proposed syntax involves implementing 8 new operators,
Whereas @AdamSpeight2008's involved zero new operators, just expanding the capability of the two existing operator object Is (Of these types / objects) |
No... I didn't say I wanted any of those. Adding the "Of" portion seems redundant if you're starting with "If TypeOf". The suggestion I like is zspitz's composable types; 'If item Is XmlSchemaElement Or XmlSchemaComplexType Then' Seems much cleaner and consistent with current VB syntax. Also, it seems like the compiler could "translate" (lower, rewrite) the "TypeOf Is ... Or (OrIs) ..." to the; |
I only suggested OrIs and AndIsNot. No need for anymore operators as this is just type chicking and no need for shortcircuiting operator (which willbe the default, since we will not break anything). Any object can have only one type, so we can't use AndIs nor OrIsNot. |
@VBAndCs Don't fall for the fallacy of "We can't give the same operator different meanings." In insolation and without context what does the character The definition of what an operator does is defined by the object that defines them. Edit Found the hyperlinked grammar for VB.net (version 11) |
That's not quite accurate. A given object has one type (the result of the call to |
I suppose I have been on a bit of a libraries over new language features trend lately, but would these functions be helpful for this scenario? Function IsAny(Of T1, T2)(obj As Object)
Return TypeOf obj Is T1 OrElse TypeOf obj Is T2
End Function
Function IsAny(Of T1, T2, T3)(obj As Object)
Return TypeOf obj Is T1 OrElse TypeOf obj Is T2 OrElse TypeOf obj Is T3
End Function
Function IsAll(Of T1, T2)(obj As Object)
Return TypeOf obj Is T1 AndAlso TypeOf obj Is T2
End Function
Function IsAll(Of T1, T2, T3)(obj As Object)
Return TypeOf obj Is T1 AndAlso TypeOf obj Is T2 AndAlso TypeOf obj Is T3
End Function Here's the original example written using one of them: If IsAny(Of XmlSchemaElement, XmlSchemaComplexType)(item) Then |
I propose to add a new
OrIs
Keyword. It will help to rewrite this:as:
This will imply adding
AndIsNot
keyword to work withIsNot
.The text was updated successfully, but these errors were encountered: