Structuring Programs

konukhov edited this page Nov 3, 2014 · 6 revisions


2.4.1 Programming by observing the real world

We often want to write programs that model the world or interact with the world. Writing such a program in a COPL (Concurrency-Oriented Programming Language) is easy.

Firstly, we perform an analysis which is a three-step process:

  1. We identify all the truly concurrent activities in our real world activity.
  2. We identify all message channels between the concurrent activities.
  3. We write down all the messages which can flow on the different message channels.

Now we write the program. The structure of the program should exactly follow the structure of the problem. Each real world concurrent activity should be mapped onto exactly one concurrent process in our programming language. If there is a 1:1 mapping of the problem onto the program we say that the program is isomorphic to the problem.

It is extremely important that the mapping is exactly 1:1. The reason for this is that it minimizes the conceptual gap between the problem and the solution. If this mapping is not 1:1 the program will quickly degenerate, and become difficult to understand. This degeneration is often observed when non-CO languages are used to solve concurrent problems. Often the only way to get the program to work is to force several independent activities to be controlled by the same language thread or process. This leads to an inevitable loss of clarity, and makes the programs subject to complex and irreproducible interference errors.

In performing our analysis of the problem we must choose an appropriate granularity for our model. For example, if we were writing an instant messaging system, we might choose to use one process per user and not one process for every atom in the user’s body.

Additional Do's & Don'ts

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.