Let's discuss where VB is going and interact with some of those that are making it happen!
Also considering a Select Case Expression
that lowers to Inline If Expression
Return Select Case operand When condition0
Case clauseslist0 When condition1 := result0
Case clauseslist1 := result1
Case Else When condition2 := result2
Case Else := result3
Else := result4
End Select
Example of the Lowering
Dim temp = If(condition0,
If(clauseslist0.InContextOf(operand) AndAlso condition1, result0, ' Case clauseslist0 When condition1
If(clauseslist1.InContextOf(operand), result1, ' Case clauseslist1
If(condition2, result2, ' Case Else When condition2
result3 ' Case Else
)
)
),
result4 ' Else
)
Return temp
:=
over return
which removes the need of having the select
nested within the return
.
Select Case
structure, and its lowering.:=
rather than return
as is similar to existing syntax of named arguments
. This indicate the partial result of this sub-expression, and not the return value of the function. Dim sign = $"{NameOf(value) is {
( Select Case value
Case Is > 0
:= "Positive"
Case Is = 0
:= "Zero"
Case Is < 0
:= "Negative"
Case Else
:= Throw New Exception("Should be impossible to get here in my analysis.")
End Select
) }"
Dim sign = $"{NameOf(value) is { If(value > 0, "Positive", If(value = 0, "Zero", If( value<0, "Negative", Throw New Exception("Should be impossible to get here in my analysis.") ))) }"
Although I see where you are going with this, I still feel that I'd prefer to write it "long hand" if for nothing more than clarity sake. Once we have too many symbols floating around, the intent of what the developer is trying to do (IMO) seems to get lost in the noise.
Dim sign = "Positive"
Select Case value
Case > 0: sign="Positive"
Case = 0: sign="Zero"
Case < 0: sign="Negative"
Case Else: Throw New Exception("Should be impossible to get here in my analysis.")
End Select
or
Dim sign="Zero"
Select Case value
Case > 0: sign = "Positive"
Case < 0: sign = "Negative"
Case Else ' Already determined
End Select
To me the second example (above) is easier to read making it easier to maintain. I also (based on looking at this very little) feel that it is easier to maintain/expand/adjust later. This, of course, could just be a case of me being used to doing it this way; so I'll have to admit that may be influencing my take on this.
As for the :=
there does seem to be something that could create a bit of a parsing issue since a :
already means something; I'm sure that could be dealt with... but it is something that would have to be considered.
I suppose I just feel that having an "inline" Select Case
is trying to force something into a position where there may be a better option. I recall from "ancient" history that there used to be something similar to:
ON value GOTO 100, 200, 300
There was also a "shorthand" version of IF
IF X = 50 GOTO 100: GOTO 200
So this begs the question of whether or not there could be a different syntax to accomplish this... such as:
If {expression_list} Return {return_list}
So it could be something like...
If {value < 0, value = 0, value > 0} Return {"Negative", "Zero", "Positive"}
If {value, Not value} Return {"True", "False"}
The expression list and the return list would need to, of course, match in length other an compiler error would occur.
I'm not saying that this is something that should be done... I just feel that forcing a Select Case
into this doesn't feel like the way to go.
Shadows
on inherited members I can understand but the inner class that threw me. I don't think I've seen a example of the warning documented any where. Maybe i missed in the vb.net language reference?