"""Dear BDFL,

I'm writing my talk for a local PyCon (it is on Saturday - and I'm late as ever), and one of the questions I'm trying to answer is why Python doesn't have real information hiding the in the way of the C++ (or Ruby) ideas of public, protected and private.

Everything I've found online just mentions the state of what it is now, with leading underscore being considered private, and double underscore getting mangled with the classname, but these are still public (and we are consenting adults). Was there a particular driving force behind the access methods in Python? Or was it a collection of smaller things?

--Procrastinating in the Southern Hemisphere
"""

Dear Procrastinating,

There is actually some information hiding possible -- but only by writing C extensions. :-)

The main reason for making (nearly) everything discoverable was debugging: when debugging you often need to break through the abstractions (since bugs don't confine them to the nice abstractions you've created for your program :-) so I though it would be handy to be able to see anything from the debugger. And since the debugger is written in Python itself (for flexibility and a number of other reasons) I figured the same would apply to other forms of programming -- after all, sometimes debugging doesn't imply using a debugger, it may just imply printing a certain value. Again, too much data hiding would make things more complicated here.

The other observation was that even in C++, there are usually ways around the data hiding (e.g. questionable casts). Which made me realize that apparently other languages could live just fine with less-than-perfect hiding, and that hiding was an advisory mechanism, not an enforcement mechanism. So Python could probably be just fine with even-less-than-perfect hiding. :-)

Good luck with your talk, and enjoy the event!
Shared publiclyView activity