Posts Tagged ‘immutable’


3 April 2008

The original annotation that started this project is @Pure. This would be applied to methods, and I think the proper definition is that a method is pure only if it does not change any state at all (either in the target object or anywhere else) and its return value depends only on the state of the parameters to the method call and the target object. This requires that the method not call any other methods that are not also marked as @Pure.

To determine when the state of objects might change, it will also be necessary to mark appropriate methods as @Const. This will mean that the method does not change the state of the target object, just like const functions in C++.

This is still not enough, however, as there could be aliases to the object in question which could be used to change it in a way that cannot easily be tracked at compile-time. As an initial way to work around this problem (in very limited circumstances), classes will be marked as @Immutable to mean that they can never be changed at all. This will allow me to make a start on making some optimisations and think further about better solutions.