Talk:Mutator method

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
In computer science the mutator method is a method that changes the value of the argument variables.

Wrong, the object the function is called on is changed, not the variables that are passed as argumetns to the method/function

In the call-by-value form of argument passing, a reference or pointer to the data needs to be passed.

Wrong, no explicit need for that, just because its a mutator. And the example also shows pass-by-value of an integer —Preceding unsigned comment added by 84.176.233.185 (talkcontribs) 09:01, 18 May 2006

C++ example[edit]

C++ example is missing usage (main.cpp). — Preceding unsigned comment added by 192.116.217.162 (talk) 10:03, 20 December 2011 (UTC)[reply]

Access time[edit]

"Accessor functions are always less efficient than directly fetching or storing data fields due to the extra steps involved"

This quote refers to a document from 1998 and is false. For example, the de facto approach to implement accessors in C++ is to write them directly inside the class definition. This causes them to automatically become "inlined" which -when compiled with a modern compiler- will render the exact same access times as if the corresponding class member had been declared "public" and was accessed directly. This contradicts the above claim that accessor functions are always less efficient. As a matter of fact, using a modern compiler accessors in C++ are only less efficient if they are implemented in a separate source file (though I have never seen anybody do this myself). — Preceding unsigned comment added by Kchrdk (talkcontribs) 13:01, 31 July 2012 (UTC)[reply]

Getters, Setters and Accessors[edit]

Been reading a lot of OO and Smalltalk literature, and it seems to me that the definition of the terms "getter", "setter" and "accessor" given here are wrong. Getter and setter are both right, but "accessor" seems to be used near universally for both setting and getting - i.e. the general term for getter and setter is "accessor".

Class ReadWriteStream is a subclass of WriteStream that represents an accessor that can both read and write elements into its collection.

Goldberg, Adele et. al. Smalltalk-80 The Language and its Implementation (1983) p. 200

For the uninitiated, accessors are methods that let you read and write the value of an instance variable of an object.

https://wiki.c2.com/?AccessorsAreEvil

Accessor methods are used to retrieve and update the values of the state variables

Smalltalk With Style, Edward J. Kilmas & Suzanne Skublics & David A. Thomas, (1996), p. 15

And various parts of writings by Kent Beck.

For a slightly more modern examples, a quick web search of "ruby attr_accessor" will be pretty fruitful.

Gypsydave5 (talk) 14:59, 12 October 2021 (UTC)[reply]

Name Change[edit]

Suggest renaming this article Accessor method

  1. The article discusses both getter and setter methods, but the title reflects only setter. Accessor describes both.
  2. The term 'mutator method' is less popular than both accessor and setter (https://trends.google.com/trends/explore?date=all&q=setter%20method,mutator%20method) (https://books.google.com/ngrams/graph?content=accessor+method%2Cmutator+method&year_start=1980&year_end=2019&corpus=26&smoothing=3#)
  3. I've never met anyone in my entire career who calls it a mutator method.

Gypsydave5 (talk) 20:30, 12 October 2021 (UTC)[reply]

In Wikipedia we need to make a distinction between common usage and a discipline's terminology. I'm not at all sure why uncited mention of some kind of procedural mutation is there, because I believe that to be fraudulent, but in terms of OO encapsulation, outside of the most popular "getter/setter" usage, Accessors and Mutators have always been the "official" terminology used in my programming lifetime. I believe Accessor as an umbrella term of the two to be mere colloquial laziness. I'll let others duke this one out though.
𝓦𝓲𝓴𝓲𝓹𝓮𝓭𝓲𝓪𝓘𝓼𝓝𝓸𝓽𝓟𝓮𝓮𝓻𝓡𝓮𝓿𝓲𝓮𝔀𝓮𝓭-𝓟𝓮𝓮𝓻𝓡𝓮𝓿𝓲𝓮𝔀𝓮𝓭𝓜𝓮𝓪𝓷𝓼𝓡𝓮𝓿𝓲𝓮𝔀𝓮𝓭𝓑𝔂𝓟𝓮𝓮𝓻𝓼𝓞𝓷𝓵𝔂 (talk) 21:12, 22 December 2021 (UTC)[reply]

Remove all mention of the unsourced "procedural mutator"[edit]

There is no such thing as elaborated upon here. The item as described is a shortcut over 1. safe assignment, 2. conditional assignment, or 3. mere compiler duping to keep its mitts off of direct assignment. It is not necessarily encapsulation, which defines the terms. It's possible to have subsystems that wall themselves off (The X11 subsystems have such a mechanism) complete with mutator-like idioms, but this is not how it's phrased here. Further, it's possible to have an OO implementation of something written in a procedural (only) language, but then we're back to OO encapsulation which again drives the proper definition of the term.

𝓦𝓲𝓴𝓲𝓹𝓮𝓭𝓲𝓪𝓘𝓼𝓝𝓸𝓽𝓟𝓮𝓮𝓻𝓡𝓮𝓿𝓲𝓮𝔀𝓮𝓭-𝓟𝓮𝓮𝓻𝓡𝓮𝓿𝓲𝓮𝔀𝓮𝓭𝓜𝓮𝓪𝓷𝓼𝓡𝓮𝓿𝓲𝓮𝔀𝓮𝓭𝓑𝔂𝓟𝓮𝓮𝓻𝓼𝓞𝓷𝓵𝔂 (talk) 21:21, 22 December 2021 (UTC)[reply]