Author: guido.van.rossum
Date: Thu Aug 24 05:53:23 2006
New Revision: 51538
Killed the <> operator. You must now use !=.
I knew this day would come and yet I'm still sad. Having known Guido as long as I have, I also know that the likelihood he'll change his mind is about the same as Tim Peters eating anything other than Kung Pao chicken at an outing to China King restaurant. Still, I have a strong attachment to this operator so I'm returning to my blog in final remembrance and to once again explain why I like <> so much more than !=.
There are several reasons why I think <> is the better spelling for inequality. First, it's symmetrical and thus feels more closely related to its opposite, == for equality. Split either symbol vertically down the center and the two sides are mirrors of each other. The symmetry appeals to my eye.
Second, <> stands out much better in code that already has == and = strewn about it. Maybe it's just me, but != is less visually distinct and my eye has a much harder time picking this out. It always has for C and Java, will so in Python code as well.
Third and most importantly, <> is much easier to type (on a US keyboard at least). Think of the chording you have to do on a keyboard to type the two inequality operators. For <>, you hold the left shift down with your left pinkie, and then hit comma and period with the second and third fingers of your right hand. Quick and easy. With != I have to go through these movements:
Hold right shift with my right pinkie and stretch my left ring finger all the way up to the 1 key
(or hold left shift with my pinkie while doing the same left ring finger stretch)
Let up on the shift key and stretch my right ring finger up to the = key at the opposite side of the keyboard
There's no question that != is more awkward and slower to type. For me it's actually more painful too.
Let's examine some of the arguments I've heard in favor of != instead of <>.
First, TOOWTDI. This Python guiding principle stands for "There's Only One Way To Do It", and it's a principle that should be honored in this case too. Note however, this doesn't really argue in favor of either symbol -- it could just as appropriately be invoked for keeping <> and ditching !=.
Another argument I've heard is that ! is a common character meaning "not" so != clearly means "not equal", while <> means "less than and greater than" and that's nonsensical. Well, != does not mean "not equal", it means "not an assignment" which is equally <wink> nonsensical. To literally mean "not equal" in Python, you'd have to write !== and no one's suggesting that!
Third, I've heard that people coming from Java and C will be more comfortable with != than <> because that's what those languages use. This doesn't hold much water for me because any programmer worth their salt will understand that they have to make adjustments when they switch languages. How often do you type semicolons at the end of your Python statements? How often do you type colons at the end of your C conditionals? Yeah, me neither. Switching to <> when writing Python would actually be a good thing because it re-enforces the differences between Python and C/Java.
Ultimately I believe this change was made because Guido simply likes != better than <> and thus it comes down to a religious argument. Since he's the BDFL and Python is his language, he gets to make these decisions. I don't have to like it, but I'll learn to live with it... eventually.
In the meantime, here's my Ode to Inequality:
One's not assignment but looks like such
One's less and more but not by much
One's within reach, an easy touch
One looks like C, a useful crutch
My fingers ache and stretch and pull
To type the Py three inequal
The end is near for symbol's duel
I mourn the loss of diamond jewel
The BDFL's made his choice
To heed the call of Java's voice
Some will cry and some rejoice
And sed will lend a heavy hoist
I'll linger then on Py two dot
So I can have my equal not
The angle brackets killed and caught
In Guido's evil bang key plot
So join me now in sweet revolt
To Ruby, Perl, or Tcl bolt
Naw, I'm just kidding truth be told
But wouldn't that be quite a jolt?
I'm just an old crumudgeon, moody
Who thinks bang equals looks like doody
So call me nuts or call me snooty
I guess I'll eat my TOOWTDI fruity
I'm not sure how symmetry best conveys an inequality test. Go Guido! I've never seen the need for the <> operator. Someone should run some counting scripts against code bases to see what percentage of code actually uses it. I'm pretty sure the world functions around !=.
> Anyhow, since <= means "less than or equal to", "<>" > obviously means "less than or greater than", which is > equivalent to "not equal to".
No, it is not equivalent. Python has at least three standard types for which this doesn't apply: sets (which overload < and <= as set inclusion), complex (for which < and > raise exceptions) and floats (where NaN defies the rules of high school math).
> . Someone should run some counting scripts against code > bases to see what percentage of code actually uses it. > I'm pretty sure the world functions around !=.
I'm sure != will win such a contest, because most Python programmers are probably coming from a language that already uses it, such as C or Java. Just because it's more popular doesn't mean it's better. :)
If the vast majority of programmers called the inequality oprator "less then or greater then", then <> might make sense, but they don't, they usually refer to it as "not equal to".
And the "if != then why not !==" argument just seems silly.