Simula - 50 years of OOP
- Tutorial
This article is a very brief introduction to Simula.
Simula ((SIMIUlation LAnguage)), the first programming language with classes and objects, undeservedly almost forgotten, but from which the modern OOP has grown in the form in which it is present in our code. This is a language for simulating reality. Developers of new programming languages "looked back" at Simula when adding the mechanisms of object-oriented programming in their language. However, Simula is mentioned so rarely that in Russian wikipedia at the time of publication there was only a HelloWord, and the network has a bunch of outdated links.

Björn Straustrup, speaking about the reasons for creating C ++, said this: “This language arose because the author needed to write interrupt-driven simulation programs. The SIMULA-67 language is ideal for this if you do not consider efficiency. ”
In fact, the language is more than 50 years old. The first version, known as Simula I, appeared in 1964-1965. It was an extension of the Algol-60 language (more precisely, a preprocessor). The authors of the language are Norwegian scientists Kristen Nyugor and Ole-Johan Dahl. The first versions of the language worked on 36-bit UNIVAC 1107.
As early as 1967, Simula-67 was released, which is now simply called Simula.
In our country, the first version of the language was launched on the Ural-16 computer.
In 1968, the language standard was officially frozen.
The language spreads in the 70s of the last century, but then its fame fades.
There are several reasons for this decline in popularity, but in modern terms - lack of marketing (slowly developing product, price, poor PR)
We will be training using GNU Cim, which is actually a compiler of Simula C code.
Installing on Linux
Mac Installation
Installation for Windows
Download the program from the site http://folk.uio.no/simula67/cim.shtml
We write a program in a notebook:
We save it under the name test1.cim
Then we do this (Linux variant):
And we get the long-awaited
Hello World!
As you can see from the syntax, the classic Algol 60. Most of the questions on this code will not, since in our country, the descendant Pascal is used as the main language for learning, which does not look very different.
Result:
Rectangle is updating, Area = 2000.00
Rectangle is updating, Perimeter = 180.00
Rectangle created: 50.00 40.00
Inside the main procedure, we created the Rectangle class with two Width and Height parameters, such as Real - i.e. real numbers. In modern terms, these are the parameters of the constructor - but they exist not only at the time the object was created, but also when it exists. In addition, we added the Area and Perimeter attributes of the same type. As we can see, they are calculated when the Update procedure is called. Since this procedure is declared inside the class, it becomes a method. What goes below the attributes and methods is called the life or body of the object.
Those. in fact, this is the code that is called when a new object is created. “Ref (Rectangle) R;” means the declaration of the R variable of the Rectangle class. The next line is initializing this variable.
Pay attention to the OutText call inside the Update procedure - what is not the analogue of the static method in Java?
Result:
Rectangle is updating, Area = 200.00
Rectangle is updating, Perimeter = 60.00
Rectangle created: 10.00 20.00
ColoredRectangle created, color = Green
As you can see from the example, a subclass is defined as a regular class, but with a prefix for the class name of the parent.
And you need to specify only additional parameters. The parameters that the parent had are added automatically.
As you can see, when creating an object, you need to list all the parameters - first the parent, then the descendant.
Now let’s “simulate” something. Still, this language was originally created to model real-world objects.
We simulate the work of a pedestrian traffic light. A traffic light has only two states. Every minute a new person approaches the crossing and, depending on the state of the traffic light, either crosses the street or waits.
Result:
0.00: GREEN ON
1.00 Peson 1 is near the crossover.
1.00 Peson 1 is going.
2.00 Peson 2 is near the crossover.
2.00 Peson 2 is going.
2.30: RED ON
3.00 Peson 3 is near the crossover.
4.00 Peson 4 is near the crossover.
5.00 Peson 5 is near the crossover.
6.00 Peson 6 is near the crossover.
6.55: GREEN ON
6.55 Peson 3 is going.
6.55 Peson 4 is going.
6.55 Peson 5 is going.
6.55 Peson 6 is going.
7.00 Peson 7 is near the crossover.
7.00 Peson 7 is going.
8.00 Peson 8 is near the crossover.
8.00 Peson 8 is going.
8.85: RED ON
9.00 Peson 9 is near the crossover.
10.00 Peson 10 is near the crossover.
11.00 Peson 11 is near the crossover.
12.00 Peson 12 is near the crossover.
13.00 Peson 13 is near the crossover.
13.10: GREEN ON
13.10 Peson 9 is going.
13.10 Peson 10 is going.
13.10 Peson 11 is going.
13.10 Peson 12 is going.
13.10 Peson 13 is going.
14.00 Peson 14 is near the crossover.
14.00 Peson 14 is going.
15.00 Peson 15 is near the crossover.
15.00 Peson 15 is going.
15.40: RED ON
16.00 Peson 16 is near the crossover.
17.00 Peson 17 is near the crossover.
18.00 Peson 18 is near the crossover.
19.00 Peson 19 is near the crossover.
19.65: GREEN ON
19.65 Peson 16 is going.
19.65 Peson 17 is going.
19.65 Peson 18 is going.
19.65 Peson 19 is going.
The main procedure starts with Simulation. The total simulation time is 20 minutes. The report procedure is auxiliary, it outputs data with the current value of the simulation time. The Semaphor traffic light in the green status is 2.3 minutes, in the red status - 4.25 minutes. The state is set by the isRed variable. The waitingPersons line is pedestrians who could not immediately cross the street because there was a red traffic light.
PersonGenerator is a pedestrian generator - every minute a new pedestrian approaches a traffic light. Hold plays the role of a simulation time course.
Process is the ancestor of all classes of “active” participants in this simulation.
As we can see, the code is quite intuitive and not complicated, a simple simulation can be done without a very deep immersion in the language.
By studying old programming languages you can find out the origin of many things in modern languages. In this case, it is amazing how far Simula is ahead of its time when you consider the computers on which it worked. I will not say that it makes sense to write code in this language. Because not all examples, even with the English-language wiki, work the first time. In particular, difficulties arose with virtual methods - although this is most likely related to a specific compiler. But for training tasks and for simple simulation Simula seemed to me quite convenient.
Useful links:
1. Installation for Linux, Mac, Windows
2.Introduction to OOP from the University of Malta , and there is even a translation into Russian
3. An article by Knut himself
4. A site with a lot of working links
Simula ((SIMIUlation LAnguage)), the first programming language with classes and objects, undeservedly almost forgotten, but from which the modern OOP has grown in the form in which it is present in our code. This is a language for simulating reality. Developers of new programming languages "looked back" at Simula when adding the mechanisms of object-oriented programming in their language. However, Simula is mentioned so rarely that in Russian wikipedia at the time of publication there was only a HelloWord, and the network has a bunch of outdated links.

Björn Straustrup, speaking about the reasons for creating C ++, said this: “This language arose because the author needed to write interrupt-driven simulation programs. The SIMULA-67 language is ideal for this if you do not consider efficiency. ”
Why do I need it
I was led to Simula static methods in Java. More precisely, it all started with a review of the report by Yegor Bugaenko, who calls static methods evil in Java. In short, in his opinion, they introduce procedural programming elements into Java, breaking OOP. Accordingly, the question arose - why did these methods appear in the Java language - what guided the creators of the language? Seeking the answer to this, the question dug up to Smalltalk (1971), from which (to be honest) OOP in Java was taken. As it turned out, static methods were there, they are only called class methods. But Smalltalk, too, did not come from the air. His predecessor was Simula (1965). As it turned out, similar methods were there. Of course they were also called differently. In particular, he met the name "free block". And “free blocks” are ordinary procedures. After all, the ancestor of Simula was Algol 60.
History
In fact, the language is more than 50 years old. The first version, known as Simula I, appeared in 1964-1965. It was an extension of the Algol-60 language (more precisely, a preprocessor). The authors of the language are Norwegian scientists Kristen Nyugor and Ole-Johan Dahl. The first versions of the language worked on 36-bit UNIVAC 1107.
As early as 1967, Simula-67 was released, which is now simply called Simula.
In our country, the first version of the language was launched on the Ural-16 computer.
In 1968, the language standard was officially frozen.
The language spreads in the 70s of the last century, but then its fame fades.
There are several reasons for this decline in popularity, but in modern terms - lack of marketing (slowly developing product, price, poor PR)
Installation
We will be training using GNU Cim, which is actually a compiler of Simula C code.
Installing on Linux
$ wget http://simula67.at.ifi.uio.no/Cim/cim-3.37.tar.gz
$ tar -xf cim-3.37.tar.gz
$ cd cim-3.37
$ ./configure
$ make
$ sudo make install
$ sudo ldconfig /usr/local/lib
Mac Installation
$ wget http://simula67.at.ifi.uio.no/Cim/cim-3.37.tar.gz
$ tar -xf cim-3.37.tar.gz
$ cd cim-3.37
$ CFLAGS='-O0 -m32' ./configure
$ make
$ sudo make install
Installation for Windows
Download the program from the site http://folk.uio.no/simula67/cim.shtml
Hello world!
We write a program in a notebook:
Begin
OutText ("Hello World!");
Outimage;
End;
We save it under the name test1.cim
Then we do this (Linux variant):
cim test1.cim
./test1
And we get the long-awaited
Hello World!
As you can see from the syntax, the classic Algol 60. Most of the questions on this code will not, since in our country, the descendant Pascal is used as the main language for learning, which does not look very different.
Feature Classes
Begin
Class Rectangle (Width, Height); Real Width, Height;
Begin
Real Area, Perimeter;
Procedure Update;
Begin
Area := Width * Height;
OutText("Rectangle is updating, Area = "); OutFix(Area,2,8); OutImage;
Perimeter := 2*(Width + Height);
OutText("Rectangle is updating, Perimeter = "); OutFix(Perimeter,2,8); OutImage;
End of Update;
Update;
OutText("Rectangle created: "); OutFix(Width,2,6);
OutFix(Height,2,6); OutImage;
End of Rectangle;
Ref(Rectangle) R;
R :- New Rectangle(50, 40);
End;
Result:
Rectangle is updating, Area = 2000.00
Rectangle is updating, Perimeter = 180.00
Rectangle created: 50.00 40.00
Inside the main procedure, we created the Rectangle class with two Width and Height parameters, such as Real - i.e. real numbers. In modern terms, these are the parameters of the constructor - but they exist not only at the time the object was created, but also when it exists. In addition, we added the Area and Perimeter attributes of the same type. As we can see, they are calculated when the Update procedure is called. Since this procedure is declared inside the class, it becomes a method. What goes below the attributes and methods is called the life or body of the object.
Those. in fact, this is the code that is called when a new object is created. “Ref (Rectangle) R;” means the declaration of the R variable of the Rectangle class. The next line is initializing this variable.
Pay attention to the OutText call inside the Update procedure - what is not the analogue of the static method in Java?
Now let's take a look at inheritance
Begin
Class Rectangle (Width, Height); Real Width, Height;
Begin
Real Area, Perimeter;
Procedure Update;
Begin
Area := Width * Height;
OutText("Rectangle is updating, Area = "); OutFix(Area,2,8); OutImage;
Perimeter := 2*(Width + Height);
OutText("Rectangle is updating, Perimeter = "); OutFix(Perimeter,2,8); OutImage;
End of Update;
Update;
OutText("Rectangle created: "); OutFix(Width,2,6);
OutFix(Height,2,6); OutImage;
End of Rectangle;
Rectangle Class ColouredRectangle (Color); Text Color;
Begin
OutText("ColouredRectangle created, color = "); OutText(Color);
OutImage;
End of ColouredRectangle;
Ref(Rectangle) Cr;
Cr :- New ColouredRectangle(10, 20, "Green");
End;
Result:
Rectangle is updating, Area = 200.00
Rectangle is updating, Perimeter = 60.00
Rectangle created: 10.00 20.00
ColoredRectangle created, color = Green
As you can see from the example, a subclass is defined as a regular class, but with a prefix for the class name of the parent.
And you need to specify only additional parameters. The parameters that the parent had are added automatically.
As you can see, when creating an object, you need to list all the parameters - first the parent, then the descendant.
Real world simulation
Now let’s “simulate” something. Still, this language was originally created to model real-world objects.
We simulate the work of a pedestrian traffic light. A traffic light has only two states. Every minute a new person approaches the crossing and, depending on the state of the traffic light, either crosses the street or waits.
Simulation Begin
Procedure report (message); Text message; Begin
OutFix (Time, 2, 0); OutText (": " & message); OutImage;
End;
Integer u;
Ref (Semaphor) s;
Integer i;
Process Class Semaphor; Begin
Boolean isRed;
Ref (Head) waitingPersons;
waitingPersons:- New Head;
isRed := false;
report ("GREEN ON");
While True Do Begin
Hold (2.3);
isRed := true;
report ("RED ON");
Hold (4.25);
isRed := false;
report ("GREEN ON");
While not s.waitingPersons.Empty Do Begin
Activate s.waitingPersons.First;
s.waitingPersons.First.Out;
End;
End;
End;
Process Class Person (pid); Integer pid; Begin
OutFix (Time, 2, 0); OutText (" Peson "); OutInt(pid, 3); OutText (" is near the crossover."); OutImage;
If s.isRed Then Begin
Wait (s.waitingPersons);
End;
OutFix (Time, 2, 0); OutText (" Peson "); OutInt(pid, 3); OutText (" is going."); OutImage;
End;
Process Class PersonGenerator; Begin
While True Do Begin
i := i + 1;
Hold (1);
Activate new Person(i);
End;
End;
s:- New Semaphor;
i := 0;
Activate s;
Activate New PersonGenerator;
Hold (20);
End;
Result:
0.00: GREEN ON
1.00 Peson 1 is near the crossover.
1.00 Peson 1 is going.
2.00 Peson 2 is near the crossover.
2.00 Peson 2 is going.
2.30: RED ON
3.00 Peson 3 is near the crossover.
4.00 Peson 4 is near the crossover.
5.00 Peson 5 is near the crossover.
6.00 Peson 6 is near the crossover.
6.55: GREEN ON
6.55 Peson 3 is going.
6.55 Peson 4 is going.
6.55 Peson 5 is going.
6.55 Peson 6 is going.
7.00 Peson 7 is near the crossover.
7.00 Peson 7 is going.
8.00 Peson 8 is near the crossover.
8.00 Peson 8 is going.
8.85: RED ON
9.00 Peson 9 is near the crossover.
10.00 Peson 10 is near the crossover.
11.00 Peson 11 is near the crossover.
12.00 Peson 12 is near the crossover.
13.00 Peson 13 is near the crossover.
13.10: GREEN ON
13.10 Peson 9 is going.
13.10 Peson 10 is going.
13.10 Peson 11 is going.
13.10 Peson 12 is going.
13.10 Peson 13 is going.
14.00 Peson 14 is near the crossover.
14.00 Peson 14 is going.
15.00 Peson 15 is near the crossover.
15.00 Peson 15 is going.
15.40: RED ON
16.00 Peson 16 is near the crossover.
17.00 Peson 17 is near the crossover.
18.00 Peson 18 is near the crossover.
19.00 Peson 19 is near the crossover.
19.65: GREEN ON
19.65 Peson 16 is going.
19.65 Peson 17 is going.
19.65 Peson 18 is going.
19.65 Peson 19 is going.
The main procedure starts with Simulation. The total simulation time is 20 minutes. The report procedure is auxiliary, it outputs data with the current value of the simulation time. The Semaphor traffic light in the green status is 2.3 minutes, in the red status - 4.25 minutes. The state is set by the isRed variable. The waitingPersons line is pedestrians who could not immediately cross the street because there was a red traffic light.
PersonGenerator is a pedestrian generator - every minute a new pedestrian approaches a traffic light. Hold plays the role of a simulation time course.
Process is the ancestor of all classes of “active” participants in this simulation.
As we can see, the code is quite intuitive and not complicated, a simple simulation can be done without a very deep immersion in the language.
By studying old programming languages you can find out the origin of many things in modern languages. In this case, it is amazing how far Simula is ahead of its time when you consider the computers on which it worked. I will not say that it makes sense to write code in this language. Because not all examples, even with the English-language wiki, work the first time. In particular, difficulties arose with virtual methods - although this is most likely related to a specific compiler. But for training tasks and for simple simulation Simula seemed to me quite convenient.
Useful links:
1. Installation for Linux, Mac, Windows
2.Introduction to OOP from the University of Malta , and there is even a translation into Russian
3. An article by Knut himself
4. A site with a lot of working links