The Artima Developer Community
Sponsored Link

Weblogs Forum
Requiem for an operator

13 replies on 1 page. Most recent reply: Aug 31, 2006 6:05 PM by Damien Grassart

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 13 replies on 1 page
Barry Warsaw

Posts: 12
Nickname: pumpichank
Registered: Jun, 2003

Requiem for an operator (View in Weblogs)
Posted: Aug 24, 2006 5:49 PM
Reply to this message Reply
Summary
Guido kills <> in Python 3000. I am sad.
Advertisement

I heard the news today, oh boy

This came in my email today:

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 !=.

The argument for <>

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.

The argument for !=

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.

A Farewell

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


Simon Percivall

Posts: 4
Nickname: percivall
Registered: Jul, 2003

Re: Requiem for an operator Posted: Aug 24, 2006 7:41 PM
Reply to this message Reply
*sigh* I couldn't agree more. There's something about <> that just strikes me as ... elegant.

John Cowan

Posts: 36
Nickname: johnwcowan
Registered: Jul, 2006

Re: Requiem for an operator Posted: Aug 25, 2006 12:39 AM
Reply to this message Reply
Anyhow, since <= means "less than or equal to", "<>" obviously means "less than or greater than", which is equivalent to "not equal to".

I think "<>" was invented by Kurtz and Kemeny when they invented Basic....

Ivan Lazarte

Posts: 91
Nickname: ilazarte
Registered: Mar, 2006

Re: Requiem for an operator Posted: Aug 25, 2006 1:56 PM
Reply to this message Reply
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 !=.

nes

Posts: 137
Nickname: nn
Registered: Jul, 2004

Re: Requiem for an operator Posted: Aug 25, 2006 4:29 PM
Reply to this message Reply
How melodramatic :-)

Jules Jacobs

Posts: 119
Nickname: jules2
Registered: Mar, 2006

Re: Requiem for an operator Posted: Aug 25, 2006 6:56 PM
Reply to this message Reply
TIOOWTDI.

Why not use /= ? Closer to maths.

Kay Schluehr

Posts: 302
Nickname: schluehk
Registered: Jan, 2005

Re: Requiem for an operator Posted: Aug 25, 2006 10:49 PM
Reply to this message Reply
> TIOOWTDI.
>
> Why not use /= ? Closer to maths.

Because it denotes inplace division and it's hard to find an alternative for this operator:

>>> i = 6
>>> i /= 3
>>> i
2

Guido van van Rossum

Posts: 359
Nickname: guido
Registered: Apr, 2003

Re: Requiem for an operator Posted: Aug 28, 2006 10:59 AM
Reply to this message Reply
> 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).

Barry Warsaw

Posts: 12
Nickname: pumpichank
Registered: Jun, 2003

Re: Requiem for an operator Posted: Aug 28, 2006 2:13 PM
Reply to this message Reply
> . 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. :)

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Requiem for an operator Posted: Aug 29, 2006 4:32 PM
Reply to this message Reply
If they decided the other way, a bunch of people would be bitching about that too.

But there is one advantage to <> over != and that's that <> is much easier to type.

Barry Warsaw

Posts: 12
Nickname: pumpichank
Registered: Jun, 2003

Re: Requiem for an operator Posted: Aug 29, 2006 5:14 PM
Reply to this message Reply
> If they decided the other way, a bunch of people would be
> bitching about that too.

No doubt. So cuts the TOOWTDI knife with a syntax that's existed for so long.

> But there is one advantage to <> over != and that's that
> <> is much easier to type.

I completely agree!

Blake Winton

Posts: 4
Nickname: bwinton
Registered: Jan, 2005

Re: Requiem for an operator Posted: Aug 31, 2006 2:01 PM
Reply to this message Reply
Surely if != means "not an assignment", then <= means "less than or an assignment", which is equally non-sensical...

I didn't find it particularly difficult to read them both, even mixed in the same file, but TOOWTDI is a compelling reason to get rid of one of them.

And I put semi-colons at the end of my Python statements depressingly often, but I always get rid of them before I check it in.

Duncan McGreggor

Posts: 1
Nickname: oubiwann2
Registered: Aug, 2006

Re: Requiem for an operator Posted: Aug 31, 2006 3:45 PM
Reply to this message Reply
Oh, that poem is *brilliant*

Damien Grassart

Posts: 1
Nickname: damg
Registered: Aug, 2006

Re: Requiem for an operator Posted: Aug 31, 2006 6:05 PM
Reply to this message Reply
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.

Flat View: This topic has 13 replies on 1 page
Topic: Requiem for an operator Previous Topic   Next Topic Topic: He's baaack....


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us