Zine

open source content publishing system


Code Styleguide

TextPress has a pretty strict code styleguide, so strict that code that doesn't match those criteria is not added into the the main TextPress repository.

So here a 5 point list for better code:

  1. indentation and spacing: python code and css 4 spaces, JavaScript with 2 spaces. EOF79 and no trailing whitespace!
  2. one empty line after methods and class docstrings, two empty lines after classes or functions, no empty line after module docstrings, but two after imports (if there are no imports, two empty lines after module docstrings)
  3. # -*- coding: utf-8 -*- as encoding cookie.
  4. standard module docstring (see below)
  5. functions, methods, variables are_named_like_this, classes ShouldLookLikeThat, acronyms in class names are all uppercased. (and for all SOC students: no Hungarian notation)

Standard Module Docstring

"""
    full.import.name
    ~~~~~~~~~~~~~~~~

    Useful description, mandatory, can be longer!

    :copyright: YEAR by Your Name.
    :license: THE_LICENSE, see LICENSE for more details.
"""

Comments

We have some inline comments:

  • # foo for normal inline comments
  • #: foo for comments that document the next assigned variable
  • #_ foo for comments that document the next translatable string
  • #! foo for comments that document the next emitted event
  • ## for code that is commented out

Those comments are important for translators, plugin developers and the tools that generate automatic documentation (even if they don't exist yet). So please try to use the correct comment forms.

Final Words

If in doubt, look at already existing code or break rules. But don't break too many!