Hacker News new | ask | show | jobs
by symmitchry 2803 days ago
> I have major gripes with PEP-8, and if you ever see me using it I want you to shoot me in the face.

That sounds extreme. I've never heard this before. Why?

3 comments

IIRC, pep8 would have you write:

    def my_very_very_very_very_very_long_function_name(self,
                                                       param1,
                                                       param2):
Looking at it (https://www.python.org/dev/peps/pep-0008/), that is one of the options, but you could also do:

  def my_very_very_very_very_very_long_function_name(
          self, param1, 
          param2):
      pass
Shrug. Seems okay to me, and preferable to what they say no to.
You can choose to use:

    def my_very_very_very_very_very_long_function_name(
            self, param1, param2):
        ...
Ah, my mistake.
My preference is to do this, which I think is quite nice and easy to work with:

    def my_very_very_very_very_very_long_function_name(
            self,
            param1,
            param2,
            ):
        do_it()  # function body here.
Yup this. It works perhaps even more nicely in languages that have braces and return types, e.g.

    func some_name(
        arg: Type,
        arg2: Type
    ) -> RetVal {
        …
    }
Yep, this is by far my least favorite autopep8 "correction".
if your function name is that long, you have a problem
I have major gripes with it too and don't use it unless a project enforces it.

The main ones that get me are the whitespace (4 characters) and restrictive line length (79 characters) rules. They don't work well together, and also don't work well with python's significant whitespace (can't easily break up a line), namespaces, generator expressions, and type hints. All for a subjective formatting decision.

I'll also often see people trying to cram as much as they can into 79 characters with one letter variable names and such while calling that elegant code because it's a "one-liner."

Yes, the 79 character limit gets in my nerves. Unless you're using a machine built in the 70s or 80s, this limit is complete BS

To be honest it says right at the beginning of PEP-8 that "A Foolish Consistency is the Hobgoblin of Little Minds" but it seems little minds are the norm (and usage of 'pep8' package to make developers do what a computer could do faster and better)

I don't see many projects enforcing a line length, and if they do it's generally set much higher (120-150).
PEP-8, to quote it [1], says in its first sentence:

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

If you are not writing Python's stdlib, you are free to not to stick to it.

If in doubt, the next section of the document is helpfully titled "A Foolish Consistency is the Hobgoblin of Little Minds".

[1]: https://www.python.org/dev/peps/pep-0008/