[Python-ideas] Infix functions
Greg Ewing
greg.ewing at canterbury.ac.nz
Sat Feb 22 03:12:20 CET 2014
Andrew Barnert wrote:
> a `cross` b + c `cross` (d `dot` e)
>
> vs.
>
> add(cross(a, b), cross(c, dot(d, e))
>
> Sure, it's only one character shorter (or four characters using @cross
> instead of `cross`), but you can't tell me it's not more readable.
It's *slightly* better, *maybe*, but it still looks
like a mess to my eyes, compared to
a % b + c % (d * e)
There are several reasons for this version being more
readable:
* It's far more compact
* It's not cluttered up with backticks
* It leverages my existing intuition about the relative
precedences of the operators involved
Precedence is a big problem. You're assuming that backtick
operators would have precedence higher than '+'. What if
I want to define my own addition-like operator? One
precedence isn't going to fit all.
--
Greg
More information about the Python-ideas
mailing list