My favorite advice on the topic of method visibility (i.e. public vs. private) comes from Python creator Guido van Rossum. It goes something like “we’re all adults here” and says it’s not really a necessary thing for compilers/runtimes to hide methods from specific callers. Don’t go mucking around in other object’s implementations. I still think that’s mostly right.
Except, coming up to speed on a new code base is vastly easier when there’s some delineation of the waterline between an object’s public API which it expects other objects to use and its private implementation which it does not. It tells me a) the private methods are open for change and refactoring and b) below the private “waterline”, don’t bother going any deeper when spelunking to figure out how this program works.
In a new or strange codebase, every little bit of tractability helps.
One thought on “We’re all adults here, but we’re not all mind readers”
This has to be one of my favorite features of Ruby: you can clearly defined private/public/protected so the waterline is clearly marked. But you can still invoke private methods if absolutely necessary.
Comments are closed.