How useful are infix operators in a programming language? Are they worth the extra complexity they provide? Can you provide any examples where infix operators are better suited to the problem that can't be handled by just overloading the normal operators?
Take the 2-minute tour
×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.
I think infix operators stem from mathematics. This:
is more readable to most people, than
because most people are familiar with mathematics. Interesting enough in Haskell you can hop between infix and prefix. This is using the same funtion "(+)":
and this is using the same function "elem":
|
|||||||||||||||||||||
|
Computer languages are designed for humans not machines. And humans are more used to infix operators than pre or postfixes. |
|||
|
The only real reason for infix operators is that humans generally find them easier to read. This is largely due to two facts:
From a logical/machine perspective, infix operators don't really add any value and in some cases are a nuisance:
|
|||||||||
|
arg1.method(arg2)
rather thanmethod(arg1, arg2)
. – Tom Hawtin - tackline May 27 '11 at 8:34