Operators in Programming
Consider the following snippet:
result = 3.1 + 0.2;
It is easy to understand what the bit 3.1 + 0.2
does. The symbol +
means addition, and the same could be expressed in funtional notation (remember mathematical functions):
result = add(3.1, 0.2);
as long as function add(x1, x1)
is defined.
Word result = Word("back") + Word("yard");
(The actual statement or line
will be different in each programming language. Here I have used C++ grammar.)
Essentially, an operator is a notation device that makes code look more natural or even more graphic.
Some programming languages allow defining new operators, notably PROLOG. Others, like C++, allow the programmer to expand the operator notation to new types. For instance, a new type Word
might have been defined as well as an operator to concatenate such Word
objects.