Why does Google use accessories and mutators after member variables?

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Function_Names#Function_Names

Regular functions have a mixed case; accessories and mutators correspond to the variable name: MyExcitingFunction (), MyExcitingMethod (), my_exciting_member_variable (), set_my_exciting_member_variable ().

Is it not all the point of encapsulation to hide implementation details from the user so that he / she does not know if the accessor / mutator / method returns a member variable or not? What if I change the name of a variable or change the way it is stored inside an object?

EDIT:

If I have an instance variable int foo_this seems simple

int foo() const { return foo_; }

but if I add another method that returns foo_ + 2, should I indicate if baror GetBar?

int bar() const { return foo_ + 2; }
int GetBar() const { return foo_ + 2; }

If I choose GetBarand later decide to cache the return value in another member variable bar_, do I need to rename the method to bar?

+5
source share
4 answers

In fact, the point of encapsulation is to hide the internal actions of the class, it is not necessary to hide the names of things. The name of the member variable does not matter; this is the level of indirection that an accessor or mutator provides.

( -), . , , , , .

, Google, , -.

+4

Google Google. - , .

- , "".

, , . .

+5

, . , , ( ) . : , , ; . , -, (, ), get set , , , , .

, , . , , . : . , , . ( : , , .)

+2

, , , .

bar/GetBar , , GetBar.

bar_, , , GetBar. , bar(), , , , .

, , , ( ) "", - - , , . , - , , . , , Google , . , , , , .

I read this style guide several times before, but I never worked at Google, so I don’t know how their code reviews tend to put it into practice. I must think that an organization whose size cannot be completely consistent in every detail. So your hunch is probably as good as mine.

+1
source

All Articles