Panopticon Central

a blog on Visual Basic, .NET and other stuff

  Home :: Contact :: Syndication  :: Login
  496 Posts :: 19 Stories :: 3378 Comments :: 637 Trackbacks

News

The information in this weblog is provided "AS IS" with no warranties, and confers no rights.

My Book

Picture

My Recent Posts

Article Categories

Archives

Post Categories

Microsoft Blogs

Samples

Technical Blogs

VB Links

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.

posted on Monday, November 17, 2003 12:00 PM

Feedback

# re: Is too! IsNot! 11/17/2003 1:04 PM Mike Gunderloy
Excellent! I'm hoping the IDE will also AutoCorrect "If x Is Not Nothing" to "If x IsNot Nothing" so I don't have to change my (bad) typing habits at all.

# re: Is too! IsNot! 11/17/2003 2:05 PM HumanCompiler
No more confusion with switching from T-SQL to VB.NET, weehaw ;) Might be too late though since I can use VB.NET instead of T-SQL in Yukon though :P

# re: Is too! IsNot! 11/17/2003 2:16 PM 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 :-)

# re: Is too! IsNot! 11/17/2003 2:43 PM Adam Kinney
Awesome! *applause* That was always a confusing point for me when switching to VB, it just seemed awkward. Thanks for listening to the masses.

# re: Is too! IsNot! 11/17/2003 5:56 PM 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. Karl P.S. - I use null instead of nothing mostly because the framework itself uses null over nothing (system.NullReferenceException)

# re: Is too! IsNot! 11/17/2003 9:40 PM Raj Chaudhuri
Thank you.

# IsNot 11/17/2003 10:50 PM .NET From India
Wow now we need not remember to put a Not before a condition to negate the condition. A new operator called IsNot appears in Whidbey. Paul has more info. It is the small things that make a big difference Paul....:-)

# re: Is too! IsNot! 11/18/2003 12:26 AM 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.

# re: Is too! IsNot! 11/18/2003 5:22 AM 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...

# re: Is too! IsNot! 11/18/2003 10:46 AM Paul Vick
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'.")

# re: Is too! IsNot! 11/18/2003 1:12 PM russ
thanks paul!

# re: Is too! IsNot! 11/18/2003 2:46 PM Brijesh Chawla
I always end up doing... If X is Nothing then 'do nothing else 'do stuff end if This is just one of the ways I waste processor cycles in favor of code readability. :-)

# re: Is too! IsNot! 11/19/2003 12:55 AM Simon
FINALLY I can write: If Not consumedBeer IsNot > 7 then....

# re: Is too! IsNot! 12/28/2003 6:33 AM Paul
Only works for operands that have reference types :-(

# re: Is too! IsNot! 1/4/2004 6:43 PM


# Is VB.net an ugly language? 2/23/2004 8:21 AM Karl's .Net Blog


# VB.NET getting uglier and uglier 2/23/2004 9:41 AM IXml* - Welcome to the real world


# re: Is too! IsNot! 2/23/2004 9:44 AM 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.”) 'Or 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.

# re: Is too! IsNot! 2/23/2004 11:30 AM 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 Console.Write(obj.ToString()) End If If obj = Nothing Then Console.Write("Nothing!") End If 'Other types need to be converted to Object !?!?!?!?! If CType(list, Object) <> Nothing Then Console.Write(list.ToString()) End If If CType(list, Object) = Nothing Then Console.Write("Nothing!") 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...

# re: Is too! IsNot! 2/23/2004 11:36 AM Daniel Cazzulino
Well, the operator is not defined in Object, looks like a compiler thing... weird, to say the least.

# re: Is too! IsNot! 11/19/2004 10:30 AM 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?

# re: Is too! IsNot! 11/19/2004 10:47 AM 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.

# This little thing... 11/19/2004 11:07 AM 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.



# re: Is too! IsNot! 11/19/2004 11:16 AM Tanel
shame om you!

# re: Is too! IsNot! 11/19/2004 11:29 AM 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.

# re: Is too! IsNot! 11/19/2004 11:51 AM 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.

# re: Is too! IsNot! 11/19/2004 1:07 PM 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 !

# You can read more on this at Slashdot. 11/19/2004 1:47 PM Slashdotter
You can read more on this at slashdot.

# re: Is too! IsNot! 11/19/2004 1:49 PM 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...


# re: Is too! IsNot! 11/19/2004 3:06 PM 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

# re: Is too! IsNot! 11/19/2004 5:02 PM What i want to know is...
How does Paul respond?

# Ridiculous 11/19/2004 5:14 PM 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.

# re: Is too! IsNot! 11/19/2004 6:45 PM 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.


# re: Is too! IsNot! 11/19/2004 9:46 PM 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.

# re: Is too! IsNot! 11/22/2004 1:48 PM Daniel Joyce
http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PG01&p=1&u=%2Fnetahtml%2FPTO%2Fsrchnum.html&r=1&f=G&l=50&s1=%2220040230959%22.PGNR.&OS=DN/20040230959&RS=DN/20040230959

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.


# IsNot owned by Microsoft, United States Patent Application 20040230959 2/22/2005 9:21 AM Is
You can't use IsNot here, it is owned by Microsoft (soon)! They invented it!!

http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PG01&p=1&u=%2Fnetahtml%2FPTO%2Fsrchnum.html&r=1&f=G&l=50&s1=%2220040230959%22.PGNR.&OS=DN/20040230959&RS=DN/20040230959

# re: Is too! IsNot! 1/11/2006 11:55 AM 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.

Post Feedback

Title:
Name:
Url:
Comments: