You Already Know How to Program — You Just Don't Know It Yet

Article 01:
Your motorcycle dies in the middle of nowhere. What do you do?

First, you check the fuel.
If not the fuel, you try to kick-start it.
If that fails, you check the spark plug.
If the spark plug is fine, you check the engine wiring.
Else, if nothing works, you call a mechanic.

The problem was simple: your bike broke down.

To solve that problem, you came up with a step-by-step procedure that may solve it. If the problem is solved in the first step, there’s no need to continue with the remaining steps. But as the cause is unknown, listing all possible solutions you knew, in order, to fix the problem was necessary.

An algorithm is a step-by-step approach to solve a problem/accomplish a task; it is the blueprint of execution.
The broader your view on the problem and its potential solution, the better the algorithm will be.

Haven’t you been using algorithms your whole life? Think of situations where you unconsciously executed them.

Every problem/task needs an algorithm. Some are simple, and some are very complex, depending on the requirement. But the fundamental idea is to break the problem/task into smaller steps until a desired result is reached.

If you want the computer to help you on a task or do something specific, you mention the procedure in which it is expected to accomplish the task, i.e., by using an algorithm.

TL;DR: An algorithm is a step-by-step procedure to do some task.

Humans have been using algorithms for thousands of years to solve problems.

**If humans were solving problems, why were computers invented?
We evolve. Every time something felt tedious, we made tools to simplify the process.

Imagine solving 982,731 × 638,249:
You can do it too; it’ll just take time. But for a modern computer it’s a matter of milliseconds.
Computers were invented to execute instructions faster, more accurately, and without getting tired.

But how can we instruct a computer to perform a certain task?

Coding

Whenever a problem is encountered or a task is needed to be done, we create algorithms. These algorithms are roadmaps for the computer. When given, they follow these steps and provide the output. The process of telling what to do (algorithm), in a language a computer understands, is coding.

It’s important to know the distinction between programming and coding. Coding is the translation of that algorithm into something the computer can interpret so it can be executed, while programming is the entire process of performing that task or solving the problem: making the algorithm, translating it, verifying/using the result, etc.

Why are there different programming languages?

Coding is the translation of instructions for a computer.

Let’s start with an example:

You say “good morning” to different people in different languages. Your objective was to greet them; words in different languages may sound different and vary, but the objective is accomplished. The message did not change, but the medium in which it’s conveyed did. The medium is decided by us based on the requirement.

Similarly, a formal set of rules, syntax, and vocabulary to translate that algorithm into computer language is called a programming language.
There are different programming languages for the same reason: there are many verbal languages. Each of them is used for a different purpose.

If I want my computer to multiply a 7 X 7 matrix, I can write a set of rules on how matrices are multiplied and the procedure and can write a code for it.
I can multiply that 7X7 matrix using a code written in:

  • Python: Prioritizes developer speed, readability, and concise syntax

a = np.array([
    [5, 0, 3, 3, 7, 9, 3],
    [5, 2, 4, 7, 6, 8, 8],
    [1, 6, 7, 7, 8, 1, 5],
    [9, 8, 9, 4, 3, 0, 3],
    [5, 0, 2, 3, 8, 1, 3],
    [3, 3, 7, 0, 1, 9, 9],
    [0, 4, 7, 3, 2, 7, 2]
])

b = np.array([
    [0, 0, 4, 5, 5, 6, 8],
    [4, 1, 4, 9, 8, 1, 1],
    [7, 9, 9, 3, 6, 7, 2],
    [0, 3, 5, 9, 4, 4, 6],
    [4, 4, 3, 4, 4, 8, 4],
    [3, 7, 5, 5, 0, 1, 5],
    [9, 3, 0, 5, 0, 1, 2]
])

result = np.dot(a, b)
print(result)
  • C/C++: Prioritizes raw speed, hardware access, and low-level memory control.
#include <stdio.h>
int main() {
    int a[7][7], b[7][7], c[7][7];
    
    for(int i = 0; i < 7; i++) {
        for(int j = 0; j < 7; j++) {
            a[i][j] = 1;
        }
    }
    
    for(int i = 0; i < 7; i++) {
        for(int j = 0; j < 7; j++) {
            b[i][j] = 2;
        }
    }
    
    for(int i = 0; i < 7; i++) {
        for(int j = 0; j < 7; j++) {
            c[i][j] = 0;
            for(int k = 0; k < 7; k++) {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    
    for(int i = 0; i < 7; i++) {
        for(int j = 0; j < 7; j++) {
            printf("%d ", c[i][j]);
        }
        printf("\n");
    }
    
    return 0;
}

or in any other programming language.(The difference is visible visually in both the codes, yet they does the same job.)

The objective was the same, and the result will be the same too. The process in which it is done varies on the type of programming language used. For more complex tasks, the choice of programming language plays a major role.

To know how a computer interprets these programming languages, you need to know how a computer works and internally how it operates. That is a very fascinating topic and will be covered in the next article!