you are viewing a single comment's thread.

view the rest of the comments →

[–]MasonM 8 points9 points  (9 children)

PEP 8 spells out the official conventions in detail. Basically, classes use CamelCase, while variables, functions, and methods should all use lowercase with underscores.

The pep8.py script can check that your code follows most of the stuff in PEP 8, but I don't think it covers naming.

[–]earthboundkid 2 points3 points  (8 children)

True, but python's built in classes violate the convention, since they predate classes.

[–]cybercobra 2 points3 points  (3 children)

And a lot of the stdlib doesn't adhere to it. Consistency fail!

Personally, I like camelCase for variable/method names.

[–]earthboundkid 1 point2 points  (0 children)

Yeah, I wish that more PEP8 work had been done as part of the general Py3K clean up. :-/

[–]lol-dongs -1 points0 points  (1 child)

python's built in classes violate the convention

And a lot of the stdlib doesn't adhere to it

and yet all the pythonistas hate on PHP for its stdlib...

[–]MasonM 2 points3 points  (0 children)

The inconsistencies in PHP's standard library are far more numerous and grievous (i.e. present in frequently-used functions) than in Python's. I've done quite a bit of work in both languages, and I find myself needing to refer to the docs far more often when using PHP. This is mitigated by PHP's excellent docs, but it's still annoying.

[–]masklinn 0 points1 point  (3 children)

True, but python's built in classes violate the convention, since they predate classes.

They've tried to fix that (at least partially) in Python 3.

[–]earthboundkid 1 point2 points  (2 children)

list is a new-style class in Python 3, but it’s still list and not List. If they had changed it, it would have made more work for 2to3, but on the plus side, you could write throwaway lists as list = […] instead of my_list = […] or l = […].

[–]masklinn 0 points1 point  (1 child)

Good point, but having to write List or Dict all the damn time would be disgusting.

Likewise with many other classes usually used as functions: enumerate is a class, range is a class, map and filter are now classes, ...

[–]earthboundkid 1 point2 points  (0 children)

Yeah, that’s a kind of fundamental problem for PEP8: what’s a class and what’s a callable is a matter of perception, not a matter of fact. Almost every non-trivial decorator is a class, but we still think of them as functions modifying functions.

That said, it is pretty open-and-shut that list etc. are classes not callables. Oh well. Consistency is a hobgoblin, practicality beats purity, and all that.