    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Mostly Comments</title>
        <link>https://members.accu.org/index.php/articles/1012</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + CVu Journal Vol 12, #3 - May 2000</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c126/">123</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-126/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+126/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Mostly Comments</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 May 2000 13:15:36 +01:00 or Wed, 03 May 2000 13:15:36 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e23" id="d0e23"></a>Code file and
comment file?</h2>
</div>
<p>In his article Francis wrote, &quot;I personally hate comment that is
invasive of the code&quot;. In his next paragraph he added, &quot;While there
is a good case to be made for recording the development and
maintenance history of the source code somewhere I question whether
it is correct to place that in the same file&quot;. Francis is clearly
suggesting that the information describing the development and
maintenance history of the source code should go into a different
file. I have a lot of sympathy with this view. Often when you read
a source file the first thing you encounter is a mass of comments:
copyright notices, standard disclaimers and maintenance histories
to name but three. It gets in the way. It is invasive. No question.
But should you split these comments off into a separate comment
file? As always, there are conflicting forces. A separate comment
file would certainly make the code file more focused. And it would
also make the code file smaller. In some cases a lot smaller. That
could make compilation faster. That might be an issue. On the other
hand a separate comment file might be just too easy to mislay (I
have heard of source files being lost and developers being left
with just the object files.) Now you could place a <tt class=
"literal">#</tt> directive in the source file that included the
comment file. That might help, but only a little. Consider: You are
up against a rapidly approaching deadline, you fix the last bug,
the regression tests all pass, but aaargh, the comment file is
missing. What would you do? Be honest. You would comment out the
<tt class="literal">#include</tt>. In fact you would probably have
already done that so you could run the regression tests. On balance
I would not create a separate comment file.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e34" id="d0e34"></a>Not me. I just
want to code and go<sup>[<a name="d0e37" href="#ftn.d0e37" id=
"d0e37">2</a>]</sup></h2>
</div>
<p>The most important thing in a source file is the source code.
The source code is the reason the source file exists. If there were
no source code there would be no comments (and if there are no
comments there is no point arguing if they should live in their own
file.) There is a priority. Recognition of this priority suggests a
solution less radical than factoring out the comments into a
separate file. Simply place all the &quot;gumpf&quot; (to use a technical
term) at the end of the source file. After the code. Order the file
contents based on their priority.</p>
<pre class="programlisting">
// Copyright ACCU, 1997-2000. All rights reserved.
// Full copyright, disclaimer and maintenance-
// history at end of file
#include &lt;list&gt;
#include &quot;accu/graphic.hpp&quot;
#include &quot;accu/cloner.hpp&quot;

namespace accu {
  class compound : 
    public graphic, public cloner&lt;compound&gt;   {
  public:
      ...
  private:
    std::list&lt;cloning_ptr&lt;graphic&gt; &gt; graphics;
    };
}
// Example of use goes here

// Permission to use, copy, modify, distribute 
// this software and its documentation for any
// purpose is hereby granted without fee,
// provided that the above copyright notice
// appear in all copies,that both that copyright
// notice and this permission notice appear in
// supporting documentation, and no charge may
// be made for the software and its
// documentation except to cover cost of
// distribution.

// ACCU makes no representations about the
// suitability of this software for any purpose.
// It is provided &quot;as is&quot; without express or
// implied warranty. Blah blah blah

// Maintenance history goes here and usually
// rambles on for ages and ages
</pre></div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e44" id="d0e44"></a>Forward
comment</h2>
</div>
<p>I am not suggesting that you need to start the code immediately.
I think it is fine to start with a few comments. But only a few. In
fact a few is probably a good idea. After all, most programmers are
used to seeing reams and reams of comments at the top of source
files. You do not want to scare them too much. I particularly like
comment on the second line:</p>
<pre class="programlisting">
// Full copyright, disclaimer and maintenance-
// history at end of file
</pre>
<p>This is very reminiscent of a forward declaration.</p>
<pre class="programlisting">
struct body;
</pre>
<p>It tells us all we need to know, and nothing we do not need to
know. And there is more information supplied elsewhere if we want
to look. Incidentally, I have never been quite sure why a forward
declaration is called a forward declaration. It kind of suggests
there is such a thing as a backward declaration, which there isn't.
Why isn't it just called a declaration?</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e57" id="d0e57"></a>Need to know
ordering</h2>
</div>
<p>The idea of putting the code first and the comments last is very
reminiscent of the need-to-know ordering in a class
definition<sup>[<a name="d0e62" href="#ftn.d0e62" id=
"d0e62">3</a>]</sup>: <tt class="literal">public</tt> before
<tt class="literal">protected</tt> before <tt class=
"literal">private</tt>. Code before comments is just another
example.</p>
<p>I was thinking about this idea of a need-to-know ordering as I
mentally prepared this article. As I did so I realised a couple of
things. The first is that it does not apply just to access
specifiers. If I had a class that publicly derived from one class
and privately derived from another class, I would place the public
derivation first. The second is that there can be a need to know
ordering within declarations with the same access. For example,
consider this fragment:</p>
<pre class="programlisting">
namespace accu {
    class Francis {
      ...
    private: // data
      ...
    private: // prevention
      Francis(const Francis &amp;);
      Francis &amp; operator=(const Francis &amp;);
  };
}
</pre>
<p>This fragment implements the <tt class="classname">Francis</tt>
class. Now <tt class="classname">Francis</tt> has strong identity
(no argument there).</p>
<p>You cannot copy <tt class="classname">Francis</tt> (be grateful
for small mercies), and we have declared in code that you cannot
copy a <tt class="classname">Francis</tt>, since the copy
constructor and copy assignment operator are <tt class=
"literal">private</tt>. No problem. But compare the fragment
to:</p>
<pre class="programlisting">
namespace accu{
  class Francis {
    ...
  private: // prevention
      Francis(const Francis &amp;);
      Francis &amp; operator=(const Francis &amp;);
  private: // data
    ...
  };
}
</pre>
<p>The only difference is the ordering of the two sections that are
both <tt class="literal">private</tt>. In this fragment the
prevention is before the data. I strongly prefer this ordering.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e105" id="d0e105"></a>Comment
noise</h2>
</div>
<p>One more comment on comments.</p>
<pre class="programlisting">
/************************************
 * How do you make toast? 
 ************************************/

/*------------------------------*/
/* You burn bread and scrape the burn off!
/*------------------------------*/
</pre>
<p>I cannot stand all the noise around comments like these. Look
closely. The comments are the words. Just the words. All the rest,
all the stars and all the dashes contribute nothing. They are just
noise that the eye and mind has to discard. Get rid of them.</p>
<pre class="programlisting">
// How do you write software?
// You write code with bugs in it and then
// scrape the bugs off!
</pre>
<p>That is all for now</p>
<p>P.S. Now if only my editor would allow me to format the code
(with its included code-comments) in a monospace font and the
post-code gumpf-comments in a nice proportional font.</p>
</div>
<div class="footnotes"><br>
<hr class="c2" width="100">
<div class="footnote">
<p><sup>[<a name="ftn.d0e4" href="#d0e4" id="ftn.d0e4">1</a>]</sup>
Comments are mostly harmless but a bad comment is an
anti-comment.</p>
</div>
<div class="footnote">
<p><sup>[<a name="ftn.d0e37" href="#d0e37" id=
"ftn.d0e37">2</a>]</sup> Implement and test my code? Not me. I just
want to code and go. The Vidal Sassoon software engineering
manual.</p>
</div>
<div class="footnote">
<p><sup>[<a name="ftn.d0e62" href="#d0e62" id=
"ftn.d0e62">3</a>]</sup> I like this ordering a lot and it's very
common. Of course there are a few unenlightened souls who still
place the private data right after the opening brace. It saves
having to type in p-r-i-v-a-t-e. Hey, I know, let's bring back the
implicit int rule. That'll save some typing. While we're at it we
could drop the requirement that insists a function is declared
before it is called. That'll save a load of typing....</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
