Programming Languages – How Useful Are Infix Operators?

operatorsprogramming-languagessyntax

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?

Best Answer

I think infix operators stem from mathematics.

This:

2 + 3 * 4

is more readable to most people, than

(+ 2 (* 3 4))

because most people are familiar with mathematics.

Interesting enough in Haskell you can hop between infix and prefix. This is using the same funtion "(+)":

(+) 1 2
1 + 2

and this is using the same function "elem":

elem 42 [1,2,42]
42 `elem` [1,2,42]