What is a Program? #
A program is simply a set of instructions that solve something through an applied medium—plain and simple. The act of programming refers to the process of teaching or instructing a system how to perform a task, and the result of that process is a program.
So if I say I want a program that performs multiplication and division, I need to define the rules and steps that, when followed, allow someone—or something—to do exactly that:
Multiplication #
- You need at least two numbers:
x
andy
. - To multiply the two numbers, compute
x * y
. - Conceptually, multiplication can be defined as adding
x
to itselfy
times.
Division #
- Again, you need two numbers:
x
andy
. - To divide, compute
x / y
. - Conceptually, division can be thought of as figuring out how many times
y
can be added until it equalsx
.
That’s a rough, human-level algorithm—a programmable way to think about solving a problem.
Now, putting that into code, here’s how such logic might look in Go.
Don’t worry about the details like
int32
orfloat64
just yet. For now, it’s enough to know that:
int32
represents a whole number (integer).float64
represents a number with decimals (a floating-point number).
func multiply(x, y int32) int32 {
return x * y
}
func multiply(x, y float64) float64 {
return x / y
}
At this stage, the functions above (think of them as named sets of instructions) might not make complete sense. That’s okay. The key takeaway is that programs are formalized instructions—like recipes—that tell the computer how to solve a specific problem.
In this case it just so happens that the specific problems are multiply
and divide
.