| |
comp.lang.python |
I ***love*** this "10 Little Programs" idea! As soon as I get a On May 26, 2:38 pm, Steven Bethard <steven.beth...@gmail.com> wrote: > http://www.python.org/dev/peps/pep-0008/ If we want to just say "well, PEP-8 says such and such," I think this > > class ShoppingCart: How's this for a better non-trivial method example: MAX_ITEMS_FOR_EXPRESS_LANE = 10 or call it "can_use_express_lane" if you must. I guess pyparsing with its mixedCase functions and attributes is -- Paul
breathing space, I'm going to add a "10 Little Parsers" page to the
pyparsing wiki!
> Though the code should probably follow PEP 8 guidelines, e.g.
> under_scores instead of camelCase for object and method names:
> </nitpick>
is the rationale for this? This style is so retro/80's/C-ish. It
seems more like a Java backlash to me than anything else. If we (or
Guido) don't like changing case to indicate word breaks, why are class
names to be UpperCamelCase, and not Capitalized_with_underscores? If
there is a casing convention nit to pick, I'd focus on UpperCamelCase
for class names, lower case (either with underscores or mixed case)
for attributes and method names, and UNDERSCORE_SEPARATED_ALL_CAPS for
constants.
is an area where the thinking has possibly evolved since 2001. Also,
I think the PEP would benefit from explicitly discouraging some
practices, such as Hungarian notation.
> > def __init__(self): self.items = []
> > def buy(self, item): self.items.append(item)
> > def boughtItems(self): return self.items
> > myCart = ShoppingCart()
> > myCart.buy('apple')
> > myCart.buy('banana')
> > print myCart.boughtItems()
the body on the same line as the def statement.
def canUseExpressLane(self):
return (len(self.items) <= MAX_ITEMS_FOR_EXPRESS_LANE)
doomed for the Dunce Corner. Too bad for BeautifulSoup, cElementTree,
and wxPython that are also at variance with this canon of Python
coding style. ("Modules should have short, all-lowercase names. ...
Python packages should also have short, all-lowercase names, although
the use of underscores is discouraged.")