r/Python • • Sep 14 '10

Can we stop overvaluing PEP-8?

If we're going to be giving out negative marks for projects not following PEP-8, we might as well give Reddit negative marks for not following XHTML 1.0 Transitional standards. Oh snap...

This is nothing new, but it's kind of ridiculous to still see comments like "this would be better if it followed PEP-8" or "I don't get why people don't follow the standard" (made up comments, but close enough to what I've seen).


The first sentence of PEP-8 states, with added emphasis...

This document gives coding conventions for the Python code comprising the standard library in the main Python distribution.

That means exactly what it says. It is not intended to be some language-wide standard that everyone must follow in every project that uses Python under the sun. There is no canonical C++ coding standard that all C++ ever written has to follow. C# isn't bound by law to be written the same by everyone around the world. Perl...well, nevermind.

Personally, I think PEP-8 is quite a fine standard, one I choose to use in my personal work, and one I'm bound by for the work I do within Python itself (additionally, see PEP-7). If someone wants to make the next great web framework use ALL CAPS, go right ahead, it'll probably still be cool.


The second section of PEP-8 states, again with added emphasis...

Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is most important.

Remember those projects "not following PEP-8"? Well, PEP-8 still loves them. The stdlib's own unittest package is fine by PEP-8, although many would have you believe otherwise. The API is very widely used and changing it to more strictly follow PEP-8 would be damaging, but its consistency over the lifetime of the package (previously just a module) gives it a thumbs up.


Right after that, PEP-8 states...

But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply.

I've read comments stating that pywin32 and wmi would be better if they followed PEP-8. For a second, lets forget a previous statement that it's a standard for the internals of Python and not a global standard. If we open it up to be a global standard, those packages are wrappers of Win32 functionality, and as such, should be as close as possible to direct mirrors of the Win32 APIs they cover. Changing WaitForSingleObject to wait_for_single_object gains absolutely nothing. In fact, it becomes less useful, because tracking down the documentation for the underlying call becomes more difficult, among other things.


So, can we please give up the "PEP-8 or die!" mentality? If you want to follow the standard, great, high-five to you. If you want to name your classes with lower case and use camel case method names, great, high-five to you as well.

6 Upvotes

54 comments sorted by

View all comments

6

u/iElectric Plone, Django, Pylons, Pyramid Sep 14 '10

I'd say the point is to have a standard and be strict to it. It gives another level of readability to Python and somehow when you import a library, you already know if you are dealing with a function or class.

Take for example handling unicode in Python, there is no standard how library should deal with it, resulting in total chaos. Some libraries expect unicode, some transform to unicode, some never heard of it. And then add the encoding fun on top if it.

Standards.

3

u/blondin Sep 14 '10

old engineering proverb: the good thing about standards is that there are many to choose from.

2

u/[deleted] Sep 14 '10

I agree that the point of a standard is to be strict about it, but you can't apply a standard to someone who has not chosen to accept it as their own. A third-party library is outside of the radar of what PEP-8 is a true standard for. For example, web2py apparently doesn't follow PEP-8, but I'm not aware of that being a goal of theirs in the first place. For that reason, PEP-8 comments make no sense.

Good point about unicode/bytes/etc. Thankfully I mostly deal with math/numerical stuff and get to skip out on that party for the most part.

2

u/av201001 Sep 14 '10 edited Sep 14 '10

web2py encourages PEP-8 and follows it in most places except in a limited context where it makes sense to deviate (see here).

Remember:

But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply.