Enforce Immutability and Purity

Enforce Immutability and Purity


At runtime, program’s states are instance and static field’s values. Controlling how/when/why states are changing is one of the most challenging programming task. This becomes incredibly difficult in multi-threaded environment. This is because potential side-effects due to a state change get too complicated to be understood.

Object-Oriented developers get more and more inspired by the functional programming approach where most states are immutable. An object is immutable if its state doesn’t change once it has been created. A method is pure if its execution doesn’t change any field state. Immutable objects and pure methods are two efficient ways to limit unexpected side-effects.

Through some dedicated CQLinq conditions and rules, CppDepend lets assert immutability and purity on your classes and methods. The best place to start with this feature is to look at the list of default CQLinq constraint and to read the associated documentation.