Operation

Computer Science, and therefore programming, has its roots in mathematics and uses a lot technical terms and jargon from math. Unfortunately this means that most programmers need to be familiar with some of this jargon.

An operation is a fancy math term for “do something”, but carries with it its own set of vocabulary. An operation is composed of:

1. an operator (one or more symbols)
2. operands (one or more pieces of data)
3. a semantic meaning (i.e. what the operator does)

Binary Operations

Binary operations operate on two inputs. This class of operations should be familiar from arithmetic. Its format is

``````    operand1 operator operand2
2     +        4
x     +        y``````

where the operator is typically some type of symbol.

Operator symbols are typically overloaded in programming languages, which means that they can do different things based on the types of the operands. For example, a typical language might do any of the following operations when the plus sign `+` is used as the operator, depending on the types of the individual operands:

Type Operand 1 Type Operand 2 Result Type
int
2
int
4
int
6
int
2
float
4.0
float
6.0
float
1.1
float
3.7
float
4.8
String
“2”
String
“4”
String
“24”
String
“2”
int
4
Error operation not defined for an operand of type String and int

We will have to refer to our language’s documentation for how each operator functions. Operator behavior, particularly in the presence of mixed-type operands varies from language to language.

Unary Operations

There are some operations that have just one operand, these are called unary operations. The typical form is `operator operand` or `operand operator`. A fairly common unary operator is `!` for the logical operation “not”. `!True` is the same as `False`. We’ll introduce more of these operators in a later chapter.