<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to CodingStandards</title><link>https://sourceforge.net/p/nocc/wiki/CodingStandards/</link><description>Recent changes to CodingStandards</description><atom:link href="https://sourceforge.net/p/nocc/wiki/CodingStandards/feed" rel="self"/><language>en</language><lastBuildDate>Thu, 11 Jul 2013 08:11:56 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/nocc/wiki/CodingStandards/feed" rel="self" type="application/rss+xml"/><item><title>CodingStandards modified by Tim Gerundt</title><link>https://sourceforge.net/p/nocc/wiki/CodingStandards/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="nocc-coding-standards"&gt;NOCC Coding Standards&lt;/h1&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#nocc-coding-standards"&gt;NOCC Coding Standards&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#indenting-and-line-length"&gt;Indenting and Line Length&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#control-structures"&gt;Control Structures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#function-calls"&gt;Function Calls&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#php-code-tags"&gt;PHP Code Tags&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#naming-conventions"&gt;Naming Conventions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;Most of the coding standards have been taken from the &lt;a class="" href="http://pear.php.net/manual/en/standards.php" rel="nofollow"&gt;PEAR Coding Standards&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="indenting-and-line-length"&gt;Indenting and Line Length&lt;/h2&gt;
&lt;p&gt;Use an indent of 4 spaces, with no tabs.&lt;/p&gt;
&lt;h2 id="control-structures"&gt;Control Structures&lt;/h2&gt;
&lt;p&gt;These include if, for, while, switch, etc. Here is an example if statement, since it is the most complicated of them:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;condition1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;action1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;elseif&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;condition3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition4&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;action2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;defaultaction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls.&lt;/p&gt;
&lt;p&gt;You are strongly encouraged to always use curly braces even in situations where they are technically optional. Having them increases readability and decreases the likelihood of logic errors being introduced when new lines are added.&lt;/p&gt;
&lt;p&gt;For switch statements:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="nx"&gt;action1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="nx"&gt;action2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="nx"&gt;defaultaction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="function-calls"&gt;Function Calls&lt;/h2&gt;
&lt;p&gt;Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; spaces between commas and each parameter, and no space between the last parameter, the closing parenthesis, and the semicolon. Here's an example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$bar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$baz&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$quux&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="php-code-tags"&gt;PHP Code Tags&lt;/h2&gt;
&lt;p&gt;Always use &amp;lt;?php ?&amp;gt; to delimit PHP code, not the &amp;lt;? ?&amp;gt; shorthand.&lt;/p&gt;
&lt;h2 id="naming-conventions"&gt;Naming Conventions&lt;/h2&gt;
&lt;p&gt;...&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tim Gerundt</dc:creator><pubDate>Thu, 11 Jul 2013 08:11:56 -0000</pubDate><guid>https://sourceforge.netf898b5e02db97c9769a0a1f9bc37b6c03d411c22</guid></item></channel></rss>