Thread: [Pyparsing] PEP-8 compliant naming, using synonyms
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2008-03-07 14:34:44
|
A while back, there was a suggestion to adopt PEP-8 compliant names in pyparsing. For example, oneOf, delimitedList, and quotedString do not conform to the PEP-8 recommended naming style. According to PEP-8, these should be one_of, delimited_list, and quoted_string. For this discussion, I'll call these two naming styles "mixedCase" and "names_with_underscores". I've used names_with_underscores for many years, in Pascal, PL/1, and C. When I learned Smalltalk, Java and C++, the general convention was shifting (to my perception anyway) to mixedCase naming. When I learned Tcl for my job, names_with_underscores was again prevalent, and I eventually came to equate mixedCase with "new and fun" and names_with_underscores with "archaic and nasty." So when I was developing pyparsing, I read PEP-8. I was still fairly new to Python, and had not fully navigated the waters of what's new and what's old. Everything that's ever been done in Python is documented *somewhere*, and very few places guide you that "module X is outmoded/deprecated" or "module Z is the new module Y". So I just assumed that PEP-8 was a product of its own generation (as are we all), and reflected late-80's/early-90's thinking, and that things had evolved some since the PEP's initial writing. Wanting to write code for the 21st century, I used mixedCase for pyparsing. Since then, I've gotten a few isolated feedback comments that pyparsing is nonstandard because it does not use names_with_underscores as directed in PEP-8. Of course, as any politician will tell you, the feedback you actually get is usually representative of many more with the same opinion, who for whatever reason choose not to express it aloud. Unfortunately, much of this discussion hinges on personal taste, so objective discussion is usually contrived, or constructed by someone who is trying to rationalize their existing preference (very similar to some of the "justifications" for different bracing styles when trying to establish a C/C++ or Java coding standard). I did receive one actual, objective, practical distinction between the two naming styles from one user who is vision impaired - on his tactile- and audio-assist hardware, it is difficult to change case within a contiguous word, but quite easy to insert an underscore, so pyparsing's use of mixedCase really slows him down. So I've considered adding PEP-8 compliant synonym definitions to pyparsing. This would consist of a series of name bindings added to pyparsing that look like: one_of = oneOf quoted_string = quotedString delimited_list = delimitedList rest_of_line = restOfLine Existing names would not be deprecated unless there was some huge "hurrah!" from the Python world. But I know that many people are already using the mixedCase style, and I strongly believe in not breaking peoples' existing code. Class names would not require synonyms, as ClassNameStyle as used in pyparsing *is* PEP-8 compliant, so OneOrMore, ZeroOrMore, etc. would not need to be changed or synonymified. Any comments? Thanks, -- Paul |
From: Joshua J. K. <jk...@sk...> - 2008-03-07 19:27:38
|
On Fri, 2008-03-07 at 08:34 -0600, Paul McGuire wrote: > A while back, there was a suggestion to adopt PEP-8 compliant names in > pyparsing. For example, oneOf, delimitedList, and quotedString do not > conform to the PEP-8 recommended naming style. According to PEP-8, these > should be one_of, delimited_list, and quoted_string. For this discussion, > I'll call these two naming styles "mixedCase" and "names_with_underscores". > <SNIP> > Any comments? Funny you should bring this up. When I first started reading the docs for pyparsing, one of my first (albeit fleeting) thoughts was, "Hmm, interesting, he doesn't follow PEP-8, the module must have been written in the early days of Python before PEP-8 was well established." I've gone through a lot of naming conventions in my programming experience. mostly_underscores when I did a lot of perl, MixedCase and varHungarianNotation (shudder) when I did VB programming, and even mixed case when I was starting in Python before I read PEP-8. I'm not a fanatic of one style over another, really, and in fact kind of like the look of MixedCase. But I do like consistency, and if there is a "blessed" way of doing things (as I would consider PEP-8 to be) I would tend to lean in that direction. In addition to the reason regarding vision-imparied programmers, I would also add that MixedCase, even if it is capitalizing every word, could still be harder for non-native English speakers to read than words separated by underscores. So, in short, I support the aliasing, and possibly the eventual replacement, with PEP-8 compliant names. Implementation idea: rename all the functions to PEP-8 compliant names, and make wrappers using the old names. Then the wrappers would print out 'suchAndSuch deprecated, use such_and_such instead. Something else to thing about: what does PEP-8 say about keyword arguments? Like I said, I don't really prefer one over the other, but I do like consistency. j -- Joshua Kugler VOC/SigNet Provider (aka Web App Programmer) S&K Aerospace Alaska |
From: Ralph C. <ra...@in...> - 2008-03-08 13:09:56
|
Hi Paul, > So I've considered adding PEP-8 compliant synonym definitions to > pyparsing. This would consist of a series of name bindings added to > pyparsing that look like: > > one_of = oneOf > quoted_string = quotedString > delimited_list = delimitedList > rest_of_line = restOfLine I think it's well worth doing this. First impressions count, and seeing non-PEP-8 stuff is a distraction. The idea of issuing a deprecated warning in the future is a good one too. Cheers, Ralph. |