哪一个更倾向于抛出错误?(Which one is more tend to throw error?)
我正在审查一个应用程序,我想知道哪一个更容易出错?
Public Function ToBool(ByVal vsValue As String) As Boolean If IsNothing(vsValue) OrElse vsValue = "" Then Return False End If If UCase(vsValue) = "TRUE" Or vsValue = "1" Or UCase(vsValue) = "Y" Or UCase(vsValue) = "YES" Or UCase(vsValue) = "T" Then Return True Else Return False End If End Function要么
Public Function ToBool(ByVal vsValue As String) As Boolean If IsNothing(vsValue) OrElse vsValue = "" Then Return False ElseIf UCase(vsValue) = "TRUE" Or vsValue = "1" Or UCase(vsValue) = "Y" Or UCase(vsValue) = "YES" Or UCase(vsValue) = "T" Then Return True Else Return False End If End FunctionI am reviewing an application and I am wondering which one is more error-prone?
Public Function ToBool(ByVal vsValue As String) As Boolean If IsNothing(vsValue) OrElse vsValue = "" Then Return False End If If UCase(vsValue) = "TRUE" Or vsValue = "1" Or UCase(vsValue) = "Y" Or UCase(vsValue) = "YES" Or UCase(vsValue) = "T" Then Return True Else Return False End If End Functionor
Public Function ToBool(ByVal vsValue As String) As Boolean If IsNothing(vsValue) OrElse vsValue = "" Then Return False ElseIf UCase(vsValue) = "TRUE" Or vsValue = "1" Or UCase(vsValue) = "Y" Or UCase(vsValue) = "YES" Or UCase(vsValue) = "T" Then Return True Else Return False End If End Function最满意答案
由于两个代码示例在语义上是相同的,因此哪个更容易出错是没有区别的。 如果代码进入第一个If块的主体,那么在两种情况下它都将退出该函数。 如果它没有进入第一个If块的主体,则执行的代码也是相同的。
There is no difference as to which one is more error prone, as the two code examples are semantically identical. If the code enters the body of the first If block, then in both cases it will exit the function. The code that executes if it does not enter the body of the first If block is also identical.
更多推荐
发布评论