[Python-Dev] Changes to PEP 327: Decimal data type (original) (raw)

Michael Chermside mcherm at mcherm.com
Wed Mar 17 12:29:02 EST 2004


Oren writes:

> Decimal.fromFloat(floatNumber, positions)

+1 on the behavior. One nitpick about the method name: this caseConvention is not consistent with the Python Style Guide (PEP 8)

It IS consistant as I read it:

Function Names

Plain functions exported by a module can either use the CapWords style or lowercase (or lowercasewithunderscores). There is no strong preference, but it seems that the CapWords style is used for functions that provide major functionality (e.g. nstools.WorldOpen()), while lowercase is used more for "utility" functions (e.g. pathhack.kosroot()). [...] Method Names The story is largely the same as for functions. Use lowercase for methods accessed by other classes or functions that are part of the implementation of an object type. Use one leading underscore for "internal" methods and instance variables when there is no chance of a conflict with subclass or superclass attributes or when a subclass might actually need access to them. Use two leading underscores (class-private names, enforced by Python 1.4) in those cases where it is important that only the current class accesses an attribute. (But realize that Python contains enough loopholes so that an insistent user could gain access nevertheless, e.g. via the dict attribute.)

I interpret that to mean that CapWords (fromFloat) is a perfectly valid style for method names. If I'm mis-interpreting it, please let me know.

And if I AM mis-interpreting it, then it's too bad. This is one minor area where Java has a better design than Python. Both languages allow any identifier, without considering case as significant. However, Java has had a clear, well-defined, and well known convention since its inception (CapWords for classes, lowercase for packages, lowerCapWords for methods), while Python's convention is vaguely specified by PEP 8 and inconsistantly applied throughout the standard library and most developer's code. The result is that in Java, I always know how to spell a name, but in Python sometimes I have to look it up.

-- Michael Chermside



More information about the Python-Dev mailing list