The Kotlin coding conventions, in the section Using infix functions, says:
Declare a function as infix only when it works on two objects which play a similar role. Good examples:
and
,to
,zip
. Bad example:add
.Don't declare a method as infix if it mutates the receiver object.
My first question is: in what way is add
a bad example?
Then in the discussion of basic types, it explains that the bitwise operators are "named functions that can be called in infix form" and it gives this example (as part of a larger expression):
(1 shl 2)
To me it seems that the three Kotlin shift operations (shl
, shr
, and ushr
) violate the coding conventions. The left and right operands don't play similar roles at all. The left operand is the original bit pattern and the right operand is how far the bit pattern should be shifted.
Am I missing something here?