Are there well established terms for referring to methods that do or do not mutate the object state?
For example of a well established term describing a type of function: "idempotent".
Are there well established terms for referring to methods that do or do not mutate the object state?
For example of a well established term describing a type of function: "idempotent".
Pure Function is a well-established term referring to an operation which depends solely on its input arguments. It neither accesses nor mutates any non-local state. The concept of a pure function in programming is derived from mathematical functions. The opposite of a pure function is an impure function, which may perform IO, produce a side effect, or have some dependency on non-local state.
Note that the definition of a pure function is more strict than what this question asks for, since a pure function prohibits not only mutation of object state but also access to object state. To find a definition which fits between pure and impure functions, we can consider the Difference between a method and a function. Often, these two terms are conflated into one amorphous abstraction; but for the purpose of this question we will use more precise meanings: a method is coupled to an object whereas a function is independent.
From that simple definition we naturally reach the concept of Pure Methods. A pure method is just a pure function with one difference: in addition to its input arguments, the method implicitly receives a reference to its enclosing object, as if it had one extra argument.
I can't say that the term pure method is well established in the same way as pure function; but if we take the definition of a pure function, alongside the definition of a method, then I think the definition of a pure method follows intuitively. So to answer the question, pure is the keyword commonly used to indicate the presence or absence of mutation.