Does Python really follow its philosophy of "Readability counts"?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Jan 25 19:59:48 EST 2009


On Sun, 25 Jan 2009 12:01:16 -0800, Russ P. wrote:

> On Jan 25, 10:04 am, Mark Wooding <m... at distorted.org.uk> wrote:
> 
>> > But what if I want an automatic check to verify that I am using it as
>> > the author intended? Is that unreasonable?
>>
>> You mean that you can't /tell/ whether you typed mumble._seekrit?
>> You're very strange.  It's kind of hard to do by accident.
> 
> But what if you type "mumble._seekrit" in several places, then the
> library implementer decides to give in to your nagging and makes it
> "public" by changing it to "mumble.seekrit". Now suppose you forget to
> make the corresponding change somewhere in your code, such as
> 
> mumble._seekrit = zzz
> 
> You will get no warning at all. You will just be inadvertently creating
> a new "private" attribute -- and the assignment that you really want
> will not get done.
> 
> For that matter, the library implementer himself could make the same
> mistake and get no warning.
> 
> When you think about it, you soon realize that the leading underscore
> convention violates the spirit if not the letter of one of the first
> principles of programming 101: if you have a constant parameter that
> appears in several places, assign the literal value in one place rather
> than repeating it everywhere. Then if you need to change the value, you
> only need to change it in one place. That reduces effort, but more
> importantly it reduces the potential for error.

How is this scenario different from an API change where public_method() 
gets changed to method()? Surely this is just a downside to Python's lack 
of declarations, rather than specific to Python's lack of data hiding?



-- 
Steven



More information about the Python-list mailing list