[SOLVED] Access Modifiers, performance question


(Bora Kasap) #1

is private access modifier makes better performance than public?

i ask this because i don’t know which one of my guesses are right?

GUESS 1 Initializes without access ways. Public = it creates access ways to be public. Private = it doesn’t creates access ways so it is private.

GUESS 2 Initializes with access ways. Public = it doesn’t block access ways so it is public. Private = it blocks access ways to be private.

And of course, the main question, is that makes a “minimal” performance difference? I don’t want to make my public variables or functions private if it is for nothing…


(JP Mortiboys) #2

There’s no real speed difference is using public vs private : http://jacksondunstan.com/articles/1820

What you should use is dependent on the class itself - does the outside world NEED to access this function? If so, make it public; if not, private or protected.

One of the best reasons for limiting your public interface is that you can minimise error-checking on private functions and only validate parameters on public functions; because you can control when you call private functions and know in advance what parameters may or may not require validation.


(Bora Kasap) #3

Got it, thanks for help. “Don’t make public if you don’t need it!”


(Zachary Lewis) #4

I prefer, “Don’t make it public if you don’t want others to use it.” It works for both code and life.


(Bora Kasap) #5

:slight_smile: :slight_smile: :slight_smile: Philosophy works.


(Zachary Lewis) #6

Testing the forum’s new “reply via email” capability. Test post, please ignore.

— Sent from Mailbox for iPhone