    <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  :: In Defense of the Normal Programmer</title>
        <link>https://members.accu.org/index.php/articles/1068</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">CVu Journal Vol 12, #6 - Dec 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/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/c123/">126</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;In Defense of the Normal Programmer</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 December 2000 13:15:40 +00:00 or Sun, 03 December 2000 13:15:40 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
</div>
<p>It seems to be the season for change. I noticed in the last
edition of Overload that John Merrells has a new job, and I am sure
I recall other such departures for new challenges of late. Far be
it from me to shun the bandwagon, I too have been looking for a new
job, and my search for work furnished me with a couple of
surprises.</p>
<p>My first surprise was more of an epiphany; I found increasingly
that I was vetting prospective employers for suitability, rather
than the other way around. This issue was brought home to me hard
by one (very) senior C++ programmer who insisted that pure virtual
functions cannot have a function body. Luckily I was given the
opportunity to discuss my practical &quot;test&quot; with the interviewers,
which included the senior programmer. It raises the question of
what one should do when one has a better grasp of the language than
the senior technical interviewer.</p>
<p>But I digress. My second surprise was the number of employers
(including software houses, development divisions of large
corporations, and small development teams in larger companies) who
stated, quite categorically, that they do not use STL because it is
too complex for normal programmers.</p>
<p>The first time I heard this, I was astonished and disappointed.
My hard-earned skills in Standard Library techniques had been
wasted! It occurred to me, however, that if I am not a &quot;normal&quot;
programmer, what am I? (Please note - this is a rhetorical
question). I do not consider myself a superstar, or a dullard,
merely competent, and yet I am familiar with the C++ Standard
Library, and know how to make good use of much of it. I would not
say I know how to use all the STL functionality, but I am
comfortable with the concepts.</p>
<p>STL's detractors commonly point first to its syntax, which is
generally described as both contorted and verbose. I understand
that, at first glance, the STL does indeed appear complex and
unintuitive. I also recall that I found pointers in C to have
complex issues and an unintuitive notation. With a little diligence
and learning from mistakes, I became familiar with C pointers in
much the same way as I have with STL. In both cases, I had a
&quot;Eureka!&quot; moment when suddenly the clouds before me lifted
(revealing some nasty terrain ahead to be sure) and I understood -
even grokked - a good deal of the issues and solutions.</p>
<p>An example, I think.</p>
<p>Oooh - nasty. Yet, with some knowledge of STL, there are not
many things we cannot deduce from just this snippet of code. It is
reasonable, for example, to assume that a prod (as contained by a
vector prices) is a structure of some kind from the use of the
<span class="markup">-&gt;</span> dereference operator. The named
pricemap is a giveaway, but even without this clue, we could guess
that it is a map, where the value type is another container -
probably a vector. From just this information, it is possible to
see that we have a collection of products, each of which has a
minimum price, and an associated collection of possible prices for
each product. We are removing all prices that are less than the
stated minimum for that product, and displaying the results for
each product.</p>
<p>Including as it does the use of function objects, function
adapters and a standard algorithm that might not do exactly as you
would expect<sup>[<a name="d0e41" href="#ftn.d0e41" id=
"d0e41">1</a>]</sup>, this is a fairly complex use of STL; yet I
think it reasonably representative of the kind of thing for which
STL is commonly used. The adept might even factor the call of
remove_if into the call to copy, but I think that would be
gratuitous. C++, as C before it, and legion other programming
languages, can be made really obscure if you try hard enough.</p>
<p>Having said that, I believe that the problem stems simply from
the matter of notation. It is an over-used example, I know, but I
think people who were unfamiliar with C or C++ would struggle over
the meaning of this simple idiom:</p>
<p><tt class="literal">while(*d++ = *s++)</tt> As I already
mentioned, the pointer notation in C++ as in C can be odd, to put
it mildly. I think I am safe enough in saying it is the single most
problematic area for beginners in C. STL, specifically its use of
iterators, is designed to support such syntax as</p>
<pre class="programlisting">
copy (prices.begin(), remove_if (prices.begin(), prices.end(), bind2nd (less&lt;int&gt;(), i-&gt;min_price)), ostream_iterator&lt;int&gt;(cout, &quot;\t&quot;));
</pre>
<p>STL is a new notation for basic Computer Science concepts. I
find it hard to believe that &quot;normal&quot; C++ programmers are
unfamiliar with linked lists, stacks, queues and balanced trees
(OK, the terminology changes in some cases). These are data
structures that form the core of our industry. I remember all too
well implementing a Binary Search Tree in C, using <tt class=
"type">void *</tt> for the container. I welcome the news that I
will never have to do it again! I actually think that the new
notation is more intuitive. I will never again prefer <tt class=
"literal">item = item-&gt;next</tt>; over <tt class=
"literal">++item</tt>;</p>
<p>The biggest boon I think for C++ programmers is that STL
containers are value based. Specifically, when an item is removed
from a container, it is automatically deleted. I mean
&quot;automatically&quot; in the programming sense of automatic variables.
Correspondingly, when the container itself goes out of scope, all
of its contents are automatically deleted. Using the C version with
<tt class="type">void *</tt>, it does not make sense for the
container to take any responsibility for memory. It cannot allocate
space for an item, because it does not know its type. It cannot
therefore sensibly free that memory, because it did not allocate
it. All memory management is the responsibility of the user of the
container. This is a source of errors and resource leaks.</p>
<p>It is much better that the container itself takes this
responsibility. I think this is the behaviour most would want and
expect. If for some reason it is not the behaviour required, then
it can be changed. A <tt class="type">vector&lt;<i class=
"replaceable"><tt>thing</tt></i>&gt;</tt> can easily be made into a
<tt class="type">vector&lt;<i class=
"replaceable"><tt>thing</tt></i> *&gt;</tt>. This is particularly
useful when items are frequently moved between containers. An
example that springs to mind is the concept of a <tt class=
"classname">Process</tt> in a real-time system, where the item
representing a process will often move between a <tt class=
"classname">Ready-To-Run</tt> list and one of possibly several
<tt class="classname">Stopped</tt> lists.</p>
<p>As I have already mentioned, I am no programming superstar. Yet
I learned STL from Austern's &quot;<i class="citetitle">Generic
Programming and the STL</i>&quot;, which is by no means a simple
introduction. Given my time again, I know there are many better
introductions to STL. So this is a note to all &quot;normal&quot;
programmers: take the time to learn basic STL concepts, and use it
even for simple things like choosing <tt class=
"type">vector&lt;&gt;</tt> instead of a C array. You will be
rewarded with a simpler, not a more complex, programming life.</p>
</div>
<div class="footnotes"><br>
<hr class="c2" width="100">
<div class="footnote">
<p><sup>[<a name="ftn.d0e41" href="#d0e41" id=
"ftn.d0e41">1</a>]</sup> remove_if causes removed items to be
placed at the end of the container, and returns one past the end
position of items not matching the predicate. It does not actually
delete those items from the container. Hence newend as the returned
iterator.</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
