Building a Distributed Spreadsheet in Modula-3

Mr. Kominek introduces us to the Modula-3 language and shows us how it can be used for cross-platform programming.
Step 5: Distributed Deployment

The netobj daemon acts like a bulletin board. First, the server posts a note saying, “I've got a spreadsheet object for sale.” Then the client comes along and says, “I'll buy that.” The server exports; the client imports; the daemon mediates. In the nomenclature of CORBA, the daemon is an object request broker. Once the sale is complete, the client and server talk to each other directly. Code details are found in Listing 4.

Listing 4 will work when the server and client are located on the same machine. Suppose instead that the server runs on some Linux box—eggnog.cmu.edu—and that the clients are elsewhere. Ensure that netobjd is running on eggnog and change one line in the client program.

address := NetObj.Locate( "eggnog.cmu.edu" );

With that, our programs now talk over the Net.

Step 6: Cell Range Locking

Because Modula-3 comes ready-made with thread support, it also provides mutexes (mutual exclusion semaphores) so that parallel operations on the same datum are serialized. In our discussion so far, the Money.T type has been left unspecified. It might actually be something like this:

INTERFACE Money;
TYPE
  T = MUTEX OBJECT
    cents: INTEGER;
  END;
END Money.

Mutexes protect data so that client B does not modify values before client A is finished. Granted, protecting each cell separately is overkill. A more elegant approach is to protect ranges of cells, with the lock initiated by user action.

Figure 2 shows a spreadsheet from the point of view of user A (Alice). She is working on the cell range tinted red. User B (Bob) cannot modify these cells. He is working on the blue cells, indicating to Alice that to her they are read only.

Figure 2. Simple Multiuser Spreadsheet

Step 7: Porting Procedure

To port our user interface program from Linux to Windows NT, do the following:

  1. Archive the client source code by using the tar command.

  2. Copy the tar file to your Windows machine.

  3. Unarchive the file using tar. Convert end-of-line markers.

  4. At the command line, type m3build.

Assuming there are no stunts of low-level programming, all the Modula-3 code in this example—including the GUI—is transparently portable. Differing path name conventions, for example, are hidden behind OS-independent interfaces. There's not an #ifdef in sight.

Conclusion

In this article I've highlighted the creation of a multi-platform, distributed spreadsheet using Modula-3. The key step is to wrap the spreadsheet into a network object. In this way, remote objects may be invoked with exactly the same syntax as local objects. Most of the hard work is done for you.

Modula-3 is not the only means for creating distributed applications, but in my mind it strikes an optimal balance between simplicity and power. By its very intent, it is a language for building large, solid systems in order for you to get your work done.

Clearly, my discussion has omitted many details. To help fill this gap, a companion tutorial is available on the Web (see the sidebar “Getting Started”.) Full source code is available for experimentation and invention.

John Kominek holds a master's degree in Computer Science from the University of Waterloo, and is currently a graduate student at CMU. When pressed, he admits to pronouncing Linux to rhyme with Linus. He can be reached via e-mail at jkominek@cs.cmu.edu.

______________________

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix