Is too! IsNot!

I got a question from “Russ” who asks whether there’s something that can be done to avoid the annoyance of having to remember to start with Not when you are testing if something is not Nothing:

If Not x Is Nothing Then Console.WriteLine(”Has a value.”)

This is something I forget to do all the time, breaking the flow of my thinking. We’ve had requests for this in the past, so for Whidbey we added an inverse operator to Is called (can you guess?) IsNot. So you can write:

If x IsNot Nothing Then Console.WriteLine(”Has a value.”)

Just one of those little things.

37 thoughts on “Is too! IsNot!

  1. Steve Hiner

    Don’t you think this is going to cause a lot of support calls?

    "I put it in right…
    If abc Isn’t Nothing Then
    but it keeps turing the end of the line green."

    How about NotLike to go with it?
    If MyString NotLike "*abc*" Then

    Maybe AndNot to go with AndAlso and OrElse? Or what about ButNot? (bad word-picture for that one)
    If MyTrueVariable ButNot MyFalseVariable Then


  2. Karl

    I don’t understand this. I’m generally against adding extra operators for the sake of it, and this really does seem like a "sake of it" kinda situation.

    Since, in .Net and unlike in ANSI SQL, null = null (as opposed to null IS null), it seems to me people should simply use the already existing and available = and <>. I don’t understand why you want to add redudant operators…especially when they can make code (and the language itself) far more ambiguous. It also encourages treating null in a unique and different manner which it isn’t in the case of objects.

    Why can’t I do:

    dim x as integer = 3
    if x is 3 then
    end if

    It seems to me one of problems with VB is you seem to add redundant operators more frequently than you solve ambigous ones. Examples:
    "or" is both a logical and bitwise operator.
    which makes code very ambiguous:
    watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite)

    String concatenation:
    + or & ? – again, overloading & shields users from understand how overloading works and that using + is truly acceptabe

    I might just be missing the point. but null = null.


    P.S. – I use null instead of nothing mostly because the framework itself uses null over nothing (system.NullReferenceException)

  3. Pingback: .NET From India

  4. RichB

    Did you consider creating a new ‘state’ called ‘something’?
    if x is something then

    end if


    Having the ‘Not’ in "if not x is nothing" has never really bothered me – what does bother me is the double negative. Double negatives are notorious for being difficult to read – especially if you didn’t write the code in the first place. I occasionally attempted to improve the situation by writing "if (x is nothing)=false then" to make my VB code easier to maintain.

    Ultimately, I reckon a ‘something’ keyword is ideal for a RAD language which shouldn’t necessarily be translating HLL tokens into MSIL tokens on a 1-to-1 fashion (as opposed to a closer-to-the-metal language like C# or MC++). The new ‘something’ keyword would be very easy for the compiler to translate to a !null in the IL.

  5. Phil Scott

    Oooh, I actually like the something idea. It’s is pretty common for me to find english majors turned programmers in my classes. They obviously cringe at the sound of me saying "if not is nothing," but I don’t think they’ll be much happier with the IsNot Nothing.

    I wonder how long it will be before I see someone write Not IsNot Nothing too…

  6. paulvick

    Karl, it seems like your question isn’t so much why we’re adding "IsNot" but why we have "Is" in the first place. It’s a good question, I’ll try to address it in an entry soon.

    Rich, we did consider the "something" idea but while it might be more grammatical, IsNot seemed to be more contained and clear as to what its intended use is. (In other words, we’d have this weird situation of people trying to pass the value "Something" as an argument or assign it to a variable. I’m not sure how *that* error message would read… "Can’t assign Something to the variable ‘x’.")

  7. Brijesh Chawla

    I always end up doing…

    If X is Nothing then
    ‘do nothing
    ‘do stuff
    end if

    This is just one of the ways I waste processor cycles in favor of code readability. πŸ™‚

  8. Pingback: Karl's .Net Blog

  9. Pingback: IXml* - Welcome to the real worl

  10. Daniel Cazzulino

    I can’t really believe this. Yet another keyword for such a stupid thing. And it’s based on the assumption that VB developers will write that ugly/unreadable code instead of something like this:
    If x <> Nothing Then Console.WriteLine(“Has a value.”)
    If x = Nothing Then Console.WriteLine("Doesn’t have a value")

    Which is FAR more readable and understandable than using that awful Is/IsNot test. It boils down to whether you want to teach VBers how to write good/maintanable/readable code or just give them new keywords to keep doing otherwise, but with less code.

  11. Daniel Cazzulino

    Well, I can’t believe it, but it’s true:

    The problem with the comparison I show above is the compiler, NOT the language. The operator = and <> is defined at the level of System.Object. Therefore, you should be able to use it with whichever descendant you have (ANY .NET type derives from it).
    It turns out that there’s apparently a bug in the VB compiler, because the code I showed compiles for a string, but not for other types. However, it DOES work for Object types. So, if you cast your variables to Object, you will be able to use the cleaner code (not so cleaner now that you need to case, but well… it’s still better/readable than Is/IsNot, IMO):

    Dim obj As Object
    Dim list As ArrayList

    ‘Object can be directly compared
    If obj <> Nothing Then
    End If

    If obj = Nothing Then
    End If

    ‘Other types need to be converted to Object !?!?!?!?!
    If CType(list, Object) <> Nothing Then
    End If

    If CType(list, Object) = Nothing Then
    End If

    I wonder how can they do such a thing… swallow an operator on the base class and show that as an error… my God…

  12. Tron

    I cannot believe that you guys filed a patent application for this. Aren’t you embarassed to claim this as your "invention" and apply for a 20 year monopoly for this tiny feature?

  13. Gabe

    The US patent system is broken. MS is simply trying to cover their collective ass. I don’t beleive MS will start suing people, but considering the ammount of lawsuits being brought against them, they would be stupid not to patent everything they can.

    This whole idea of IP firms that simply buy patents and then sue is insane! It has to stop. It will hurt EVERYONE in the long run.

  14. Dr. Nybble

    A quick Google UseNet search shows someone suggesting ‘If X IsNot Y’ in 2000, well before your patent filing date. So much for a prior art search (not a single piece of prior art is mentioned in the patent application).

    If, as you indicate, you’ve "had requests for this in the past" then the inventors listed on your application have a duty to disclose this information to the USPTO and not declare themselves (all three of them!) the true inventors.

  15. James

    Attempting to patent IsNot is outrageous. Algol 68 had IS and ISNT operators that differed from EQ and NEQ just as Is and IsNot differ from = and <>. In 1980, BASIC09 programmers could write "ADDR(A) <> ADDR(B)" to get the same effect. LISP drew the same distinction with EQ and EQUAL back in the 1960s.

  16. Mohan Das

    When a company spends these kinds of resources on patenting such trivial stuff, it shows that the company has nothing better to patent; in other words, the fount of creativity in that company runneth dry.

    Whatever happened to "innovation", Microsoft? Or is this what you call "innovation" ?

    People who work at Microsoft and agree to do this kind of crap should be ashamed of themselves. There is no honor in working like a scavenger (which is what this basically is, scavenging).

    This is a sure sign of the upcoming demise of Microsoft.

  17. Shame on You!

    All you VB users, at least go learn Delphi or Python and do something useful! VB always changes so much that you can’t compile your code in version V+1 or V-1 if you wrote it on version V !

  18. another disappointed soul

    you guys are ridiculous…

    attempting to patent something with nearly 30 years of prior usage is a foolish waste of time.

    more than likely, with your thousands of similar bogus patent applications, you’ll finally succeed in proving to the masses that the patent system is horribly broken…and then where will you be? or………is that the point?

    inquiring minds want to know…

  19. Ridiculous

    Ugh… Pathetic…. First these guys ridiculously claim something as trivial as an != as their own invention and file a patent for it. And then we have VB cry-babys overjoyed at this! LOL

  20. dismayed

    I wish there were some better way to indicate the civilized world’s displeasure with the actions of Paul Vick, Amanda Silver and this Barsan fellow (fella?). These three are truly the scum of the earth. But with their fat salaries and complete disregard for the law and common sense, I expect they’ll just keep on wasting taxpayers’ money and time with their ridiculous claims. I encourage anyone in the Seattle area, if you see one of these three on the street, kick him in the ass for me.

  21. red floyd

    Just what, precisely made you think that this was innovative enough to file for a patent on it?

    I think that the idea IsNot original enough.

  22. Bill Price

    Gee. Back in the 60’s, we chose to spell it ISNT, to be closer to standard usage. Welcome to the ancient, honorable society of IS NOT inventors.

  23. Daniel Joyce

    MS is trying to patent this stupidity. According to freestanding claim #1, C would infringe, Course, C would then count as prior art, invalidating the parts that depend on Claim 1, and freeing us all from the problems a patent on isNot would cause.

    if a and b are pointers, then (a != b) have the same effect as isNot, and the != operator would infringe.

    Note that the patent is NOT just about BASIC, given claim #1. I hope the USPTO is smart enough not to approve it, and smart enough to realize it’s anti-competitive measure designed to make a ‘free’ VB implementation impossible. Say, VB on Mono, or other .NET clones.

    Silly silly silly.

    Oh, and VB is a horrible language too.

  24. x

    So Microsoft continues to abuse the patent system. One more reason to boycott them.

    *Sigh*. And I used to like the company, back in the 1980s.


Leave a Reply

Your email address will not be published. Required fields are marked *