Lazy Evaluation ternary op?
-
I know MS (FINALLY) added in lazy evaluation versions of And (AndAlso) and Or (OrElse). Have they perchance introduced a lazy eval version of the ternary-operator function (Iif)? Thats one thing i sorely miss from the C/Java world is the nice ?: operator. Iif can sort of emulate it, but Iif always evaluates both conditions (true AND false)... where as the ?: one only evaluates which ever one is selected by the condition. The Non-Lazy Iif is all but useless for the most very simplest simplest basic cases. Thanks in advance
-
I know MS (FINALLY) added in lazy evaluation versions of And (AndAlso) and Or (OrElse). Have they perchance introduced a lazy eval version of the ternary-operator function (Iif)? Thats one thing i sorely miss from the C/Java world is the nice ?: operator. Iif can sort of emulate it, but Iif always evaluates both conditions (true AND false)... where as the ?: one only evaluates which ever one is selected by the condition. The Non-Lazy Iif is all but useless for the most very simplest simplest basic cases. Thanks in advance
Whosit wrote: Thats one thing i sorely miss from the C/Java world is the nice ?: operator. Iif can sort of emulate it, but Iif always evaluates both conditions (true AND false)... where as the ?: one only evaluates which ever one is selected by the condition. The Non-Lazy Iif is all but useless for the most very simplest simplest basic cases. I suspect Iif is implemented as a function. See, the worst thing about Iif is that it return an object, and if Option Strict is On, you'll need to cast, even if both types are correct.
It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)
-
Whosit wrote: Thats one thing i sorely miss from the C/Java world is the nice ?: operator. Iif can sort of emulate it, but Iif always evaluates both conditions (true AND false)... where as the ?: one only evaluates which ever one is selected by the condition. The Non-Lazy Iif is all but useless for the most very simplest simplest basic cases. I suspect Iif is implemented as a function. See, the worst thing about Iif is that it return an object, and if Option Strict is On, you'll need to cast, even if both types are correct.
It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)
Ha! That's not the worst thing about "IIF". The worst thing is that it tries to Evaluate both Expressions before returning a Value. What it should do is only Evaluate the Expression and then Return the Value that is absolutely neccessary! For example, you can never do this: Dim MyObject As Object = Nothing rsData.Fields("MyField").Value = IIF(IsNothing(MyObject), "", MyObject.Name) This will always give you an Error because MyObject is nothing when it tries to Evaluate "MyObject.Name". So I ask...why does it do that? :wtf:
-
Ha! That's not the worst thing about "IIF". The worst thing is that it tries to Evaluate both Expressions before returning a Value. What it should do is only Evaluate the Expression and then Return the Value that is absolutely neccessary! For example, you can never do this: Dim MyObject As Object = Nothing rsData.Fields("MyField").Value = IIF(IsNothing(MyObject), "", MyObject.Name) This will always give you an Error because MyObject is nothing when it tries to Evaluate "MyObject.Name". So I ask...why does it do that? :wtf:
Because IIf is not an operator, it's a function, defined like this:
Function IIf(Byval x as boolean, Byval o1 as object, Byval o2 as object) as Object
If x then
Return o1
Else
Return o2
End if
End FunctionSee?
It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)
-
Because IIf is not an operator, it's a function, defined like this:
Function IIf(Byval x as boolean, Byval o1 as object, Byval o2 as object) as Object
If x then
Return o1
Else
Return o2
End if
End FunctionSee?
It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)