<?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/vms-ports/wiki/CodingStandards/</link><description>Recent changes to CodingStandards</description><atom:link href="https://sourceforge.net/p/vms-ports/wiki/CodingStandards/feed" rel="self"/><language>en</language><lastBuildDate>Sat, 05 Jan 2013 18:11:30 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/vms-ports/wiki/CodingStandards/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage CodingStandards modified by John Malmberg</title><link>https://sourceforge.net/p/vms-ports/wiki/CodingStandards/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="coding-standards"&gt;Coding Standards&lt;/h1&gt;
&lt;p&gt;There are actually many coding standards that different projects use.&lt;/p&gt;
&lt;p&gt;When making updates to a project being ported, you need to follow the standards that are in use for that project for those modules.&lt;/p&gt;
&lt;p&gt;For new modules, it may not be obvious what coding standard to use.&lt;/p&gt;
&lt;p&gt;In general though, the following guidelines are universal:&lt;/p&gt;
&lt;h2 id="almost-universally-banned"&gt;Almost universally banned&lt;/h2&gt;
&lt;p&gt;These almost always show up in coding standards as examples of what to never do.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Spaces after an open parenthesis&lt;/li&gt;
&lt;li&gt;Spaces before a closing parenthesis&lt;/li&gt;
&lt;li&gt;No space before or after a binary mathematical operator.&lt;/li&gt;
&lt;li&gt;No space before an opening parenthesis for a conditional clause.&lt;/li&gt;
&lt;li&gt;No space before a punctuation operator like a comma or period.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="line-width"&gt;Line width&lt;/h2&gt;
&lt;p&gt;80 column maximum, actually about 79 characters may be preferred as a guideline.  Most GUI based editors allow setting an indicator of where that line is.&lt;/p&gt;
&lt;p&gt;An 80 column output can be read on most terminals, and the compiler listings from that will fit properly on terminals and printers in 132 character mode.&lt;/p&gt;
&lt;p&gt;If you notice, newspapers tend to run narrow columns as they have found it is easier for people to read.  (At least that is what I was told in elementary school), so keeping your lines short is preferred.&lt;/p&gt;
&lt;p&gt;You can use temporary variables and refactor in to local subroutines to help keep lines shorter.&lt;/p&gt;
&lt;h2 id="tabs"&gt;Tabs&lt;/h2&gt;
&lt;p&gt;Most projects are now banning hard coded tabs in text files because of the mess described below.&lt;/p&gt;
&lt;p&gt;Actual TAB characters in code should only be used where the tab stops are on 8 character boundaries.&lt;/p&gt;
&lt;p&gt;100 % of all terminals and printers commonly used by programmers, and most output formatting tools assume that Tabs are on 8 character boundaries, so when you use the TABs for 4 characters, your files look strange to everyone else that is not using your particular editor or IDE.&lt;/p&gt;
&lt;p&gt;Unfortunately many of the early editor and IDE developers do not understand this basic fact have set the defaults to be 4 character TAB for GUI based environments.  So you need to check before you save or publish code.  Most of these environments now have features to convert TABs to equivalent spaces as one of their options.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Python&lt;/strong&gt; also assumes that TABS are on 8 character boundaries.&lt;/p&gt;
&lt;p&gt;My personal preference is to use TABS on 8 character boundaries as I can move the cursor\ faster in the VMS EVE editor as I move across a line.&lt;/p&gt;
&lt;h2 id="white-space-usage"&gt;White space usage&lt;/h2&gt;
&lt;p&gt;The common convention is that white space should be between binary operators and not for unary operators.&lt;/p&gt;
&lt;h2 id="indenting"&gt;Indenting&lt;/h2&gt;
&lt;p&gt;Indenting is now usually 4 characters with older conventions of 2 and 3 characters.  If you see something larger than 4 characters it usually means that someone was using TABS set to 4 characters.&lt;/p&gt;
&lt;p&gt;For DCL, I usually indent 3 characters from the leading $ on the line for the first indent&lt;br /&gt;
and then use 4 characters for each indent after, which allows TAB characters to be used.&lt;/p&gt;
&lt;p&gt;On DCL there are two common conventions, no space after the initial $, or one space after&lt;br /&gt;
the initial $.  I tend to prefer the no space.&lt;/p&gt;
&lt;h2 id="block-delimiters"&gt;Block Delimiters&lt;/h2&gt;
&lt;p&gt;For languages that take braces or other block delimiting tokens like &lt;strong&gt;C/C++/Perl&lt;/strong&gt; the current convention for most new projects is that the opening delimiting token be on the same line as any code that references the block, and the closing delimiter be at the same&lt;br /&gt;
indentation as the statement where the block begins.&lt;/p&gt;
&lt;p&gt;This compacts the code down so that more fits on a page.&lt;/p&gt;
&lt;p&gt;That is per this example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xx&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Older conventions are to have the opening delimiter directly below and may have the&lt;br /&gt;
block delimiters with no indentation with respect to the block, or have the block delimiters that with either partial or full indentation.&lt;/p&gt;
&lt;h2 id="function-declarations"&gt;Function declarations&lt;/h2&gt;
&lt;p&gt;For languages like C, there is a convention on some projects to have the return type and any qualifiers on a different line.&lt;/p&gt;
&lt;p&gt;There is also a convention in declarations to put a space between the function name and the opening parenthesis, but not to put the space in where the routine is called.  This is to make it so that searches for &lt;strong&gt;foo(&lt;/strong&gt; find where a routine is called and searches for &lt;strong&gt;foo (&lt;/strong&gt; find where it is defined.&lt;/p&gt;
&lt;h2 id="trailing-spaces"&gt;Trailing spaces&lt;/h2&gt;
&lt;p&gt;You may need to set your editor to not trim trailing spaces.  This can cause unwanted white space changes in patches submitted.&lt;/p&gt;
&lt;h2 id="line-endings"&gt;Line endings&lt;/h2&gt;
&lt;p&gt;Most open source projects want line endings that are equivalent to stream LF.  The GNV gnu diff utility will translate this properly for patches.&lt;/p&gt;
&lt;p&gt;Diff will complain if your last line does not have a line terminator.&lt;/p&gt;
&lt;p&gt;TODO:  Add links to common coding standards.&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://sourceforge.net/p/vms-ports/wiki/CodeDevelopment/"&gt;Code Development&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">John Malmberg</dc:creator><pubDate>Sat, 05 Jan 2013 18:11:30 -0000</pubDate><guid>https://sourceforge.netd28e145f6176bae51c8795765acd4dfff82cfd98</guid></item></channel></rss>