
| Home | Portfolio | Articles | Art | Links | |
|
Tao of Coding SE is a Joke The Game Loop Long live <> |
Long live <>One day I was sitting behind my computer (nothing unusual so far), surfing some articles on programming and stuff, when suddenly I read something about the new Python 3.0. I thought "well, let's find out what they have been up to lately". So I started reading and skimming over some PEP's, when suddenly something caught my eye: The <> operator: use != insteadWhat the hell??? My favorite Python operator was about to die a terrible death!!! I couldn't just let this happen, so I just had to write this article as a desperate attempt to try and save it. If it's != versus <>, then <> should definitely come out as a winner. I've been programming in C/C++/C#/Java and Python (of course) for many years. All those languages use the != operator as a "not equals". But I always found that one very confusing, and here is why: All of these languages have an assignment operator: =, so the statement a = expressionmeans that the variable is set to the value of the expression. As an extra, these languages also provide some fancy assignment statements like +=, *=, &=, ... . For comparison (not assignment!), they use operators like <, >, <= (smaller or equals), >= (larger or equals), == (double '=' so there is no confusion with assignment). All pretty clear hey? But now comes the catch, there exists an operator !=... but what does it mean? Well, that one is pretty easy, of course ! must be an operator of its own (in non-python languages meaning 'not'), and it resembles the fancy assignment statement, so a != bmust mean "assign the value 'not b' to 'a'... right?... Wrong! Somehow this is a comparison operator meaning "not equals"... what??? Yes, that's right, but hey, you learn to live with it eventually. When I started to learn python I came across an operator <>. What could it mean? Well, you don't have to think long about it. You're only reference are the < and > operators (with meanings the same as in mathematics or plain written language, any non programmer would understand this). So <> must mean "smaller or larger", or not-equals, no question about that. It couldn't possible be mistaken as an assignment operator. You just have to love a language that uses operators with clear and obvious meaning. But what have they decided for Python 3.0? Well, lets just drop the clear and understandable <> and only allow !=, unclear for non-programmers and confusing for programmers, and as a bonus, it even types slower. So please, please, please, bring back my favorite operator in my favorite language, pretty please... Koen Witters
See also Requiem for an operator |
Copyright ©2008 Koen Witters