Python PEP8 Naming

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
tlf30
Member
Member
Posts: 35
Joined: Fri Feb 15, 2013 9:29 pm

Python PEP8 Naming

Post by tlf30 »

I have a hard time following the Python PEP 8 when it comes to the naming convention:
Function names should be lowercase, with words separated by underscores as necessary to improve readability.

mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.
Yet we see countless times in python where they break their own guild lines:
str.startswith()
file.readlines()
etc..

I like to use camelCase for my function names, and I see no issue with others using lower_case, but I fail to understand how PEP8 can require us to use 'lower_case' when python itself uses 'lowercase' (no underscore) in many situations.

Just rambling,
Trevor
Programming is like fishing, you must be very patient if you want to succeed.
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

Re: Python PEP8 Naming

Post by Rusky »

Probably for the same reason that they allow mixedCase- for backwards compatibility. They just want as much code as is reasonable to have the same style, for consistency.
HoTT
Member
Member
Posts: 56
Joined: Tue Jan 21, 2014 10:16 am

Re: Python PEP8 Naming

Post by HoTT »

Yet we see countless times in python where they break their own guild lines:
str.startswith()
file.readlines()
etc..
Probably underscores weren't deemed necessary to improve readability in this cases.
thomasloven
Member
Member
Posts: 89
Joined: Tue Feb 26, 2008 10:47 am
Location: Sweden

Re: Python PEP8 Naming

Post by thomasloven »

PEP 8 is a recommendation, not a law. What's important is the spirit.

Code: Select all

>>> import this
Also see - if you haven't - the PyCon talk: Beyond PEP 8 by Raymond Hettinger.
Post Reply