Difference between revisions of "Programming Guideline Checklist"

From Dreamwidth Notes
Jump to: navigation, search
(Created page with 'This is a quick checklist of the Dev Programming Guidelines page; go there for details. == Code Formatting == * Check for whitespace: ** Four spaces for indentation. No ta...')
 
 
(3 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
* Check for whitespace:
 
* Check for whitespace:
** Four spaces for indentation.  No tabs.
+
** Four spaces for indentation.  No tabs. (Easy check: <tt>cat -et</tt> command.)
 
** No trailing whitespace.
 
** No trailing whitespace.
 
** Spaces around parenthesis and operators.  A space between if and the starting parens, spaces between method arg parens, etc.  Do not use spaces around hash indexes, however.
 
** Spaces around parenthesis and operators.  A space between if and the starting parens, spaces between method arg parens, etc.  Do not use spaces around hash indexes, however.
Line 11: Line 11:
 
* Use postfix conditionals -- ie, <tt>do_something() if $something;</tt>
 
* Use postfix conditionals -- ie, <tt>do_something() if $something;</tt>
 
* Use human logic -- unless instead of if not.
 
* Use human logic -- unless instead of if not.
 +
* Favor list assignment for local variables over multiple calls to shift.
 
* Don't quote hash literals -- <tt>$HASH{DATA}</tt>, not <tt>$HASH{'DATA'}</tt>
 
* Don't quote hash literals -- <tt>$HASH{DATA}</tt>, not <tt>$HASH{'DATA'}</tt>
 
* Commenting: have you commented appropriately?
 
* Commenting: have you commented appropriately?
 +
* Use Carp's croak/confess and die for error reporting
  
 
== DW Code Specific Conventions ==
 
== DW Code Specific Conventions ==
  
* Use <tt>LJ::HOME</tt> over $ENV{LJHOME}
+
* Use <tt>$LJ::HOME</tt> over $ENV{LJHOME}
 
* Use <tt>LJ::is_enabled()</tt> over $LJ::DISABLED
 
* Use <tt>LJ::is_enabled()</tt> over $LJ::DISABLED
 
* Use <tt>$u->get_cap</tt> over <tt>LJ::get_cap($u, ...)</tt> (or add an accessor in <tt>LJ::User</tt>)
 
* Use <tt>$u->get_cap</tt> over <tt>LJ::get_cap($u, ...)</tt> (or add an accessor in <tt>LJ::User</tt>)

Latest revision as of 19:01, 11 July 2013

This is a quick checklist of the Dev Programming Guidelines page; go there for details.

Code Formatting

  • Check for whitespace:
    • Four spaces for indentation. No tabs. (Easy check: cat -et command.)
    • No trailing whitespace.
    • Spaces around parenthesis and operators. A space between if and the starting parens, spaces between method arg parens, etc. Do not use spaces around hash indexes, however.
    • Suggested line break length at 120 characters.
  • Do not use extraneous parentheses, including on methods that don't need it or on postfix conditionals.
  • Use postfix conditionals -- ie, do_something() if $something;
  • Use human logic -- unless instead of if not.
  • Favor list assignment for local variables over multiple calls to shift.
  • Don't quote hash literals -- $HASH{DATA}, not $HASH{'DATA'}
  • Commenting: have you commented appropriately?
  • Use Carp's croak/confess and die for error reporting

DW Code Specific Conventions

  • Use $LJ::HOME over $ENV{LJHOME}
  • Use LJ::is_enabled() over $LJ::DISABLED
  • Use $u->get_cap over LJ::get_cap($u, ...) (or add an accessor in LJ::User)
  • English stripping is required for pages!
  • New files need appropriate header/credit