[Tutor] Philosphy on method naming in modules?
Terry Carroll
carroll at tjc.com
Tue Sep 2 20:57:58 EDT 2003
I've written a little module, and it's gotten me thinking about the
philosophy, and maybe even ethics and/or etiquette, of naming methods.
My module, which I call Unihan, provides an interface into the Unicode
folks' Unihan.txt file. You can see this file, all 10 meg of it, at
<http://www.unicode.org/Public/UNIDATA/Unihan.txt>.
I use this to basically do lookups in the file, using the various tags
as keys. For example, I can take a sequence of 4 hex digits, and find
out whether any character uses that code, either in Unicode, Big Five,
or GB, or any of the other encoding methods documented in the Unihan.txt
file (although I only know a little Chinese, so the encodings for
Korean, Japanese, etc. are pretty much a mystery to me).
Right now, this is just for me, but I plan to make it available in case
anyone else would care about it.
So here's the thing: should the developer of a module that's going to be
publicly shared try to use unique method names, to avoid name collisions
with other modules? For example, a method I have that uses Tkinter to
display the character and its related data is named merely "Display."
This happens to be a bound method, so isn't the greatest example, but
suppose it wasn't? If everyone used a method name like "Display", it'd be
tough to use more than one of the conflicting modules.
I suppose part of the problem is my approach to using modules. I almost
always used "import foo" rather than "from foo import bar, baz" or "from
foo import *" to import; so I usually end up fully-qualifying the method
names I use, anyway (the exception being Tkinter, where the code just bogs
down too much).
So what do you guys think? For an unbound method to display a thing,
should you use a nice generic name like "Display", or deliberately alter
the name to something a little less mnemonic, but less likely to collide
(say, "UnihanDisplay", "UHDisplay" or some such)?
--
Terry Carroll | "I say to you that the VCR is to the American
Santa Clara, CA | film producer and the American public as the
carroll at tjc.com | Boston strangler is to the woman home alone."
| Jack Valenti, MPAA President
Modell delendus est | Testimony before Congress, 1982
More information about the Tutor
mailing list