Thoughts about Python
Paul Prescod
paul at prescod.net
Tue Feb 24 21:33:04 EST 2004
Greg Ewing (using news.cis.dfn.de) wrote:
>....
> You're right that naming conventions (or lack thereof) in Python
> leave something to be desired, but we're stuck with many of them
> for historical reasons.
Not really. If "open" can be renamed "file" it could also have been
renamed File. To be honest I think that the real problem is that Guido
is allergic to caps. I don't know how None snuck in. ;)
> Your suggested convention (classes start with uppercase, functions
> with lowercase) has its uses, and I tend to follow it in most of
> the code that I write, but it has its drawbacks as well. A
> counterargument often put forward is that users of a class usually
> don't care whether something is really a class or whether it's
> a factory function, and often you would like to be free to change
> the implementation from one to the other without affecting client
> code. With a naming convention that distinguishes classes from
> functions, you can't do that.
Changing from a function to a class is _always_ easy.
def open(filename, flags):
return File(filename, flags)
The trickier issue is having the class itself export the interface the
client code is used to.
Changing from a class to a function is never really very safe:
class myobject(File):
...
if isinstance(myobject, File):
....
How can you change File to be just a function safely? But anyhow, why
would you want to?
Paul Prescod
More information about the Python-list
mailing list