I've been reading Principles of Computer System Design
(Saltzer & Kaashoek), and one of the early chapters is on modularity. For example:
- Different modules should only interact through specified interfaces
- Modules should be constructed to expose as little of their internal implementation as possible
Now that's all pretty standard stuff, and is the way most OO languages work. However, they mention even stricter requirements, such as:
- A called module should not be able to lock up the caller by failing to return
- A called module should not be able to cause its caller to die by running out of stack space
Now these requirements make perfect sense to me, and would do much to stop errors propagating through the entirety of a massive program and bring it all crashing down.
However, the method they suggest, splitting everything up into client/server processes, seems somewhat of an overkill for many purposes. Writing everything you want to modularize as client/server seems to be both:
- incredibly tedious
- slow (w.r.t. execution speed)
For example, I would like to be able to delegate work to my Math module, and place limits on execution time and memory use, but I don't really want to have to make a separate Math server running in the background just for these benefits! Furthermore, the IPC message-passing overhead (both computation and latency) is certain to be pretty huge compared to direct procedure calls.
Are there any languages that provide this kind of modularity within a process? As an in between before the tight-coupling of direct procedure-calls and the overhead of a multi-process client-server design? The way I envision it, instead of :
y = Math.sin(x)
which leaves me open to infinite loops and stack-overflows in the Math
module, I would like to do something like
y = try(maxMemory=1024kb, maxTime=12ms){
Math.sin(x)
}catch(Anything){
0
}
Which would set y to a default value (0
) if anything fails within Math.sin
. Invalid input, bugs, infinite loops, runtime-exceptions, anything. Does anything like this exist already in some language, and if not, why? It seems to me like something that would be immensely useful, in a wide variety of places.