There is only one truth. It is the source.
December 13, 2012
Tags: java, private, protected, public, python
In a job application I had to answer this question:
What's something (programming or computer science related) that you disagree with the vast majority of programmers about? What makes you convinced that you're correct?
My answer:
Some languages like Java have the concepts of private/protected and friends. These language features are used to control access to attributes and methods of classes. The advocates say that this enables encapsulation. They think they are right. They are wrong. Using private does not enable encapsulation because code is properly encapsulated by good object-oriented design, not by complier tricks.
Indeed using private and friends can be harmful to people who want to reuse your objects or extend them or correct mistakes in them. In other words the only legitimate use of these keywords is code written by those who can design 100% bug free future proof objects that are capable of doing anything anyone would ever consider using them for. This is an impossibility. All abstractions leak. Attempts to stop abstraction leakage are mistakes and will fail regardless.
Python does not include these nonsensical concepts. In Python there is a convention of prepending an underscore to the names of variables and functions that are intended for internal use. This is what private is ostensibly for. But in Python the underscore prefix is just an understood contract. The contract states that if you monkey patch, override, call such members that you and only you are responsible if it doesn't work. The point is that internal functions are internal for a reason, but if you know what you're doing then do whatever you want. If you don't know what you're doing and it doesn't work, tough luck. If you don't have the source code you get screwed even if you know what you're doing.
I know I am correct because if you have the source code you could use a find-and-replace operation to convert all private members to public members.