ChatZilla Coding Guidelines

There are a few rules to follow when making a patch for ChatZilla. Some of them are dead simple, others might not be. If you're fuzzy on a particular rule, check for examples in the source, or just ask. Hopefully the rules won't scare off potential patch makers. They may be a bit pedantic, but they help keep things consistent.

  1. No hard tabs. 4 spaces per tab.
  2. No lines longer than 80 columns. No breaking a line in the middle of an object dereference or before the first parameter to a function call. Exceptions allowed only under extreme situations.
             1         2         3         4         5         6         7         8
    12345678901234567890123456789012345678901234567890123456789012345678901234567890
    
    CORRECT:
        if (someObject.propertyWithALongName && reallyLongFunctionName() &&
            someOtherFlag)
        {
            const nsISample = Components.interfaces.nsISample;
            const CTRID_SAMPLE = "@mozilla.org/sample";
            var sample = Components.classes[CTRID_SAMPLE].createInstance(nsISample);
        }
    
    INCORRECT:
        if (someObject.propertyWithALongName && reallyLongFunctionName() && someOtherFlag)
        {
            var sample = Components.classes["@mozilla.org/sample"].createInstance(Components.interfaces.nsISample);
            var sample = Components.classes["@mozilla.org/sample"].
                createInstance(Components.interfaces.nsISample);
            var sample = Components.classes["@mozilla.org/sample"].createInstance(
                Components.interfaces.nsISample);
        }
    
  3. Please stick with the ChatZilla bracing style. Each brace on its own line. No braces on blocks with only a single statement, unless the clause itself takes up more than one line. Always include a newline for control clauses. For example...
    CORRECT:
    if (foo)
      bar();
    
    if (foo)
    {
      bar();
      baz();
    }
    
    while (foo && ... &&
           bar)
    {
      baz();
    }
    
    if (foo)
      bar();
    else if (baz)
      quux();
    
    if (foo)
    {
      bar();
    }
    else
    {
      baz();
      quux();
    }
    
    INCORRECT:
    if (foo) bar();
    
    if (foo) {
      bar();
      baz();
    }
    
    if (foo)
      bar()
    else
    {
      baz();
      quux();
    }
    
  4. Functions should have the opening brace on a new line.
  5. Include proper license and Emacs modeline in all new files. The preferred mode for JavaScript files is C++.
  6. Always use double quotes for strings. The only place where single quotes should appear are for single character strings (a la C), or in arguments passed to an event handler coded in HTML/XUL.
  7. Never use an else after a return. The return will take care of control flow, the else is redundant.
    CORRECT:
    if (a)
      return;
    
    b();
    
    INCORRECT:
    if (a)
      return;
    else
      b();
    

    Last modified: Mon Dec 2 17:48:43 PST 2002