# Operations and Operators

Very often, programmers come from a mathematical background where they have frequently dealt with operators and operations and but find it confusing to use these same terms in the context of programming. I had that problem one time myself. Since then, I have spoken of how the methods of a class are operations upon the data of a class and been asked to define the term, even though I should have recognized the uncertainty that the term brings to discussions and preemptively addressed it myself.

In the context of computers, on definition of operation is the execution of one computer instructions. These instructions, or collections of instructions, usually manipulate one or more pieces of data. For example, one instruction might load the integer value stored in a memory location into a registry of the processor. Another instruction might load another integer into another memory location. A third instruction may add the two values together and store the sum in yet a third register. A fourth instruction may place the calculated value in to one of the first two memory locations, or place it in yet another memory location. When programmers talk about operations, they are ordinarily talking about a collection of fundamental processor operations that do something identifiable. Even very simple things like multiplication (a logical, programmatic operation) may take many processor operations from the standpoint of the processor.

In common usage of the term operation, we are not referring to individual atomic processor instructions, but the overall activity of a function or a line of code. For example, if we have the following code:

1. Dim I, j, k as Integers

2. I = 1

3. J = 1

4. k = I + j

Lines 2 and 3 each have 1 operation. In each of these lines, the value of 1 is copied into the memory locations named I and j. The equals sign is the assignment operator that takes the value of the expression on the right side of the equals sign (the value 1 on both lines) and copies it to the storage location identified (by friendly name, not by memory address) to the left of the equals sign (or assignment operator). It may take more than one computer instruction to execute these instructions, but we as programmers view it as a single operation.

Line 4 has two operations. There is an operation that adds I and j together, and another operator that assigns the result to the memory address (identified by the variable k) to the left of the equal sign. The plus sign is an operator that takes two integers and adds them together. The plus sign is also used as an operator for other data types, but if I and j are not types that the plus sign recognizes as types that the plus sign can use in any operation, an error will result at compile time. The equals sign is again recognized as the assignment operator.

We say that the plus sign operates on I and j, and the equals sign operates on the result of I and j (stored as an intermediate result in a register) as well as k.

So when we say that a method DoSomething(int I, int j) is an operation of the class which contains it, we are saying that DoSomething is a function that operates on I and j (and other variables that may be visible within its scope).

n operator is merely a shorthand way of representing common functions. For example, instead of writing k = I + j, most languages would let us have a function that operates on I and j that might look something like k = i.Add(j).

Tags: