Was working with some code today that I did not write and noticed that in a class there was a private member m_privateMember
. The coder had also included a method called GetPrivateMember()
which contained only return m_privateMember
. It is worth mentioning that this method is heavily used within the class itself as opposed to simply using the private field that is accessible in this scope.
Semantically I see a lot of things wrong with this. A method vs. an actual getter/setter seems sloppy and I've always thought that if you are within class scope it is better form to actually use the private field rather than the getter. Needless to say, I am going to clean up the code purely for the reason that it does not meet coding standards in our workplace but I was curious to know if doing so would also improve performance in any way?
Does calling a method that simply returns a private field invoke more overhead?