Skip to content

Consider not curating a full custom Python code-style guide #20

Closed
@lukpueh

Description

@lukpueh

transferred from in-toto/in-toto#370

--

Description of issue or feature request:

Following coding style guidelines is extremely important especially for the reference implementations we create at the lab. But I've become increasingly reluctant to point contributors to our guideline document, due to the issues outlined below.

Given that curating our own code style guide is a time-consuming task and there are many excellent code guides out there, I wonder if it wouldn't be better to restrict our guide to:

  • pointers to PEP 8 and other well-curated code style guides that match our expectations, and
  • only document the differences and short-comings we identify in those guides.

E.g. "Do as in PEP 8, but indent with 2 instead of 4 spaces!" (for reasons XYZ ... needs less horizontal space, consistency with existing code don't want a global flag day, ...)

I'd also like to say that I find the Google Python guide really good and it covers most of the principles of our guide in a clearer way, and other things that I find helpful.

Regardless, we should also configure strong linters on all projects (see e.g.
secure-systems-lab/securesystemslib#243) to enforce the code style we expect.


Issues with the current guideline

  • unclear mix of " and ' (see Single quotes (') or double quotes (") #4)

  • Python2-centered, e.g.: use of print statement and file built-in, mention of Python 2.3 (!!) and 2.6, no mention of Python 3

  • several inconsistencies between recommendations and examples, especially in the "Maximum line length" section, where the "how it should be done"-example has wrong line continuation indentation, unclear line break condition (neither hanging nor aligned indent, nor breaking close to 80 chars), no blank lines to separate logic, use of format operator which is advised against. Other inconsistencies include recommended but missing underscores in "Naming" section, missing whitespaces around operators in some string concat examples, etc...

  • some code examples are unnecessarily comprehensive, so that the emphasis on the specific recommendation suffers (especially in "Maximum line length", or in "Never use short circuit..")

  • syntax errors, e.g. assert(x = y), or the incorrectly continued strings in "Never use short circuit.."

  • obsolete recommendations about subprocesses (these things are documented in in the Python reference of the subprocess module and only add clutter here) and pointers to archived Seattle code

  • important drawbacks in our custom docstring format

    1. not Sphinx-friendly
    2. (less important) needs more vertical space than necessary

    I suggest using Google style docstring, for which there is Sphinx extension, and which needs less vertical space than the similar NumPy style, and which (just as NumPy) is also friendlier to the human eye than the standard reStructuredText Docstring Format.

    See Revise and update source code documentation and build with sphinx in-toto/in-toto#369 for a recent switch to Google style docstring.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions