Web Development Conventions

The following list of conventions is simply a codification of what I do when I do web development. I’m not necessarily endorsing any of this, just writing it down. If you wanted to do web development in a way that might fool me into thinking I’d done it myself, here are some guidelines:

Apache/Unix

  • AllowOverride All is used to allow maximum control from .htaccess
  • Writable directories have 755 permissions

MySQL

  • Table names are singular nouns
  • Primary keys are always “id”, auto-incrementing
  • Date and time keys are named for the event being recorded, e.g. “added”, “approved”

PHP

  • Variable, class, and function names are all lowercase, underscore_separated
  • Constant names are all uppercase
  • Excepting cron jobs, .php extensions are never used in URLs; everything is a directory
  • Class names are singular nouns
  • All logic-based includes go in /include/ directory
  • All template-based includes go in /template/
  • Class definition file names end in .class.php
  • All non-class include file names end in .inc.php
  • Trailing white space is deleted (e.g. auto-indent tabs on blank lines)
  • Function calls and definitions have no space before the parenthesis; language constructs, e.g. if, while, always have a space.

HTML

  • Character encoding is always UTF-8
  • Tag names are all lowercase
  • Attribute names are all lowercase
  • Attribute values are always surrounded by double quotes
  • No inline JavaScript or style declarations
  • JavaScript and CSS includes go in the head, never in the body
  • Tags describe content, as specifically as possible, but never misleading
  • Class names are used liberally to add specificity to content description
  • Contained tags are tab-indented from the container
  • No HTML comments; markup alone is sufficiently descriptive
  • br is only used where line breaks are more content than style, e.g. poetry

JavaScript

  • Most recent version of jQuery is used as base for all JavaScript
  • Variable and function names use camelCase
  • All block ends include a comment indicating what just ended, e.g. } // if
  • All JavaScript files go in /js/ directory
  • Trailing white space is deleted (e.g. auto-indent tabs on blank lines)

CSS

  • Eric Meyer’s reset.css provides standard base for all other stylesheets
  • ID and class names are all lowercase, dash-separated
  • Blocks are indented under the selector, e.g.:
    p {
    	color: #000;
    	}
  • Sub-selectors are indented below parent selector, e.g. tr.odd and td both go under tr.
  • Colors are always identified by hex codes
  • All CSS files go in /css/ directory
  • Trailing white space is deleted (e.g. auto-indent tabs on blank lines)

Bad Behavior has blocked 892 access attempts in the last 7 days.