What do APPLICATIONS do after make?

by Bernd Schoeller (modified: 2007 Oct 29)

The lifetime of an Eiffel program is currently defined by the creation procedure of the root class (normally called 'make' in class 'APPLICATION'). When the creation of terminates, the Eiffel program terminates, too.

To me, it looks strange that an Eiffel application terminates after the root object has been created. What is the meaning of the invariant of the root class, if it needs to be established just before termination ?

My favorite scripting language is called Pike (http://pike.ida.liu.se), and that programming language has an interesting twist: In this C-like language, if the main procedure terminates with 'return -1;', then, instead of terminating, the runtime starts the 'internal main loop', waiting for events that will trigger the execution of code. Of course, using publish/subscribe, these events were registered before.

On a typical Unix system, there are (AFAIK) just two sources for events: signals and select. Signals are interrupts received by the program from the operating system. Select is a special unix statement that lets the program sleep while waiting for a state change on some file handler (reading: new data is available, writing: new data can be sent without blocking). The 'interal main loop' will have a list of subscribers for all of these sources.

The fact that Pike has a programming-language integrated main loop has a number of advantages. First, all IO operations can behave pseudo-parallel, as they know about the main loop. For example, you can open two network sockets and the register connection requests to the sockets with the Pike main loop. This makes it possible to listen to two sockets at the same time, without any need for multi-threading.

Second, as there is a main loop integrated into the language, different libraries always rely on the same main loop. This makes the common problem of using two libraries that define their own main loop (for example GTK and SDL) go away.

To cut the message of this blog entry short: I would love to see a general, ELKS-defined main loop class and support of this main loop by the Eiffel runtime and all ELKS (and other libraries). I think it is important that there is just one main loop that everybody uses.

  • Colin Adams (9 years ago 31/10/2007)


    One meaning of the invariant is that its assertions hold when the root class is not a root class, but is being called by another class.

    Anyway, your idea is interesting - why not mock up a definition so we can see its merits and demrits more clearly? Colin Adams

    • Peter Gummer (9 years ago 1/11/2007)

      Root Class

      I don't think I've ever seen a class which was used as the root of an application project and as a non-root in another project.

      Note my qualification: an application root. I've seen at least one case where the root class of a DLL was used as a non-root class in an application.

      In my experience, application root classes are always purpose-built as such. Does anyone ever reuse them in the manner proposed by OOSC2?