    <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  :: Francis' Scribbles</title>
        <link>https://members.accu.org/index.php/journals/824</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>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">CVu Journal Vol 17, #4 - Aug 2005 + Francis' Scribbles from CVu journal</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/journals/">All</a>

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

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

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c95/">174</a>
                    (12)
<br />

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

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c181/">Francis' Scribbles</a>
                    (29)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c95-181/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c95+181/">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;Francis' Scribbles</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 05 August 2005 05:00:00 +01:00 or Fri, 05 August 2005 05:00:00 +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="d0e26" id="d0e26"></a>SESE or
SEME</h2>
</div>
<p>Several very competent programmers have been debating the
relative merits of the requirement for a 'Single Entry, Single
Exit' coding style. This debate is on <tt class=
"literal">comp.lang.c++.moderated</tt>. Andrei Alexandrescu's
passionate defence of SEME (single entry, multiple exits) has led
to the debate being more than just the 'lazy' versus the
'experts'.</p>
<p>You should note that SESE is not just about functions having
only one return statement; it is about there being only one exit
from any structure.</p>
<p>Part of Andrei's case is that the existence of exceptions in C++
(and C#, Java etc.) means that code often has potential for an
alternative exit and the programmer needs to be aware of that and
handle it.</p>
<p>Some of you may remember that I have never been an advocate of
making SESE an absolute requirement for good code. I also place
relatively little value on the arguments from SESE proponents that
their code is easier to read. Ease of reading is partly governed by
familiarity with the writing style.</p>
<p>Now from my perspective, the primary question is how to get more
people writing good code. Here are some thoughts on the topic.</p>
<p>The best is the enemy of good. My observation is that when we
present novices with SESE as an absolute, they write very poor
code. In a strict sense, their code is SESE compliant but they
achieve this with contortions. This bares a similarity to what
happens when you tell novice writers that they must not use the
passive voice.</p>
<p>There is a wide gap between the excellent programmer and the
good one. Adopting methods that make more programmers into good
ones without trying to turn them immediately into excellent ones,
IMO, is more beneficial in the long term. (Note that I avoided the
split infinitive, but did that avoidance help you understand the
sentence?)</p>
<p>Now, I freely admit to being less than a devotee of SESE.
However, I do have certain personal guidelines:</p>
<div class="orderedlist">
<ol type="1">
<li>
<p>Loops have one exit point. This maybe internal, in which case
the loop is written as <tt class="literal">while(true){ }</tt></p>
</li>
<li>
<p>A loop-iteration may terminate early (for example, with
<tt class="literal">continue</tt>) but only once in the body of a
loop. Actually I very rarely if ever use <tt class=
"literal">continue</tt>.</p>
</li>
<li>
<p>All exits from a <tt class="literal">switch</tt> must be to the
same place (either all <tt class="literal">break</tt>s or all
<tt class="literal">return</tt>s)</p>
</li>
<li>
<p>If a function contains more than a single <tt class=
"literal">return</tt> statement, re-view its structure to see if it
can be written more cleanly with only a single return.</p>
</li>
<li>
<p>Be wary of negative tests, human beings do not handle these
well.</p>
</li>
<li>
<p>Nested structures can usually be replaced by function calls. I
make a great deal of use of the unnamed namespace for such
functions.</p>
</li>
</ol>
</div>
<p>I find application of these guidelines leads to most of my code
being single exit, but I think that is a consequence not a
target.</p>
<p>The fact that good code usually has single exits points from
structures does not, in my opinion, mean that we should teach
programmers that SESE is an end in itself. What we should be doing
is teaching them coding methods that naturally lead to code that
usually has only one exit point.</p>
<p>What I would value, by way of feedback, is more guidelines that
help the less experienced programmer write simpler code. So what do
you have to offer?</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e93" id="d0e93"></a>Recommended
Books</h2>
</div>
<p>Some time ago, I suggested that we should attempt to produce
single topic lists of recommended books. For example, a list of
useful books for an experienced C++ (C, Java, C# etc.) or a list
for those writing for embedded systems. So far, I have had a single
volunteer (to contribute a list for an aspect of Python).</p>
<p>I think we can do much better than that. I think we should do
much better than that. Software developers do not have time to
waste on reading bad or mediocre books. However, they do not have
time to invent everything from scratch. They need good references
and tutorials and they need help selecting relevant books.</p>
<p>Like the parable of the Stone Soup, if each contributes a little
bit we eventually have something worthwhile. I have neither the
expertise nor that time to sit and create lists. Nor do most of
you, But each of us has time to draw up a list of books for what we
are experts in and then get others to review and refine it.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e102" id="d0e102"></a>Problem
21</h2>
</div>
<p>Consider:</p>
<pre class="programlisting">
class x;
class xyz {
public:
  xyz();
  ~xyz();
  static int const elements(100);
// rest of interface
private:
  x * pointers[elements];
};

xyz::xyz(){
  for(int i(0); i != elements; ++i){
    pointers[i] = 0;
  }
}
  
xyz::xyz(){
  for(int i(0); i != elements; ++i){
    delete pointers[i];
  }
}
</pre>
<p>Is there a better way to implement the constructor? Of course
there is, and I know some of you know it but do you?</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e111" id="d0e111"></a>Commentary on
Problem 20</h2>
</div>
<p>Here is a miniscule program. Now I think it is clear what the
programmer intended but what do you think a conforming compiler
will do with it and why? How should the author have written the
definition of <tt class="varname">p</tt>?</p>
<pre class="programlisting">
 struct data {
    int i;
    int j;
 };
 int main() {
    data** p = new (data*)[5];
 }
</pre>
<p>It seems that the writer wants an array of five pointers to
<span class="structname">data</span>. That looks a little unusual
so the first question I would ask is 'Why do you want an array of
pointers? Perhaps he is intending to create a two dimensional array
of <span class="structname">data</span>.</p>
<p>It is easy to answer the immediate question; remove the
parentheses surrounding <tt class="type">data*</tt>.</p>
<p>The reason I asked the question was that I suspected (correctly
as it happens) that most (nine out of the eleven) respondents would
simply answer the syntax question. That is the easy way to respond
to requests for help and many people asking questions like such
simple answers, but it does not help them in the end.</p>
<p>By the way, in my opinion, the programmer should either be
declaring an array (if the correct size will be fixed and known at
compile time) or be using a <tt class="literal">std::vector&lt;data
*&gt;</tt>. I am always deeply suspicious of uses of <tt class=
"literal">new[]</tt> outside low-level classes.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e144" id="d0e144"></a>Cryptic Clues
for Numbers</h2>
</div>
<p>Twice lucky? Thrice lucky? About when China ruled the seas.</p>
<p>Here is Mick Brooks' clue for 1421:</p>
<div class="blockquote">
<blockquote class="blockquote">
<p>The ultimate answer (read between the lines) is the last
Lancastrian's birthday.</p>
</blockquote>
</div>
<p>By the way, if you have not already come across it 1421 (ISBN
0-553-81522-9) is a fascinating read. I wish I had time to try to
untangle wild speculation from the underlying reality. This book
should probably be treated as a historical novel. However, like all
such novels, it is hard to separate truth from fiction.</p>
<p>Here is another little clue to exercise your grey cells (A
knowledge of classic SF might help).</p>
<p><span class="emphasis"><em>The reverse of this issue adds a
score to burning books. (3 digits)</em></span></p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
