1
0

code_style.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Basically, PEP8
  2. - NEVER tabs. 4 spaces to indent.
  3. - Max line width: 79 chars (with flexibility to overflow by a "few chars" if
  4. the overflowing content is not semantically significant and avoids an
  5. explosion of vertical whitespace).
  6. - Use camel case for class and type names
  7. - Use underscores for functions and variables.
  8. - Use double quotes.
  9. - Use parentheses instead of '\\' for line continuation where ever possible
  10. (which is pretty much everywhere)
  11. - There should be max a single new line between:
  12. - statements
  13. - functions in a class
  14. - There should be two new lines between:
  15. - definitions in a module (e.g., between different classes)
  16. - There should be spaces where spaces should be and not where there shouldn't be:
  17. - a single space after a comma
  18. - a single space before and after for '=' when used as assignment
  19. - no spaces before and after for '=' for default values and keyword arguments.
  20. - Indenting must follow PEP8; either hanging indent or multiline-visual indent
  21. depending on the size and shape of the arguments and what makes more sense to
  22. the author. In other words, both this::
  23. print("I am a fish %s" % "moo")
  24. and this::
  25. print("I am a fish %s" %
  26. "moo")
  27. and this::
  28. print(
  29. "I am a fish %s" %
  30. "moo"
  31. )
  32. ...are valid, although given each one takes up 2x more vertical space than
  33. the previous, it's up to the author's discretion as to which layout makes most
  34. sense for their function invocation. (e.g. if they want to add comments
  35. per-argument, or put expressions in the arguments, or group related arguments
  36. together, or want to deliberately extend or preserve vertical/horizontal
  37. space)
  38. Comments should follow the google code style. This is so that we can generate
  39. documentation with sphinx (http://sphinxcontrib-napoleon.readthedocs.org/en/latest/)
  40. Code should pass pep8 --max-line-length=100 without any warnings.