Programming languages

Talhah Peerbhai published on
3 min, 525 words

What is a programming language?

A programming language is a formal language comprised of statements which follows certain rules and can be translated to machine code for a computer to understand and execute.

What led the movement from punch cards to programming languages?

Punch cards are write-once medium which encodes data and these are stored on cards as the name implies. Due to the amount of data a program may take up multiple cards. More often than not, you would have stacks of cards. This is problematic, cards can be damaged easily, mixed up or lost. The cards are also write once and any mistake or change means making another card over again. Large scale data processing wasn't viable and programming languages were a solution. You can change data easily.

What is the purpose of programming languages?

The main purpose of a programming language is to provide instructions to a computer. They allow a human to write code in a language which is not too hard to understand and closer to natural language. Imagine having to code in machine code and 1s and 0s. Yikes. Or even in lower level language, you need a strong basis of what exactly is going on and you need to implement alot of things by yourself. A programming language typically deals with this. The whole point is to make coding easier.

Why are there so many programming languages?

There's quite a lot of programming languages and each of them have been designed with certain goals in mind. One language may be fast wheras another may be slow at execution but is easier to write and closer to natural language. Some languages may encourage representing real world data as an object wheras another will encourage a different approach of representing data. This each have their pros and cons.

A drawback of a language I use: Python.

Python is slow at execution as compared to other languages such as C. Lets see an example.

Python
import sys
NUMBER = int(sys.argv[1]) 
s = 0
for i in range(NUMBER):
    s += 1
C
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
    int NUMBER, i, s;
    NUMBER = atoi(argv[1]);
    for (s = i = 0; i < NUMBER; ++i) {
        s += 1;
    }
    printf("s: %d",s);
    return 0;
}
Speed difference
[talhah@dev:~]$ time python speed.py 100000000000

real	102m12.496s
user	102m9.726s
sys	0m0.023s

[talhah@dev:~]$ time ./speed 100000000000
s: 1215752192
real	0m2.097s
user	0m2.096s
sys	0m0.000s

Iterating 10^11 times results in these times, with python being the slowest and C the fastest. 102m12.496s vs 2.097s is a significant time difference. It would be really cool if we could have python syntax and rules with C speed. Thankfull there are projects which aim to do this. Albeit for certain implementations and cases.

If I were going to create a programming language how would I start?

I'd need to gain a deeper understanding on how computers work at the lower level before I can even create a language and I'd need to define the purpose of the language and design around that. Syntax rules, speed, object oriented vs functional are just some considerations.