-
Notifications
You must be signed in to change notification settings - Fork 7
/
coding-standards.html
45 lines (42 loc) · 1.9 KB
/
coding-standards.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
title: Coding Standards
layout: default
---
<ul>
<li>Generally, <a href="http://pear.php.net/manual/en/standards.php">PEAR standards</a>.</li>
<li>Indentation: tabs, not spaces.</li>
<li>Wrap at 100 columns, unless the result would be confusing.</li>
<li>Variable names in lowercase (e.g., <code>$section_number</code>), multiple words separated with underscores, never camelCase or StudlyCaps.</li>
<li>Generally, give everything space to breathe. Whitespace is free.</li>
<li>Braces on a new line:
<pre><code>if ($x == $y)
{
...
}</code></pre></li>
<li>Save for very terse (>~5 lines?) clauses, use an extra carriage return after an opening brace and before a closing brace:
<pre><code>while ($reference = $statement->fetch(PDO::FETCH_OBJ))
{
$reference->catch_line = stripslashes($reference->catch_line);
$reference->url = 'http://' . $_SERVER['SERVER_NAME']
. ( ($_SERVER['SERVER_PORT'] == 80) ? '' : ':' . $_SERVER['SERVER_PORT'] )
. '/' . $reference->section_number . '/';
$references->$i = $reference;
$i++;
}</code></pre></li>
<li>Don't use the ternary operator (<code>($size > 2) ? 'small' : 'large'</code>).</li>
<li>The results of conditionals should always go within braces, rather than expressed on a single line, e.g.:
<pre><code>if ($a == TRUE)
{
echo 'true';
}</code></pre></li>
<li>Spaces before conditionals (<code>if ($a == TRUE)</code>, not <code>if($a == TRUE)</code>)</li>
<li>Boolean terms in all caps (e.g., <code>TRUE</code>).</li>
<li>Comments as complete sentences, offset like such:
<pre><code>/*
* Example comment here.
*/</pre></code></li>
<li>Comments preceded with <code>//</code> indicate temporary, working comments, generally indicating problems.</li>
<li>If a bit of code is anything short of perfectly obvious, provide a comment explaining it.</li>
<li>Use <code>echo</code>, not <code>print</code>.</li>
<li>HTML 5, meaning self-terminating tags (e.g., <code><br /></code></li>
</ul>