What condition, or lack thereof, am I even testing for again???
-
Condensed and renamed to protect the guilty...
Public Sub TestThis(bFlag as Boolean, objVar as Object)
If (Not bFlag) And (bFlag <> Not CBool(objVar Is Nothing)) Then 'do some stuff End If
End Sub
I know the
CBool
is completely unneeded. But I'm having a heck of a time understanding what this little snippet was supposed to be testing for, or how it even came into existence in the first place. It seems like it would be cleaner to just test:(Not bFlag) And Not (objVar Is Nothing)
There are actually several other instances of this kind of test that I think are just there for a confusion factor. They all follow the same basic pattern of:
(Not boolean1) And (boolean1 <> boolean\_test\_condition)
In order for the whole test to be True, the first Boolean must be False, so boolean test condition on the right side MUST be True. Why even bother comparing the test condition result against the first value?
(Not boolean1) And boolean\_test\_condition
I'm so ripping my hair out every time I have to dive into legacy code like this. Good thing it's Friday!
-
Condensed and renamed to protect the guilty...
Public Sub TestThis(bFlag as Boolean, objVar as Object)
If (Not bFlag) And (bFlag <> Not CBool(objVar Is Nothing)) Then 'do some stuff End If
End Sub
I know the
CBool
is completely unneeded. But I'm having a heck of a time understanding what this little snippet was supposed to be testing for, or how it even came into existence in the first place. It seems like it would be cleaner to just test:(Not bFlag) And Not (objVar Is Nothing)
There are actually several other instances of this kind of test that I think are just there for a confusion factor. They all follow the same basic pattern of:
(Not boolean1) And (boolean1 <> boolean\_test\_condition)
In order for the whole test to be True, the first Boolean must be False, so boolean test condition on the right side MUST be True. Why even bother comparing the test condition result against the first value?
(Not boolean1) And boolean\_test\_condition
I'm so ripping my hair out every time I have to dive into legacy code like this. Good thing it's Friday!
:doh: X|
public void WriteCode(ICodeContext ctx)
{
throw new BrainNotFoundException();
}Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions. Dave Barry Read more at [BrainyQuote](http://www.brainyquote.com/quotes/topics topic_technology.html#yAfSEbrfumitrteO.99)[^]
-
Condensed and renamed to protect the guilty...
Public Sub TestThis(bFlag as Boolean, objVar as Object)
If (Not bFlag) And (bFlag <> Not CBool(objVar Is Nothing)) Then 'do some stuff End If
End Sub
I know the
CBool
is completely unneeded. But I'm having a heck of a time understanding what this little snippet was supposed to be testing for, or how it even came into existence in the first place. It seems like it would be cleaner to just test:(Not bFlag) And Not (objVar Is Nothing)
There are actually several other instances of this kind of test that I think are just there for a confusion factor. They all follow the same basic pattern of:
(Not boolean1) And (boolean1 <> boolean\_test\_condition)
In order for the whole test to be True, the first Boolean must be False, so boolean test condition on the right side MUST be True. Why even bother comparing the test condition result against the first value?
(Not boolean1) And boolean\_test\_condition
I'm so ripping my hair out every time I have to dive into legacy code like this. Good thing it's Friday!
That's called obfuscation. Theoretically, it could be intended (protection against reverse engineering, or just abuse of the colleagues who have to maintain that code). But more often, it happens due to other factors. E.g. the law of thermodynamics: things get worse under pressure. Or medical conditions like hypocaffeinemia.