[Python-Dev] PEP 8 and optional underscores

Barry Warsaw barry at python.org
Thu Jun 12 13:49:42 CEST 2008

Hash: SHA1

On Jun 11, 2008, at 2:03 PM, Raymond Hettinger wrote:

> "Function names should be lowercase, with words separated by  
> underscores as necessary to improve readability." -- PEP 8
> If I'm reading this correctly, then underscores are not required   
> everywhere.  Can some of these be shortened?
>   function:: active_count()
>   method:: Thread.get_name()
>   method:: Thread.is_alive()
>   method:: Thread.is_daemon()
>   method:: Thread.set_daemon(daemonic)

+1 on opting for properties in the specific cases here where it makes  

> In some cases, the mental pronounciation changes and affects my  
> perception of meaning.  For example, Thread.setName or  
> Thread.setname both feel like a setter to me, but Thread.set_name  
> causes a mental pause and a momentary double-take (is it the name of  
> a set?).
> A few months ago, I think there was a PEP 8 discussion rejecting  
> suggestions to make underscores required everywhere (leading to  
> getattr-->get_attr, iteritems-->iter_items,  staticmethod- 
> >static_method, setdefault->set_default, popitem->pop_item,  
> splitlines->split_lines etc.)
> Perhaps underscores should only be used when the contracted form  
> lacks clarity.

There are some builtins that I wish had used underscores to make them  
easier to read.   isinstance() and issubclass() come to mind.

OTOH, getattr and iteritems are already contractions, so leaving them  
underscoreless doesn't bother me too much.  For the others you  
mention, well I'll invoke ZoP 12 and 13.

There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.

- -Barry

Version: GnuPG v1.4.9 (Darwin)


More information about the Python-Dev mailing list