3 ms·
Operators are just names. When you're writing very abstract code that operates on abstract structures -- there's often no name that conveys the meaning. Engli
by Peaker 15y ago
Operators are just names.
When you're writing very abstract code that operates on abstract structures -- there's often no name that conveys the meaning. English and maths don't have names for every useful abstraction and abstract concept.
Instead of inventing some arbitrary name in English, you invent some arbitrary name as an operator, and that gives you infix syntax (often desirable for binary operators) and a recognizable visual signature.
Also, operators can greatly enhance readability, if you know a certain convention. Consider for example a vector library:
There are various arithmetic operators -- and those can be applied on scalars and vectors. Ordinary arithmetic operators operate on scalars. If < is prepended on the left side of the operator, then the left argument is a vector, and similarly with > on the right side. This makes it easy to immediately know what <+> means, vs what *> means, and so forth.