Why does python not have a mechanism for data hiding?

Terry Reedy tjreedy at udel.edu
Sun May 25 21:34:50 EDT 2008


"Joe P. Cool" <joe.p.cool at googlemail.com> wrote in message 
news:09847cfc-eaec-4adc-8cbf-1e2ebbf940c4 at m44g2000hsc.googlegroups.com...
| Actually it is very useful to be able to  distinguish
| between inside and outside.

Which Python allows one to do.

| This is obvious for real world things e.g. your
| TV. Nobody likes to open the rear cover to switch the channel.

The original issue was that users might open the case to do something 
unplanned and that they would come to depend on and clamor for the 
maintenance of internal details that the manufacturer wants to change.  But 
in the real world, most customers know and accept that custom alterations 
and extensions of a product my be model specific.  Some things I buy even 
have a disclaimer that user-visible details might be different from what 
the instructions say, and only guarantee that the functionality will be as 
good or better than specified.

[...]
| Please don't sell a missing feature as a philosophy.

I won't if you don't claim that a feature is missing because you don't like 
its implementation.  To most of us, replacing the nearly never used '__' 
with a keyword would be a auful change.

| Please don't tell me that encapsulation does not mean "enforced 
restriction".

There are obviously degrees of enforced restriction.  Take your TV example. 
Most users will respect a 'do not open' request by the manufacturer 
(Python's '_'.).  But some will unscrew anyway.  So some makers use 
fasteners that are resistent to opening without specialized tools from 
specialized sources -- or perhaps specialized knowledge (Python's '__'). 
(This is very frustrating if one needs to open such a system.)  Or some 
mark the screws so they can detect and punish entry.  At least one (Apple) 
has intentionally altered internals to punish entry and alteration.  Or 
there is the 'embed in epoxy' method.

If you want something equivalent to epoxy embedding, design it, implement 
it, and share it (if you want).  Perhaps one could make an Opaque extension 
class, perhaps even usable as a mixin class rather than as a single-base 
class.

Terry Jan Reedy






More information about the Python-list mailing list