1. Common
  2. Python
    1. Docstrings
    2. Python References
  3. Javascript

Coding Styles

Common

  • Line length: Maximum of 119 rather than usual 79. That said, where possible keep it between 79-99 to keep it readable.
  • Indent: 4 spaces, no tabs.
  • All code should use 'single quotes'.

Python

Deluge follows PEP8 and Python Code Style with line length the only exception.

  • Using the pre-common app can aid in picking up issues before creating git commits.
  • All byte strings (str) should be decoded to strings (unicode strings, unicode) on input and encoded back to byte strings on output. From Stackoverflow:
    >>> b"abcde"
    b'abcde'
    >>> b"abcde".decode("utf-8")
    'abcde'
    
    Notes:
    • PyGTK/GTK+ will accept str (utf8 encoded) or unicode but will only return str. See GTK+ Unicode docs.
    • There is also a bytearray type which enables in-place modification of a string. See Python Bytearrays
    • For reference Python 3 renames unicode to str type and byte strings become bytes type.
  • All relative path separators used within code should be converted to posix format /, so should not contain \ or \\. This is to prevent confusion when dealing with cross-platform clients and servers.

Docstrings

You will find a mix of the older reStructuredText and newer, easier to read, Sphinx Napoleon format.

Going forward the Napoleon Google Style will be used for all new doctrings and eventually convert over the rest.

Google Style short example:

def func(arg):
   """Function purpose.

   Args:
       arg (type): Description.

   Returns:
      type: Description. If the line is too, long indent next
         line with three spaces.

   """

Most common sections are Args and Returns. See complete list of supported headers.

Verify that the documentation parses correctly with:

python setup.py build_docs

Python References

Useful links to style guides from other projects:

Javascript

Using codepainter with hautelook style will ensure a consistent coding style.

codepaint xform -p hautelook "file.js"
  • Classes should follow the Ext coding style.
  • Class names should be in CamelCase
  • Instances of classes should use camelCase.
Last modified 7 years ago Last modified on 11/13/2016 11:56:03 AM