Why does python not have a mechanism for data hiding?

Roy Smith roy at panix.com
Wed Jun 4 22:36:07 EDT 2008


In article <87prqwltqi.fsf at benfinney.id.au>,
 Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:

> Then what you're really testing is the interactions of the "push the
> button" function with its external interface: you're asserting that
> the "push the red button" function actually uses the result from "pick
> a random city" as its target.

No, that's not what I'm testing at all.  I want to test that the cities 
really do get picked randomly.  Notice the implementation I gave:

   def _pickCity():
      cities = ['New York', 'Moscow', 'Tokyo', 'Beijing', 'Mumbai']
      thePoorSchmucks = random.choice(cities)
      return 'New York'

There's a deliberate bug in there, i.e. it always returns 'New York', which 
(as a resident of that city), I would find distressing in such an 
application.  If you plugged in some other function for _pickCity(), you'd 
never discover that bug until it was too late.



More information about the Python-list mailing list