Does anyone here use VB.NET and have a strong preference for or against using 'IsNothing' as opposed to 'Is Nothing' (for example, 'If IsNothing(anObject)' or If anObject Is Nothing...')? If so, why?

EDIT: If you think they're both equally acceptable, do you think it's best to pick one and stick with it, or is it OK to mix them?

+1  A: 

VB is full of things like that trying to make it both "like english" and comfortable for people who are used to languages that use () and {} a lot. For example, on the "like english"side...VB has the "Ain't" keyword...and no, I'm not joking. And on the other side, as you already probably know most of the time you can use () with function calls if you want to, but don't have to.

I prefer IsNothing()...but I use C and C#, so that's just what is comfortable. And I think it's more readable. But go with whatever feels more comfortable to you.

Adam Haile
+3  A: 

I'm leaning towards the "Is Nothing" alternative, primarily because it seems more OO.

Surely Visual Basic ain't got the Ain't keyword.

Can VB.NET do extension methods? :)

@Deadtime: Some guy called Jeff Atwood ain't agreeing with you.

+9  A: 

If you take a look at the MSIL as it's being executed you'll see that it doesn't compile down to the exact same code. When you use IsNothing() it actually makes a call to that method as opposed to just evaluating the expression.

The reason I would tend to lean towards using "Is Nothing" is when I'm negating it becomes "IsNot Nothing' rather than "Not IsNothing(object)" which I personally feel looks more readable.

+1  A: 

I also tend to use the Is Nothing version partially from using it as much as I do in SQL.

Brian Childress
+1  A: 

I agree with "Is Nothing". As stated above, it's easy to negate with "IsNot Nothing".

I find this easier to read...

If printDialog IsNot Nothing Then
End If

than this...

If Not obj Is Nothing Then
End If

I initially used IsNothing but I've been moving towards using Is Nothing in newer projects, mainly for readability. The only time I stick with IsNothing is if I'm maintaining code where that's used throughout and I want to stay consistent.

Chris Tybur

GateKiller: But that post, I'm pretty sure, ain't serious:

Microsoft is also reported to be experimenting with "AsIf", "Maybe", and "Totally". In addition, "Catch" will likely be replaced with "Doh!", and "Finally" will be replaced with "Whatever".

Anyway, this is pretty OT so I'm stfu'ing now.

Would love to upvote this, but I also agreed strongly with the topmost answer.
+1  A: 

I find that Patrick Steele answered this question best on his blog: Avoiding IsNothing()

I did not copy any of his answer here, to ensure Patrick Steele get's credit for his post. But I do think if you're trying to decide whether to use Is Nothing or IsNothing you should read his post. I think you'll agree that Is Nothing is the best choice.

Jack Snipes