    <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  :: The Journey - from accu.general May 1999</title>
        <link>https://members.accu.org/index.php/articles/919</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">Design of applications and programs + CVu Journal Vol 11, #5 - Aug 1999</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/c67/">Design</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/c130/">115</a>
<br />

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

                    -                        <a href="https://members.accu.org/index.php/articles/c67+130/">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;The Journey - from accu.general May 1999</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 August 1999 13:15:33 +01:00 or Tue, 03 August 1999 13:15:33 +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="d0e18" id="d0e18"></a></h2>
</div>
<p class="c2"><span class="remark">Recently on <tt class=
"literal">accu-general</tt>, I expressed a desire to contribute to
the journals of the society. The support I got was superb, so how
could I let these people down? One suggestion (from Lois
Goldthwaite) was to condense interesting posts to the news lists
into an article (as used to be done for the column &quot;Caught in the
Net&quot; by Jim Bartholomew). So here is my first attempt. Let me know
how it goes&hellip;</span></p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e26" id="d0e26"></a>Comments in
Code</h2>
</div>
<p class="c2"><span class="remark">By far the busiest thread of the
month, the origins of this one are deep inside that Medusa thread -
'I was thinking' which covered; inheritance hierarchies, interview
techniques, the design rationale of <tt class=
"classname">std::string</tt>, the software engineering lifecycle,
abstract base classes and commenting habits. Although comments had
been raised already, the thread was really born from the following
quote:</span></p>
<div class="variablelist">
<dl>
<dt><span class="term">[Kevlin Henney]</span></dt>
<dd>
<p>Who says that code with &quot;nice comments&quot; is necessarily good
engineering practice?</p>
<p>Kernighan &amp; Pike (in their new book, The Practice of
Programming) repeat what I consider to be closer to standard
software engineering wisdom on this topic, and most of their
recommendations are about removing rather than adding comments.</p>
</dd>
<dt><span class="term">[Burkhard Kloss]</span></dt>
<dd>
<p>We may be opening a can of worms here - but I'd think the key is
to express in code what can be expressed in code, and put into
comments what adds value. Let the code express the what, and the
comments explain the why.</p>
</dd>
<dt><span class="term">[Edward Collier]</span></dt>
<dd>
<p>I spend a good deal of my time working through code for which
the supporting documentation is either never-existent, incomplete
or missing presumed dead. And I regularly give thanks for those
persons whose programs contain meaningful, complete comments,
including the occasional plain text description of the purpose of
the code, or a pseudo-code PDL-type header block, or almost
anything except what I seem to get most of - single letter variable
names being far from the worst of it.</p>
</dd>
<dt><span class="term">[Nigel Armstrong]</span></dt>
<dd>
<p>What has not been mentioned at all is that there is a Third Way,
that of literate programming. In this approach the source code is
just another aspect of the system documentation, which can be
extracted and viewed in a multitude of ways, depending whether the
target 'user' is a human being, a compiler, a typesetter program or
whatever. This means that for example all the documentation which
applies to a particular class, including the source code, can be
readily viewed in a structured fashion - such as an HTML
document.</p>
</dd>
<dt><span class="term">[Adrian Fagg]</span></dt>
<dd>
<p>If you're suffering from single letter variable names and other
poorly thought out code, then the presence or absence of comments
can't be the primary issue. If an author chooses poor identifier
names and comments them 'nicely' then he could just as well choose
meaningful names in the first place. It is my (and others I hope)
contention that well factored code with well-chosen function and
variable names should generally need little commenting.</p>
<p>My own bad experiences of poorly commented code have all been
cases where there was lots of commenting. Usually, the code quality
has been poor and often the comments have ceased to match what's
there.</p>
</dd>
<dt><span class="term">[Kevlin Henney]</span></dt>
<dd>
<p>Say it in the programming language first, and if that does not
suffice add comments accordingly. Comments for their own sake lead
to verbosity, which rarely leads to clarity. When trying to define
function intent I am more likely to use pre and post conditions
than pseudocode, as pseudocode often ends up as simply the code
rehashed (+/- a few errors/distractions just to keep readers
amused).</p>
</dd>
<dt><span class="term">[Sean Corfield]</span></dt>
<dd>
<p>If a function is (a) well-named and (b) factored into readable
'chunks' (other, well-named functions), then an overview comment
should be almost unnecessary. I might put a one or two line comment
at the head of a non-obvious function (but I'll usually agonise
over ways to make the function and parameter names more obvious
instead).</p>
<p>As for an overview of the program, that's the job of the
requirements, analysis and design documentation.</p>
</dd>
<dt><span class="term">[James M Stern]</span></dt>
<dd>
<p>Comments that tell you what the code does are often useless.
Comments that express intent can be boons. &quot;Intent&quot; means what the
code is supposed to do, which may be only part of what it does.</p>
</dd>
<dt><span class="term">[David Watson]</span></dt>
<dd>
<p>On the other hand, just because you need to study the code in
any sort of depth doesn't make it bad code. It may be a complex
problem. It may be a clever solution; think of the first time you
were faced with something like quicksort - most people have to
think about that. (Neither is it easy to write succinct comments
for something like quicksort.)</p>
</dd>
</dl>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e96" id="d0e96"></a>Assert</h2>
</div>
<p class="c2"><span class="remark">This thread emerged from the
Comments in Code thread from the idea that pre- and post-conditions
capture much of the intent of a function. I found the conclusion of
the following thread surprising, and the strength of argument with
following support won me over pretty quickly.</span></p>
<div class="variablelist">
<dl>
<dt><span class="term">[Kevlin Henney]</span></dt>
<dd>
<p>What I have abandoned, though, is the use of assert to back up
the commented preconditions. I used to advocate assert, but changed
my mind about 4 years ago. I now tend to advocate the opposite:
leave it out!</p>
</dd>
<dt><span class="term">[Burkhad Kloss]</span></dt>
<dd>
<p>Now that is interesting - once you specify invariants, what is
wrong with checking them at runtime? I have often found that very
useful in tracking down problems, and often ones that I didn't
realise I had yet&#9786;</p>
</dd>
<dt><span class="term">[Kevlin Henney]</span></dt>
<dd>
<p>This was exactly my rationale, and works in support of the
commenting convention - I first described this combined in an
article c1991 &quot;Programming by Contract in ANSI C&quot;. It was something
I found useful on a number of projects.</p>
<p>However, one of the problems is the way in which <tt class=
"function">assert</tt> is often misused: as with anything,
disciplined use of it enhances a system, and non-disciplined use
undermines it - just as inheritance can be both used to increase or
decrease dependencies in a system. But there is more to cautioning
against something simply because it can be misused, otherwise we'd
have to institute a prohibition on even thinking about - let alone
using - C/C++!</p>
<p>Anyway, misuse of <tt class="function">assert</tt> includes
using it to assert on environmental factors (e.g. memory
allocation, file existence, etc.), invoking it with a side effect
based expression (e.g. initial assignment of a pointer), and also
using a pointer argument (<tt class="function">assert</tt> is
intended to take an <tt class="type">int</tt>, not a pointer). An
example that illustrates all three:</p>
<pre class="programlisting">
FILE *fp;
assert(fp = fopen(name, mode));
</pre>
<p>In spite of a reasonable amount of education and guidelines, I
found this and other examples in a few systems. Some of the misuses
were quite creative and I must confess surprised me: I had such a
narrow view of what was sensible use of <tt class=
"function">assert</tt> that I never realised to what extent it
could be abused!</p>
<p>It gets misused to the point that people are afraid to turn off
<tt class="literal">NDEBUG</tt> in the release version for fear of
breaking the system! Here we have a case that the tables are
turned: <tt class="function">assert</tt> has become a major
liability. And how did it become so? Misunder-standing and
miss-education. This is no slight on the authors, but there are
some very experienced people whose recommendations represent
classic misuses of this feature.</p>
<p>In short, most uses of <tt class="function">assert</tt> found in
systems are inappropriate, and leave Sturgeon's Law far behind in
the rear view mirror. Surprisingly - now that I have long since
been disabused of my na&iuml;vet&eacute; - for just a single
feature, <tt class="function">assert</tt> is remarkably hard to use
correctly and consistently.</p>
<p>If I could be sure that <tt class="function">assert</tt> were
used only as a correctness tool and was guaranteed not to be a
liability, I would go back to recommending it for mixed teams.
Otherwise, given a limited amount of time and effort, I prefer to
concentrate on ensuring the understanding of other (commonly
misused) constraint concepts in the language: types, const,
inheritance, polymorphism, scope, etc.</p>
</dd>
<dt><span class="term">[Alan Griffiths]</span></dt>
<dd>
<p>Strange coincidence, I gave up <tt class="function">assert</tt>
about the same time as Kevlin. My reasons:</p>
<p>Proving some code is valid involves more than demonstrating that
a (usually limited) set of test cases fail to execute an error
trap.</p>
<p>Since the limits of what one can efficiently test are limited
(e.g. there are many &quot;invalid pointer&quot; values other than 0) such
tests lead to a false sense of security.</p>
<p>The code in the development build should be the same as that in
the release build (that is the one that has to work)! <tt class=
"function">assert</tt> defeats this.</p>
<p>There is an industry shortage of developers that use it
correctly (checking preconditions/invariants) - too often I've seen
horrors like:</p>
<pre class="programlisting">
assert(file = fopen(&quot;plover&quot;));
</pre></dd>
<dt><span class="term">[Adrian Fagg]</span></dt>
<dd>
<p>A interview question that I used to ask was:</p>
<p>What's wrong with the following code fragment?</p>
<pre class="programlisting">
int *pInt = 0;
assert( pInt = new int[100] );
pInt[0] = 0;
</pre>
<p>To which an alarming number of candidates said 'nothing'.</p>
</dd>
</dl>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
