On Jan 25, 2007, at 11:06 PM, Daniel Stenning wrote:
Ok - to illustrate how useful this would be - here is how it could
be used
with the new syntax:
Dim myRef As myClass
if myRef FROM getA() <> nil then
.. do something with myRef
elseif myRef FROM getB() <> nil then
.. do something with myRef
elseif myRef FROM getC() <> nil then
.. do something with myRef
end if
1 * IF
2 * ELSEIF
1 * END IF
TOTAL = 4 lines for the branching
And here is how this would have to be written in RB currently:
Dim myRef As myClass
myRef = getA()
if myRef <> nil then
.. do something with myRef
Else
myRef = getB()
if myRef <> nil then
.. do something with myRef
else
myRef = getC()
if myRef <> nil then
.. do something with myRef
end if
end if
End if
3 * if
2 * else
3 * end if
TOTAL = 8 lines for the branching.
The forner is much clearer in meaning.
I disagree as the latter form is easier for me to follow and is far
less prone to an oops. I will agree that it takes more lines of
code, but fewer lines of code don't necessarily translate to faster
code.
How about this code:
Dim myRef As MyClass
Function getA(ByRef myRef As MyClass) As Boolean
// Same for getB and getC
// stuff to set the contents of myRef
If it_Is_True
Return True
else
Return False
end if
End Function
If Not getA(myRef) Then
// Do that stuff
ElseIf getB(myRef) Then
// Do the other stuff
ElseIf getC(myRef) Then
// Do the last stuff
Else
// something went horribly wrong and the world will now reboot
End If
It looks to me that by making the getA/getB/getC functions more
aware, you further simplify the If - ElseIf - End If construct. That
results in:
1 * IF
3 * ELSEIF
1 * END IF
TOTAL = 5 lines for the branching
But, your original example didn't take into account the possibility
that getA, getB, and getC would fail to set myRef, so it's the same.
On 26/1/07 01:44, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
I also don't see how you
can say that it makes for simpler to read code. Perhaps it is
occasionally useful, but those times are pretty rare IMHO.
I agree with Joe.
Tim
--
Tim Jones
[EMAIL PROTECTED]
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>