archives

State of objects

Imagine having a purely object-oriented language, meaning that all algorithms (functions/methods/procedures) are methods in objects, and all value storing are also handled by objects.

When a compiler see code for creating an object, it will implicitly associate a state with it. The state can be any of the following:
1) Allocated but not yet initiated.
2) Initiated, ready for use
3) Destructed

It uses these states to determine what is legal syntax or not, and probably for doing optimization and what not.

I'm playing with the idea to make these states not only visible for the programmer, but also extendable. If you combine this with the possibility to condition methods (members?) with the state, you can actually define an object that e.g. only allows a certain method to be invoked once. This would enable the compiler to enforce this statically whenever possible, and only do this enforcement dynamically when it is not possible to do this statically.

Is there anyone out there who have tried this already?