Home > OS >  Will avoid using private properties in Class in programming improve program efficiency?
Will avoid using private properties in Class in programming improve program efficiency?

Time:10-18

In the situation of 100% guarantee that all the members of a system development will not call the object properties that should be "private" to that class only outside of that class, so we do not set the "private properties" as private, so that although technically these "private properties" still can be called outside but we as a developer will very carefully not to call those private properties, will this improve a bit system efficiency because the system do not need to take the privacy of the properties ?

CodePudding user response:

No, not at all.

In interpreted languages, the access check will still be made when accessing the member (e.g. from a class method).

In compiled languages, being private vs. public leads to practically identical code. Access specifiers (private, public, protected) are not a security feature. They are "only" there for the writer of the class to specify what is the public interface for callers, and what are the implementation-specific details that callers need not (and should not) have to think about.

(There is one small exception: in C , access specifiers can affect class layout, which may, in some cases, affect performance. However, there's no saying which access specifier "makes things faster", it could go both ways.)

  • Related