On 12/11/05, Steven Bethard <[EMAIL PROTECTED]> wrote: > On 12/11/05, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > I know about the fear of accidental reuse of class names, but I don't > > find it a compelling argument. > > FWIW, I know I currently have a number of classes that are potentially > hazardous in this way. Each of these classes is basically a > substitute class for a third-party API that I have to code to. The > API is missing a number of convenience methods, and the most > straightforward way to introduce these methods[1] is to create a > subclass of the appropriate class. Since they are in a different > module, it seems perfectly normal for me to give them the same name > since for all external modules, they should look the same as the > original API (but with the added methods). So I have a number of > classes that look something like: > > class Document(_cdm.Document): > ... > # add convenience methods here > ...
Personally, I find that naming convention a mistake. Call it MyDocument or EnhancedDocument or DocumentPlusPlus (be creative!) but don't reuse the original name. I'm not saying this because it helps the __private argument; I'm saying this because in lots of contexts we leave out the package/module path and only use the class name, and added functionality is a good reason to be able to distinguish between the original class and the enhanced version. > > Also, I like the current, well-defined mangling algorithm; it means > > that when I'm in the debugger I can manually mangle or unmangle names > > as required. > > Why couldn't the name mangling do something like: > > '_%s_%s__%s' % (cls.__module__, cls.__name__, attrname) Too long, IMO. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com