Administrative Computing Developer Resources
 
S A P Development Standards Web Development Standards Quality Assurance Glossary    

Rule #1: Follow a few, basic code formatting rules.

The most important words in this concept are few and basic. The presentation layer of your program includes at least HTML, CSS, JavaScript, and one server-side scripting language (JSP, BusinessHTML). Because of the simplicity of these rules, they can be applied uniformly to all of these eventualities despite the differences in purpose, construction, and syntax. Don't worry about exceptions, they will provide for themselves.

Cross-Platform and Code Editor Compatibility

Two-character soft indents. Spacebar characters should be used to indent code instead of tab characters. Each level of nesting is indented two character spaces.

Unix style line breaks. Even if the web server lives on Windows. Even if every developer is on a Mac. Etc.

Formatting Script

For any scripting language, line-break between a procedure name and the rest of the script, and line break between every statement in a statement block. Conditionals (if/else, while) that result in a single statement don't need a line break between the conditional and that result. For conditionals that result in a multi-line statement block, break between the conditional and the first statement. Don't forget to indent.

For C-style punctuated scripting languages, always use punctuation like parentheses, semi-colons, and brackets even when they are optional. Line-break between the procedure name and the opening bracket. For every bracketed block, the end bracket occurs on it's own line, vertically parallel with the open bracket.

Here's a simple JavaScript pseudo-function:

function MyScript( IntArgOne, StrArgTwo )
{
  if (condition)
  {
    IntArgOne.toString();
    return IntArgOne + StrArgTwo; // multiple statement block
  }
  else { return; } // single statement
}

Formatting Markup

The rules for markup are similar to those for script. Here's some simple pseudo-HTML:

<form id="FormOne">
  <table>
    <tr>
      <td><input id="InputOne" /></td>
      <td>
        <input id="InputTwo" />
        <input id="InputThree" />
      </td>
    </tr>
    <tr><td><input id="InputFour" /></td></tr>
  </table>
</form>

An HTML element is indented two-spaces in from it's container on the next line. For elements that only contain one element inside them, you can put everything on one line.

M I T
I S and T

© Copyright 2002 by the Massachusetts Institute of Technology, Cambridge, MA, USA.
View the full Copyright Notice and Disclaimer.