This is for C-like languages including Java, JavaScript, Perl,
PHP, Ruby, etc.
- Use a programmer's editor that does automatic formatting,
e.g.,
emacs.
- Keep all lines less than 78 characters long. (If you absolutely
need to have a long line, consider putting a blank line above and
below it, to make it easier to read.)
- Use two spaces for indentation level. (Wider indents would
make more lines wrap.)
- Make all inline comments start in the same column when possible.
I.e., in emacs try M-; to run indent-for-comment.
- Use a 65-dash comment to separate sections, e.g., for Perl:
# -----------------------------------------------------------------
# subroutines:
- Most subroutines should be less than about 50 lines of code.
- Usually put a space before any open parens, and after every comma and
semi-colon, and on either side of built-in operators like the = sign.
- Do not put two statements on one line.
- Open brace at end of line like this:
if condition {
action();
}
- Always follow an if/for/while clause with {} to wrap the actions,
even if there is only one statement as the action.
See Also
|