0

Is there a standard technical term for methods that mutate global state?


  • "Unpure" is too strict, because the unpure methods println("I don't consider stdout to be part of the global state") and date() do not modify global state.
  • "Mutator method" comes close, but is often a synonym for "setter" and thus may only change one variable, or only change a local variable but not the global state.
  • "Const method" seems to be used for C++ only and implies some technical details that are too strict (e.g., the method may not call any non-const method).
  • "Mutating method" sounds good to me, but seems to be a term used in objective c only.

Update: By global state, I mean memory that is visible to other methods or other calls of the same method.

Since stdout cannot be read by any method of the program, println("I don't consider stdout to be part of the global state") has the side effect of printing but does not change global state.

DaveFar
  • 7,078
  • 4
  • 50
  • 90

4 Answers4

2

I would say the method has a "side effect". I first came across the term when I was taught functional programming at uni way back, but I have found it is commonly used in ordinary programming to mean a state change.

(References from a web search: wikipedia, discussion on programmers' stack exchange.)

Community
  • 1
  • 1
TooTone
  • 7,129
  • 5
  • 34
  • 60
  • So by "commonly used in ordinary programming to mean a state change" you mean output is commonly not considered a side effect? – DaveFar Jun 08 '13 at 17:05
  • I'm not sure you're going to find a term that precisely meets your criteria (and you've now clarified your question to mention side effect explicitly). I guess I would still use the term side effect in discussion with colleagues, but qualify it if necessary to say that I was excluding output. A lot of what's included or excluded is going to be clear from the context anyway. Personally -- and I'm not trying to pick a fight over terminology here (it is your question and your definition) -- I would be more comfortable for global state to include output. – TooTone Jun 08 '13 at 19:07
2

I don't think that there is one language agnostic technical term for methods that mutate global state. As you have already pointed out mutator comes the closes but it indeed is synonymous to setter.

Also the notion of global state is a very broad and controversial. What do you consider global state?

If we were to formulate a name I would maybe recommend the term 'Mutagenic' as a potential fit. Its meaning is 'capable of inducing mutation'(http://www.thefreedictionary.com/mutagenic) which is close to what such methods are capable of. Now you could mutate the state of a local variable, an object or 'global' state. And thats where the confusion really lies. In early BASIC and COBOL every method would modify global state. In C any method can modify global state. Java has no explicit globals (http://en.wikipedia.org/wiki/Global_variable#Java:_no_explicit_globals)

MickJ
  • 2,127
  • 3
  • 20
  • 34
  • The question of what is meant by "global state" is key here. – jerry Jun 07 '13 at 21:06
  • I've added a definition for global state. – DaveFar Jun 08 '13 at 16:55
  • mutagenic is a nice suggestion, thx. But I'm looking for a technical term that most people understand. – DaveFar Jun 08 '13 at 16:57
  • agree v much with "I don't think that there is one language agnostic technical term for methods that mutate global state." and "Also the notion of global state is a very broad and controversial." – TooTone Jun 09 '13 at 20:16
1

"Modifier method"? Did not find a definitive official source except that it is used here https://en.wikipedia.org/wiki/Method_(computer_science)#Accessor_and_mutator_methods

" An update, modifier, or mutator method, is an accessor method that changes the state of an object."

user2246051
  • 231
  • 1
  • 7
  • Thanks for the answer. I think in Java, modifier method is used synonymously for setter, i.e. a special instance of global state changing methods that mutates a private variable. – DaveFar Jun 08 '13 at 17:04
0

There is the technical term Referentially Opaque but it's not often used in commercial programming contexts, it is more of an academic term. You could call it "destructive", which more people would understand, but it is still a bit confusing if it is just altering the state. You could call it a 'global mutator' or 'non-idempotent'. As someone with over 10 years of professional programming experience I can say there is no term that would be widely recognized. The most common notation would be that the method has "side effects."

Old Pro
  • 24,624
  • 7
  • 58
  • 106