5 old Programming Languages you should know about
Alvaro (Blag) Tejada Galindo
Posted on January 21, 2022
This post was originally posted on LinkedIn.
For some people, old programming languages are ugly, obsolete, old-fashioned and useless. For me, they're the complete opposite...gems waiting to be rediscovered.
An old programming language can teach you a lot and can make you for sure a better developer. People today are getting used to have everything provided by the language and that's bad because it doesn't force you to think. Old programming language lack a lot of things that you find in modern languages, but that doesn't mean they're not as powerful, as they provide you all the tools to implement things yourself.
To illustrate how those programming work, we're to use a very basic app called "Fibonacci List" which will simply output a list of requested Fibonacci numbers, for example if we ask for 5, it should return 0, 1, 1, 2, 3, 5.
Let's start with the oldest programming language I know...
FORTRAN (Formula Translator - 1957)
A general-purpose, imperative programming language that is essentially suited to numeric computations and scientific computing.
program fibonacci
implicit none
integer :: a=0, b=1, num
write(*,'(a)',advance="no") "Enter a number: "
read(*,*) num
write(*,*) trim(fib(num, a, b))
contains
recursive function fib(num, a, b) result(fibo)
integer, intent(in) :: num, a, b
integer :: ab
character(1000) :: a_s, b_s, ab_s
character(1000) :: fibo
if(a > 0 .and. num > 1) then
ab = a + b
write(ab_s, '(I0)') ab
fibo = trim(ab_s) // " " // fib(num - 1, ab, a)
else if (a == 0) then
ab = a + b
write(a_s, '(I0)') a
write(b_s, '(I0)') b
write(ab_s, '(I0)') ab
fibo = trim(a_s) // " " // trim(b_s) // " " //
trim(ab_s) // " " // trim(fib(num - 1, ab, b))
else
fibo = ""
end if
return
end function fib
end program fibonacci
Let's see...A program must be enclosed between "program" and "end program" tag. Variables need a type when they are declared. A recursive function must be labeled as "recursive". String variables are fixed in length. "//" is used to concatenate. Integers and Character can be concatenated together without further transformations. We need to trim a lot to avoid extra space due to the really long fixed size. Functions can return zero, one or multiple values.
To compile this...I used GFORTRAN which come with Linux, but can be simply installed by doing "sudo apt-get install gfortran". Being a GNU App...this is not a real Fortran compiler...it's written in C.
GFORTRAN -WALL -C "NAME_OF_FILE.F95"
GFORTRAN -WALL -O "NAME_OF_EXEC" "NAME_OF_FILE.F95"
You can read my FORTRAN Introduction here.
Cobol (Common Object Business Oriented Language - 1959)
A compiled English-like computer programming language designed for business use.
It's imperative, procedural and since 2002, Object Oriented.
IDENTIFICATION DIVISION.
PROGRAM-ID. fibonacci.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 USER-NUMBER PIC 9(3).
01 A PIC 9(3).
01 B PIC 9(3).
01 AB PIC 9(3).
01 COUNTER PIC 9(3).
01 COUNTER-SPACES PIC 9(3).
PROCEDURE DIVISION.
PROGRAM-BEGIN.
MOVE 0 TO A.
MOVE 1 TO B.
DISPLAY "Enter a number: ".
ACCEPT USER-NUMBER.
PERFORM GET-FIBO WITH TEST AFTER UNTIL USER-NUMBER = 1.
DISPLAY " ".
PROGRAM-DONE.
STOP RUN.
GET-FIBO.
IF A = 0
COMPUTE AB = A + B
INSPECT AB TALLYING COUNTER FOR CHARACTERS
INSPECT AB TALLYING COUNTER-SPACES FOR LEADING ZEROS
COMPUTE COUNTER-SPACES = COUNTER-SPACES - COUNTER
DISPLAY 0 " " 1 " " AB(COUNTER:COUNTER-SPACES) WITH NO ADVANCING
COMPUTE USER-NUMBER = USER-NUMBER - 1
MOVE AB TO A
ELSE
MOVE 0 TO COUNTER
MOVE 0 TO COUNTER-SPACES
COMPUTE AB = A + B
INSPECT AB TALLYING COUNTER FOR CHARACTERS
INSPECT AB TALLYING COUNTER-SPACES FOR LEADING ZEROS
IF COUNTER-SPACES = 0
DISPLAY " " AB WITH NO ADVANCING
END-IF
IF COUNTER-SPACES = 1
COMPUTE COUNTER = COUNTER - COUNTER-SPACES
DISPLAY " " AB(COUNTER:COUNTER) WITH NO ADVANCING
END-IF
IF COUNTER-SPACES = 2
COMPUTE COUNTER-SPACES = COUNTER-SPACES - COUNTER
DISPLAY " " AB(COUNTER:COUNTER-SPACES) WITH NO ADVANCING
END-IF
COMPUTE USER-NUMBER = USER-NUMBER - 1
MOVE A TO B
MOVE AB TO A
END-IF.
As we can see...Cobol is very strict...it has "divisions" and "sections". Variables need to be declared first and cannot be declared anywhere else outside it's section. Moving a value into a variable is not the same as assigning a value to a variable. There is no such thing as IF-ELSE. You can inspect a variable to get its length or amount of zeros.
I know you're wondering what the heck "PIC 9" means...well..."9" is for numeric values, "X" for alphanumeric, "S" for sign and "V" for decimals.
To compile this...I used Open-Cobol that can be simply installed by doing "sudo apt-get install open-cobol". Being a GNU App...this is not a real Cobol compiler...it's written in C.
COBC -X -FREE -O "NAME_OF_FILE" "NAME_OF_FILE.COB"
You can read my Cobol Introduction here.
Simula (Simulation Programming Language - 1962)
Superset of Algol 60. Consired the first Object Oriented programming language.
begin
integer num;
text result;
procedure fib(num, a, b);
integer num, a, b;
begin
if a > 0 and num > 1 then
begin
OutInt(a+b,3);
fib(num - 1, a + b, a);
end;
if a = 0 then
begin
OutInt(a,3);
OutInt(b,3);
OutInt(a+b,3);
fib(num - 1, a + b, b);
end;
end;
OutText("Enter a number: ");
OutImage;
num := InInt;
fib(num,0,1)
OutImage;
end
Every program start with a "Begin - End". Variables need a type. We can have global and local variables. "OutInt" is used to print Integers on the screen while "OutText" is for strings. OutImage is used to print an empty line. Integer variables are assigned using "=" while String variables use ":=".
To compile, I used GNU CIM which is a transpiler from Simula to C. You can install it from here.
cim "NAME_OF_FILE.cim"
You can read my Simula Introduction here.
Snobol (String Oriented and Symbolic Language - 1967)
Imperative and Unstructured programming Language. Also, it's goal oriented.
* Fibonacci Sequence
define('fibo(num,a,b)temp','fib') :(fibo_end)
fib fibo = eq(a,0) a ' ' b ' ' ( a + b )
num = num - 1
a = a + b :s(fib0)
fib0 gt(num,1) :s(fib1)f(return)
fib1 fibo = gt(a,0) fibo ' ' ( a + b )
num = num - 1
temp = a
a = a + b
b = temp :s(fib0)f(return)
fibo_end
output = 'Enter a number: '
num = input
output = fibo(num,0,1)
end
Variables doesn't need a data type, it's type depend on the assigned value. When defining a method we need to specify what to call when it ends or fails. For each section we need to determine if it works or not and depending on that move to another section. An "If" condition needs to be by itself and move to other section depending on the result. In this example "gt(num,1)" is an "If" statement.
To compile we need to first build the compiler...which is by the way a C app.
WGET FTP://FTP.ULTIMATE.COM/SNOBOL/SNOBOL4-1.5.TAR.GZ
TAR –ZXVF SNOBOL4-1.5.TAR.GZ && CD SNOBOL4-1.5
SUDO APT-GET INSTALL M4
SUDO MAKE INSTALL
To run we need to do...
snobol "NAME_OF_FILE.sno"
You can read my Snobol Introduction here.
Algol68 (Algorithmic Language - 1968)
Part of the Algol family of imperative programming Languages (Algol58, Algol60 and Algol68). One of the most influential languages of all time, giving rise to Simula, B, Pascal and C amongst many others.
BEGIN
print("Enter a number: ");
INT num = read int;
PROC fib = (INT num, a, b)VOID:
IF a > 0 THEN
IF num > 1 THEN
printf(($g(0)x$, a + b));
fib(num-1, a+b, a)
FI
ELIF a = 0 THEN
printf(($g(0)x$, a + b));
fib(num-1, a+b, b)
FI;
printf(($g(0)x$, 0, 1));
fib(num,0,1);
print(newline)
END
All applications start with a BEGIN-END. Variables need a type. Procedures can have zero or more parameters. The last value is returned and a value must be always returned. When printing a number, the sign will be displayed, that's why we need to format its output. This one most likely the first programming language to use "ELIF", and also "FI" to close an "IF" statement. ";" is used to end a line.
To compile, we need to first install Algol68Genie
SUDO APT-GET INSTALL -Y ALGOL68G
Then we can simply do...
a68g "NAME_OF_FILE.a68g"
You can read my Algol68 Introduction here.
Bonus Section
I know...five is not enough...so why not include a bonus language...one that always interested me as the name seems kind of weird for a programming language -;)
Smalltalk (1972)
An object-oriented, dynamically typed reflective programming language.
Smalltalk had influenced many languages like Objective-C, Java, Python, Ruby and many more...
| number fib result |
result := ''.
fib := [:num :a :b |
a > 0 & (num asNumber > 1) ifTrue: [
result := result , (a + b) asString , ' ' ,
(fib value: (num asNumber - 1) value: (a + b) value: a).
] ifFalse: [
a = 0 ifTrue: [
result := a asString , ' ' , b asString , ' ' , (a + b) asString , ' ' ,
(fib value: (num asNumber - 1) value: (a + b) value: b).
].
].
].
Transcript show: 'Enter a number: '.
num := stdin nextLine.
Transcript show: (fib value: num value: 0 value: 1); cr.
Variables are declared between "|". Values are assigned using ":=". "IF" statements are special as they are defined as "ifTrue" and "ifFalse" and "[ ]" are used to enclosed blocks. We use "Transcript show" because otherwise a text will be printed enclosed like this 'This is a text' instead of This is a text. If you wonder about "value:", that's used to call a parameter.
To compile, we're going to use GNU Smalltalk, that can be installed like this
sudo apt-get install gnu-smalltalk
and them simply...
gst "NAME_OF_FILE.st"
You can read my Smalltalk Introduction here.
That's it -:) Hope you had some fun -;) I had a lot of fun learning them...and they surely made me a better developer...and yes...I frustrated me plenty of times...but that's the fun of programming -;)
Blag.
Posted on January 21, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.