On Jan 25, 10:04 am, Mark Wooding <m...@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. The same principle applies to "declaring" an attribute private. If that "declaration" is encoded in every occurrence of its identifier, then if you decide to change it to public, you need to change the identifier at each and every location. But if a "private" or "priv" keyword were available, you would only need to make the change in one location. -- http://mail.python.org/mailman/listinfo/python-list