    <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  :: Editorial: The &quot;Safe C++ Standard Library&quot;</title>
        <link>https://members.accu.org/index.php/articles/297</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">Journal Editorial + Overload Journal #70 - Dec 2005</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/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c185/">Editorial</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/c78/">Overload</a>

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

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

                    -                        <a href="https://members.accu.org/index.php/articles/c185+142/">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;Editorial: The &quot;Safe C++ Standard Library&quot;</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 09 December 2005 05:00:00 +00:00 or Fri, 09 December 2005 05:00:00 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="section" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a></h2>
</div>
<p>At a conference some years ago a group of us developed an
analogy for software development over a series of lunchtime
conversations. (I won't mention names as my memory is sufficiently
vague as to who participated in these conversations and who was
simply around at the time.) The analogy was with the preparation of
food. The circumstances under which software is developed vary from
&quot;fast food&quot; to &quot;gourmet&quot; - and the way it is developed differs just
as much. At the time the point of these discussions and the
building of this analogy was a discussion of the differences
between types of developer and the way in which they approach their
work.</p>
<p>One of the points we explored was that the approach to
developing software reflected the context in which the developers
work. There is a place in the world for quickly developed &quot;burger
and fries&quot; software - I occasionally write throwaway scripts to
munge data from one format to another or to generate test data.
This type of software is effective in meeting the immediate needs
of the business, but achieves this with potentially poor error
detection and handling, or with performance characteristics that
scale poorly, and is written with no thought to reuse or
maintenance. Also, it is all too common for such software to be
unusable without the author on hand to deal with odd behaviour.
There is, of course, a medium to long term cost of this sort of
diet. Since this conversation Morgan Spurlock shot to fame with his
demonstration of this in the context of food: &quot;Supersize Me&quot;. (And
a similar problem arises when organisations clog up their arteries
with this sort of software.)</p>
<p>For the more discerning organisation there is a requirement for
developers to craft something that can be used without the author
standing by to fix problems if they occur, or that may be
maintained over a long period of time, or used in a variety of
contexts, or meets stringent performance characteristics. Different
skills come into play when writing such software. A lot more care
with the preparation of the ingredients, a different set of tools
and a lot more thought. But the results are worth the effort: a
diet of quality software base makes for a fitter and happier
organisation.</p>
<p>One of the things that we were considering was the mismatch that
occurs if a developer accustomed to working in one way encounters a
situation that required the other approach. We can all imagine the
consequence of swapping the kitchen staff of a burger chain with
those from a good restaurant. (I hope I've not just invented
another theme for &quot;reality TV&quot;.) When this happens the frustration
of all involved in such situations will be obvious - even if the
true causes are not. All too often the incompetence is assumed
where a failure to communicate what is needed is the cause.</p>
<p>During these conversations we also examined the role that tools
played in the analogy - are great tools required to produce great
software? Or can bad software be avoided by the use of good tools?
It was my contention that it is the skills that matter: a top class
chef would be able to produce good quality food even when separated
from their kitchen. On the other hand, if separated from the
freezer full of frozen burgers the results would not be so good for
the McDonald's kitchen staff. The killing argument against this
however was that &quot;a real chef would not be separated from his
knives&quot;.</p>
<p>These conversations - especially the usefulness of potentially
dangerous tools to an expert in the craft - came to mind recently.
I was reading the reactions of a group of C++ experts to the recent
discovery that a vendor plans to ship an implementation of C++ that
produces messages like the following:</p>
<pre class="screen">
c:\program files\microsoft visual studio 8\vc\include\algorithm(637) : warning C4996: 'std::swap_ranges' was declared deprecated
c:\program files\microsoft visual studio 8\vc\include\algorithm (625) : see declaration of 'std:: swap_ranges'
Message: 'You have used a std:: construct that is not safe. See documentation on how to use the Safe Standard C++ Library' ...
</pre>
<p>This discussion was the first I'd heard of the &quot;Safe Standard
C++ Library&quot; - which is a bit surprising as for some years I've
been involved with both the BSI and ISO working groups that define
the standard C++ library. And, as it was the latter group who were
discussing this development, I'm pretty sure most of the rest of
them did not know about it either. We were also surprised to see
the term &quot;deprecated&quot; used in this context - it has a technical
meaning within the standard that is not applicable here.</p>
<p>Let me be quite clear about this: the so called &quot;Safe Standard
C++ Library&quot; has no standing outside of Microsoft - it is neither
an official standard nor a de-facto one. Also the ISO C++ working
group has not deprecated <tt class="function">std::swap_range</tt>
(or any of the other functions that can lead to these messages
appearing). So, what on earth is this all about? There are
representatives of Microsoft that participate in the
standardisation of C++, and they were able to supply some of the
details. It seems that Microsoft have identified a number of
&quot;unsafe&quot; constructs in the standard C and C++ libraries: that can
overwrite memory, or functions that return pointers to static data,
or ... There is nothing very contentious about there being &quot;sharp
knives&quot; in the C++ library - although there may be some debate
about some of the specific choices made by Microsoft.</p>
<p>To assist themselves in eliminating these &quot;unsafe&quot; uses from
their own codebase Microsoft have modified their compiler to flag
them. This is illustrated by the message shown above. (This was
posted to the library working group reflector - I presume that
somewhere in the part of the error message I've not seen it
identifies the code that uses <tt class=
"function">swap_ranges</tt>.) If carelessly written this code could
lead to memory being overwritten.</p>
<p>Microsoft have also developed some &quot;safe&quot; alternatives to the
standard functions they have &quot;deprecated&quot; - and this alternative is
what they have called &quot;The Safe C++ Library&quot;. Well, their code is
developed in their &quot;kitchen&quot; - so they are perfectly entitled to
ban sharp knives there and from their account of their experience
it seems that they had good results (although it hasn't been made
clear to me how they measured this).</p>
<p>Full of enthusiasm for these benefits that this initiative has
achieved, they've decided that all their users will gain from
having these facilities made available to them. However, many of
the experts working in C++ resent the idea of these rules being
imposed upon their kitchens! In these kitchens the sharp knives are
there because they are useful and are (hopefully) used with the
care they require.</p>
<p>Many of the experts involved in this discussion provide
libraries that need to compile cleanly with a wide range of C++
implementations. Some have already announced that they will be
disabling this message in their code - they clearly don't want to
spend time producing a special version of their code for clients
that happen to use the Microsoft compiler.</p>
<p>There are also concerns for the ordinary C++ developer. Like
many others I require clean compiles, and while a few of us might
recognise that the above message is misleading I've certainly
worked for organisations where an extended debate would ensue about
how to adapt to it. (Which is a waste of time and energy.) And
there will be some organisations or developers that will blithely
follow the advice to use &quot;The Safe C++ Library&quot; without realising
that doing so locks their codebase into a library that is only
available from a single vendor.</p>
<p>The Microsoft representatives seem to be surprised at the
negative reaction of the other experts to their plans. They had
come up with a way to improve the quality of their customer's code
and had not foreseen the possibility that people would not want to
have these &quot;unsafe&quot; uses of C++ highlighted or to be offered a safe
alternative. They really hadn't considered how their efforts would
be perceived by the remainder of the C++ community.</p>
<p>Now there are many things that Microsoft could have done
differently if only they had realised the need. And, after the
feedback they have received, they may indeed do things differently
when they ship the next version! They could have avoided
terminology that suggests that their coding guidelines are
connected with the C++ standard, they need not have made these
messages the default option, and they could have provided better
mechanisms for controlling these messages. (In the current version
if a library vendor disables them for the duration of a header from
their library, then the messages are not always emitted for users
that choose to adopt Microsoft's guidelines.)</p>
<p>A more generous option would be to ensure that their &quot;Safe
Standard C++ Library&quot; is made widely available - preferably under a
licence that allows it to be used and supported on other platforms.
If it brings the benefits to others that Microsoft have experienced
then it could be of real benefit to developers. I don't know how
common they are in the wider community but there is certainly a
class of buffer-overrun errors addressed by these efforts. If they
are as common as Microsoft believes, it would be a shame if these
warnings are ignored (or simply disabled) by developers as &quot;yet
another attempt to achieve vendor lock-in&quot; - but that has been
precisely the reaction of those developers I've consulted about
this.</p>
<p>The &quot;Safe Standard C++ Library&quot; might even form the basis for
future revisions to the C++ standard. The Microsoft representatives
have indicated that the parts of this work applicable to the C
standard have already been adopted by the ISO C working group as
the basis for a &quot;Technical Report&quot; (due next year) and that &quot;once
there is a little more community experience&quot; Microsoft intends to
do the same with the work on C++. So, in a future revision of C++,
using <tt class="function">swap_ranges</tt> with pointer arguments
(which Microsoft considers an unsafe practice) may indeed become
deprecated!</p>
<p>From what I've seen on TV every chef thinks the way that they
run their kitchen is the right way - and that everyone else can
gain by emulating them. So it is not too surprising that the
developers at Microsoft think the same way. On the other hand the
resistance to new ideas cannot be absolute - otherwise we'd still
be using wooden implements to cook over open fires. Chefs (and
developers) are impressed by results - and if the results of using
these tools are good enough they will be adopted.</p>
<p>And what will I be doing in &quot;my kitchen&quot;? Well, I see C++
developers writing needlessly platform specific code far more often
than I see them misusing <tt class="function">swap_ranges</tt> (and
I don't think I've seen <tt class="function">gets</tt> used since
the mid-'80s). So I'll be turning that warning firmly to the &quot;off&quot;
setting.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
