VB.NET Chapter #3 - IsSomething?

I once worked together with this developer that seems to enjoy (or had a rather bad habbit of) turning every logic expression into its negative complement. That is, instead of properties (or fields) named Enabled or Visible, his properties would be named Disabled or Hidden. It made every expression look like:

If Not Disabled And Not Hidden Then       

    'enabled and visible       

End If

In my honest opinion this was just confusing  (and it should be in your opinion too). You could of course simplify such an expression to become:

If Not (Disabled Or Hidden) Then       

    'enabled and visible       

End If

To me this was better, but still negatively mind blowing. To make things even worse, he sometimes added properties like NotEnabled or NotVisible, resulting in code like:

If Not NotEnabled And Not NotVisible Then       

    'enabled and visible       

End If

Ofcourse the exact same expression as the in the first example - but who would ever know. The simplfied version would be:

If Not (NotEnabled Or NotHidden) Then       

    'enabled and visible       

End If

Expressions like this these are, if not insane, at least not logical. I was a mystery to me why someone would even adopt such bad habits - well, until recently. As you’ve seen from other posts I’ve never been a big VB.NET fan, but it’s not until recently that I’ve had the chance to work substantially with it. I’m still no big VB.NET fan. I’ve figured that there is one statement that, even if I use it over and over again, still confuses me. It’s:

If Not obj is Nothing Then       

    'obj is something       

End If

What is that?! “If not object is nothing”? OK, I see myself as reasonably well equipped when it comes to logical thinking, but this statement it just confusing. I usually have to look at it 3-4 times, pulling fingers, before I realize that the statement is correct, and that it’s in fact what I need. But any sane person know that the question is “If object is something”! So, why didn’t they invent a construct like this:

If obj is Something Then       

    'obj is something       

End If

Wouldn’t this make life a lot more easier? You tell me.

Leave a comment...

Powered by WordPress. Entries (RSS) and Comments (RSS).