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

<p>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?</p>

[{'answer_id': 5792, 'author': 'Adam Haile', 'author_id': 194, 'author_profile': 'https://Stackoverflow.com/users/194', 'pm_score': 2, 'selected': False, 'text': "<p>VB is full of things like that trying to make it both &quot;like English&quot; and comfortable for people who are used to languages that use () and {} a lot.\nAnd 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.</p>\n<p>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.</p>\n"}, {'answer_id': 5809, 'author': 'deadtime', 'author_id': 614, 'author_profile': 'https://Stackoverflow.com/users/614', 'pm_score': 2, 'selected': False, 'text': '<p>I\'m leaning towards the &quot;Is Nothing&quot; alternative, primarily because it seems more OO.</p>\n<p>Surely Visual Basic <a href="http://web.archive.org/web/20050308014055/http://ea.3leaf.com/2004/08/vb_adds_aint_ke.html" rel="nofollow noreferrer">ain\'t</a> got the Ain\'t keyword.</p>\n'}, {'answer_id': 5837, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 8, 'selected': True, 'text': '<p>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. </p>\n\n<p>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.</p>\n'}, {'answer_id': 5889, 'author': 'proudgeekdad', 'author_id': 702, 'author_profile': 'https://Stackoverflow.com/users/702', 'pm_score': 5, 'selected': False, 'text': '<p>I agree with "Is Nothing".  As stated above, it\'s easy to negate with "IsNot Nothing". </p>\n\n<p>I find this easier to read...</p>\n\n<pre><code>If printDialog IsNot Nothing Then\n    \'blah\nEnd If\n</code></pre>\n\n<p>than this...</p>\n\n<pre><code>If Not obj Is Nothing Then\n    \'blah\nEnd If\n</code></pre>\n'}, {'answer_id': 5901, 'author': 'Chris Tybur', 'author_id': 741, 'author_profile': 'https://Stackoverflow.com/users/741', 'pm_score': 1, 'selected': False, 'text': "<p>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.</p>\n"}, {'answer_id': 7815, 'author': 'Jack Snipes', 'author_id': 1382, 'author_profile': 'https://Stackoverflow.com/users/1382', 'pm_score': 6, 'selected': False, 'text': '<p>I find that <a href="http://weblogs.asp.net/psteele/default.aspx" rel="noreferrer">Patrick Steele</a> answered this question best on his blog: <a href="http://weblogs.asp.net/psteele/archive/2005/06/03/410336.aspx" rel="noreferrer">Avoiding IsNothing()</a></p>\n\n<p>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.</p>\n\n<p><em>Edit - VoteCoffe\'s comment here</em></p>\n\n<p>Partial article contents: After reviewing more code I found out another reason you should avoid this: It accepts value types! Obviously, since IsNothing() is a function that accepts an \'object\', you can pass anything you want to it. If it\'s a value type, .NET will box it up into an object and pass it to IsNothing -- which will always return false on a boxed value! The VB.NET compiler will check the "Is Nothing" style syntax and won\'t compile if you attempt to do an "Is Nothing" on a value type. But the IsNothing() function compiles without complaints. -PSteele – VoteCoffee</p>\n'}, {'answer_id': 24494417, 'author': 'KyleMit', 'author_id': 1366033, 'author_profile': 'https://Stackoverflow.com/users/1366033', 'pm_score': 5, 'selected': False, 'text': '<h2>You should absolutely avoid using <code>IsNothing()</code></h2>\n<p>Here are <strong>4 reasons</strong> from the article <a href="http://blog.reneorban.com/2011/12/vbnet-isnothing-vs-is-nothing.html" rel="nofollow noreferrer"><strong>IsNothing() VS Is Nothing</strong></a></p>\n<ol>\n<li><p>Most importantly, <code>IsNothing(object)</code> has everything passed to it as an object, even value types!  Since value types cannot be <code>Nothing</code>, it’s a completely wasted check.<br />\nTake the following example:</p>\n \n<pre class="lang-vb prettyprint-override"><code> Dim i As Integer\n If IsNothing(i) Then\n    \' Do something \n End If\n</code></pre>\n<p>This will compile and run fine, whereas this:</p>\n<pre class="lang-vb prettyprint-override"><code> Dim i As Integer\n If i Is Nothing Then\n     \'   Do something \n End If\n</code></pre>\n<p>Will not compile, instead the compiler will raise the error:</p>\n<blockquote>\n<p>\'Is\' operator does not accept operands of type \'Integer\'.<br />\nOperands must be reference or nullable types.</p>\n</blockquote>\n</li>\n<li><p><code>IsNothing(object)</code> is actually part of part of the <code>Microsoft.VisualBasic.dll</code>.<br />\nThis is undesirable as you have an unneeded dependency on the VisualBasic library.</p>\n</li>\n<li><p>Its slow - 33.76% slower in fact (over 1000000000 iterations)!</p>\n</li>\n<li><p>Perhaps personal preference, but <code>IsNothing()</code> reads like a <a href="http://blog.codinghorror.com/new-programming-jargon/" rel="nofollow noreferrer">Yoda Condition</a>.  When you look at a variable you\'re checking its state, with it as the subject of your investigation.</p>\n<p>i.e.  does <em>it</em> do x? --- <strong>NOT</strong> Is <code>x</code>ing a property of <em>it</em>?</p>\n<p>So I think <code>If a IsNot Nothing</code> reads better than <code>If Not IsNothing(a)</code></p>\n</li>\n</ol>\n'}, {'answer_id': 35823080, 'author': 'ybacou', 'author_id': 6024284, 'author_profile': 'https://Stackoverflow.com/users/6024284', 'pm_score': -1, 'selected': False, 'text': '<p>Is Nothing requires an object that has been assigned to the value Nothing. IsNothing() can take any variable that has not been initialized, including of numeric type. This is useful for example when testing if an optional parameter has been passed.</p>\n'}]
['https://Stackoverflow.com/questions/5791', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/133/']