Edgewall Software

Changes between Version 23 and Version 24 of TracDev/CodingStyle


Ignore:
Timestamp:
Jan 14, 2015, 10:11:44 PM (9 years ago)
Author:
figaro
Comment:

Cosmetic changes

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/CodingStyle

    v23 v24  
    1 = Trac Coding Style =
     1= Trac Coding Style
    22
    3 Executive summary: we'll usually frown on patches that
     3Code is read more often than it is written, so we adhere to a coding style. Patches that:
    44 - have long lines
    55 - have multiple statements per line
    66 - break the naming conventions
    7 because this immediately tells us the patch author hasn't tried to follow our coding conventions. On the other hand, a patch that follows the conventions detailed below tells us that the patch author has made some effort, therefore the patch itself is much more likely to be a [[TracDev/SubmittingPatches#Whatisagoodpatch|good patch]] and has a better chance to get the attention it deserves...
     7do not follow our coding style. On the other hand, a patch that does meet the conventions is much more likely to be a [[TracDev/SubmittingPatches#Whatisagoodpatch|good patch]] and has a better chance to get the attention it deserves.
    88
     9Like most Python projects, we adhere to [pep:0008 PEP 8 (Style Guide for Python Code)] and [pep:0257 PEP 257 (Docstring Conventions)]. Be sure to read those documents if you intend to contribute code to Trac.
    910
    10 Like most Python projects, we try to adhere to [pep:0008 PEP 8 (Style Guide for Python Code)] and [pep:0257 PEP 257 (Docstring Conventions)]. Be sure to read those documents if you intend to contribute code to Trac.
     11Note that some of the current Trac code could violate coding style rules. We are always in the process of refactoring the offending modules so that all code adheres to the conventions.
    1112
    12 Note that some of the current Trac code could violate a couple of the rules stated below. We are always in the process of refactoring the offending modules so that all code uses the same conventions, though it's much better now than it used to be.
    13 
    14 == Naming conventions ==
     13== Naming conventions
    1514
    1615 * Package and module names should be all lower-case, words ''may'' be separated by underscores.
     
    2221 * Abstract base classes should use the suffix `Base`.
    2322
    24 == Strings ==
     23== Strings
    2524
    2625 - Use `"..."` for text meant to be read by users,
     
    3332 - For SQL code, use multiline `"""..."""` strings if needed. Single line SQL also use `"..."` style most of the time, as they often contain single quotes (`'`).
    3433
    35 == Miscellaneous ==
     34== Miscellaneous
    3635 * '''Lines shouldn't exceed a length of 79 characters.''' [[br]]
    37    No, it's not because we're mainly using VT100 terminals while developing Trac,
     36   No, it's not because we're using VT100 terminals while developing Trac,
    3837   rather because the diffs look nicer on short lines, especially in side-by-side mode.
    3938 * ''Never'' use multiple statements on the same line, e.g. `if check: a = 0`.
     
    4140 * Use `raise TracError("message")` instead of `raise TracError, "message"`
    4241 * Only use a `global` declaration in a function if that function actually modifies a global variable.
    43  * A little difference from PEP:0257: we usually don't ''insert a blank line between the last paragraph in a multi-line docstring and its closing quotes''.
     42 * A little deviation from PEP:0257: we usually don't ''insert a blank line between the last paragraph in a multi-line docstring and its closing quotes''.
    4443 * docstrings should contain reStructuredText markup, as understood by [http://sphinx.pocoo.org Sphinx], as we're using the latter for generating our ApiDocs.  \\
    4544   In some situations however, like for documenting Macros and Options, WikiFormatting
     
    4847   macros, respectively.
    4948 * Prefer tuples without parenthesis, particularly in `return` and `yield` statements. When parenthesis are needed for line continuation they can be used rather than a backslash on the continuation line.
     49 * Code blocks are copiously documented, describing the code blocks' functionality concisely.
    5050
    51 == JavaScript ==
     51== JavaScript
     52
    5253!JavaScript code should follow [http://javascript.crockford.com/code.html these conventions] with the following exceptions and additions:
    5354* Lines shouldn't exceed a length of 79 characters.
     
    5758* Define non-anonymous functions as `function fooBar() {...}` (rather than `var fooBar = function() {...}`)
    5859* Keep as much as possible private, by defining private functions in an inner scope. Attach functions you want to export to the $ symbol.
    59 * Use a `trac-` prefix for all id and class names. (For new names. Changing old names would break customizations.)
     60* Use a `trac-` prefix for all id and class names. This is for new names, because changing old names would break customizations.
    6061* Prefix variables containing a jQuery object with `$`.
    6162