[Python-ideas] Infix functions

Steven D'Aprano steve at pearwood.info
Mon Feb 24 02:35:40 CET 2014


On Sun, Feb 23, 2014 at 12:47:46PM -0800, Andrew Barnert wrote:

> Of course this is me talking about Bruce's idea. I don't want to put 
> words in his mouth. And I also don't want people to forget that _my_ 
> idea was using infix functions for _non-mathematical_ cases, and this 
> is only a minor sideline to me. 

I can't think of many useful examples of infix operators that aren't 
mathematical, and even fewer that aren't just as easily written as 
methods or functions.

I think that's why there are so few non-mathematical examples given in 
this thread. Apart from, say, taking the union and intersection of two 
dicts, I can't really think of anything where I'd want this outside of 
mathematics.

In the absense of any compelling use-case for allowing arbitrary 
non-mathematical infix operators, I'm -1 on adding all this complexity 
and (to be frank) cryptic ugliness to the code.

99 times out of 100, the right answer is "use a method or function", and 
the remaining time, using a method or function is nearly always 
acceptable. All the low-hanging fruit is taken: between + - * / and 
perhaps a few other operators, nearly all the common and important 
use-cases are covered.


-- 
Steven


More information about the Python-ideas mailing list