<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Proposed C++0x Keywords Considered</title>
</head>

<body>

<p>Doc. no.&nbsp;&nbsp; WG21/N2105=06-0175<br>
Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%Y-%m-%d" startspan -->2006-10-23<!--webbot bot="Timestamp" endspan i-checksum="12042" --><br>
Project:&nbsp;&nbsp;&nbsp;&nbsp; Programming Language C++<br>
Reply to:&nbsp;&nbsp; Beman Dawes &lt;<a href="mailto:bdawes@acm.org">bdawes@acm.org</a>&gt;</p>

<h1>Proposed C++0x Keywords Considered</h1>

<p><a href="#Introduction">Introduction</a><br>
<a href="#Proposed-Keywords">Proposed Keywords</a><br>
<a href="#semantics">Do proposed names clearly denote semantics?</a><br>
<a href="#consistent">Are proposed names consistent with naming conventions?</a><br>
<a href="#impact">How much do proposed names impact existing code?</a><br>
<a href="#alternatives">Possible alternatives for problem keywords</a><br>
<a href="#Code-search-web-sites">Code-search web sites</a><br>
<a href="#Acknowledgements">Methodology</a><br>
<a href="#Acknowledgements">Acknowledgements</a><br>
<a href="#Existing-keywords">Existing keywords</a></p>

<h2><a name="Introduction">Introduction</a></h2>

<p>This paper looks at  new keywords proposed for C++0x, identifiers several 
that cause concerns, and proposes alternatives to eliminate or reduce the concerns.</p>

<p>Whenever the committee makes a decision that appears inconsistent or to fly 
in the face of reason, committee members (me included) get called stupid, 
arrogant, and unconcerned about ordinary users. That's OK as long as there is a 
compelling rationale for the decision, and alternatives have been considered and 
found wanting. The purpose of this paper is to discover if any proposed keywords 
are problematic, explicitly consider alternatives for problem keywords, and 
encourage development of rationale for the committee's final keyword choices.</p>

<p><i><b>Please don't shoot the messenger! I am in favor, often strongly, of all 
the proposals discussed in this paper. But someone has to point out the bad news 
about some of the proposed keywords.</b></i></p>

<p>Possible concerns regarding proposed keywords include:</p>
<ul>
  <li>Does the common English usage of the name clearly denote the C++ semantics 
  associated with the keyword?</li>
  <li>Is the name, particularly capitalization and spelling, consistent with C++ 
  Standard naming conventions?</li>
  <li>How much existing code will be broken by the name?</li>
  <li>Are there clearly better alternatives?</li>
</ul>

<p>Each of those concerns is discussed below.</p>

<h2><a name="Proposed-Keywords">Proposed Keywords</a></h2>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="100%" colspan="2" align="center"><i><b>Proposed New C++ Keywords</b></i></td>
  </tr>
  <tr>
    <td width="37%" align="center"><i><b>Keyword</b></i></td>
    <td width="63%" align="center"><b><i>Proposal</i></b></td>
  </tr>
  <tr>
    <td width="37%"><code>_Char16_t, _Char32_t</code></td>
    <td width="63%" valign="top">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1823.html">
    N1823</a> - New Character Types in C++</td>
  </tr>
  <tr>
    <td width="37%"><code>alignof, align_union</code></td>
    <td width="63%" valign="top">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1877.pdf">
    N1877</a> - Adding Alignment Support to the C++ Programming Language</td>
  </tr>
  <tr>
    <td width="37%"><code>concept, concept_map, where, axiom, late_check</code></td>
    <td width="63%" valign="top">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2081.pdf">
    N2081</a> - Concepts</td>
  </tr>
  <tr>
    <td width="37%"><code>constexpr</code></td>
    <td width="63%" valign="top">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1980.pdf">
    N1980</a> - Generalized Constant Expressions</td>
  </tr>
  <tr>
    <td width="37%"><code>decltype</code></td>
    <td width="63%" valign="top">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1705.pdf">
    N1705</a> - Decltype (and auto)</td>
  </tr>
  <tr>
    <td width="37%"><code>import</code></td>
    <td width="63%" valign="top">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2073.pdf">
    N2073</a> - Modules in C++</td>
  </tr>
  <tr>
    <td width="37%"><code>nullptr</code></td>
    <td width="63%" valign="top">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1601.pdf">
    N1601</a> - A name for the null pointer: nullptr</td>
  </tr>
  <tr>
    <td width="37%"><code>static_assert</code></td>
    <td width="63%" valign="top">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html">
    N1720</a> - static_assert</td>
  </tr>
</table>

<h2>Do proposed names clearly denote <a name="semantics">semantics</a>?</h2>

<p>This concern has not be raised for any of the proposed keywords. It will be 
of interest, however, when considering alternatives to proposed keywords.</p>

<h2>Are proposed names <a name="consistent">consistent</a> with naming conventions?</h2>

<p>New keywords which do not follow current C++ Standard naming conventions are 
more difficult to learn and provide a lightning rod for criticism of C++. Indeed, there has already been criticism on comp.std.c++ and elsewhere 
of some of the new keywords for their inconsistency with current language and 
standard library naming conventions.</p>

<p>C++ language and standard library  naming conventions for ordinary names are to use 
all-lowercase, begin with an alpha character, and separate multiple words with underscores. The underscore separator convention is 
sometimes not applied if it will become part of a set of <a href="#Existing-keywords">existing keyword</a> or 
library names that do not follow this convention.</p>

<p>The following proposed keywords do not follow the above conventions, and thus 
clash with similar current keywords and library names:</p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="22%" align="center"><b><i>Proposed keyword</i></b></td>
    <td width="78%" align="center"><b><i>Similar existing keywords and library 
    names</i></b></td>
  </tr>
  <tr>
    <td width="22%" valign="top"><code>_Char16_t</code>, <code>_Char32_t</code></td>
    <td width="78%"> <code>wchar_t, size_t,</code> and the 
many header &lt;cstdint&gt; types.</td>
  </tr>
  <tr>
    <td width="22%" valign="top"><code>constexpr</code></td>
    <td width="78%">
<code>const_cast</code>, <code>const_iterator</code>, <code>const_pointer</code>,
<code>const_reference</code>, <code>const_mem_fun_t</code>, and so on.</td>
  </tr>
  <tr>
    <td width="22%" valign="top"><code>decltype</code></td>
    <td width="78%"> 
<code>size_type</code>, <code>value_type</code>, <code>difference_type</code>,
<code>argument_type</code>, <code>result_type</code>, and so on.</td>
  </tr>
  <tr>
    <td width="22%" valign="top"><code>nullptr</code></td>
    <td width="78%">
<code>auto_ptr</code>, <code>shared_ptr</code>, <code>weak_ptr</code> and <code>bad_weak_ptr</code>.</td>
  </tr>
</table>

<h2>How much do proposed names <a name="impact">impact</a> existing code?</h2>

<p>Any new keyword has the potential to break existing code. In the past, it was 
not possible to quantify how much existing code would be broken, but with the 
advent of <a href="#Code-search-web-sites">code-search web sites</a> it is now 
possible to gain quantitative insights into the impact of a proposed new 
keyword. Although the searches that can be performed by these search engines are not 
yet sophisticated enough to make 
exact assertions about potential keywords, they do allow us to make hard-data 
predictions about the impact on existing code.</p>

<p>The impact of proposed keywords on 1,388,870 existing C++ source files is 
analyzed in the following table. See Methodology.</p>

<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="32%" align="center"><b><i>Keyword</i></b></td>
    <td width="9%" align="center"><b><i># of files</i></b></td>
    <td width="82%" align="center"><b><i>Comments</i></b></td>
  </tr>
  <tr>
    <td width="32%"><code>_Char16_t</code>, <code>_Char32_t</code>, <code>align_union</code>, <code>
concept_map</code>, <code>late_check</code>.</td>
    <td width="9%" align="right">0</td>
    <td width="82%">&lt;1 in 1,000,000 files</td>
  </tr>
  <tr>
    <td width="32%"><code>alignof</code></td>
    <td width="9%" align="right">0</td>
    <td width="82%">There was one use in a gcc compiler file not counted since it 
    appeared compatible.</td>
  </tr>
  <tr>
    <td width="32%"><code>static_assert</code></td>
    <td width="9%" align="right">0</td>
    <td width="82%">A few uses of a static_assert macro not counted since they 
    appeared compatible.</td>
  </tr>
  <tr>
    <td width="32%"> <code>constexpr</code></td>
    <td width="9%" align="right">1</td>
    <td width="82%">&nbsp;</td>
  </tr>
  <tr>
    <td width="32%"> <code>nullptr</code></td>
    <td width="9%" align="right">7</td>
    <td width="82%">&nbsp;</td>
  </tr>
  <tr>
    <td width="32%"> <code>
decltype</code></td>
    <td width="9%" align="right">14</td>
    <td width="82%">&nbsp;</td>
  </tr>
  <tr>
    <td width="32%"><code>axiom</code></td>
    <td width="9%" align="right">17</td>
    <td width="82%">&nbsp;</td>
  </tr>
  <tr>
    <td width="32%"><code>concept</code></td>
    <td width="9%" align="right">110</td>
    <td width="82%">&nbsp;</td>
  </tr>
  <tr>
    <td width="32%"><code>import</code></td>
    <td width="9%" align="right">190</td>
    <td width="82%">1 in 7,300 files</td>
  </tr>
  <tr>
    <td width="32%"><code>where</code></td>
    <td width="9%" align="right">11,678</td>
    <td width="82%">1 in 119&nbsp; files; ~ 1% of all files. Projects include: 
    wxWidgets, Mozilla, KDE, etc.</td>
  </tr>
</table>

<p>The proposed <code>where</code> keyword stands out as a serious problem. It 
can't just be changed globally in a source file, because its use in comments is ambiguous; 
is &quot;where&quot; the English word &quot;where&quot; or a source entity name? The name <code>where</code> 
is used in widely in third party libraries, including 
proprietary libraries. That means an organization can't upgrade to C++0x until 
after 
all of the third party libraries it depends on upgrade to C++0x. Because one of 
the several meanings of the word &quot;where&quot; is &quot;location&quot;, applications such as 
Geographic Information Systems, Logistics Support, graphics, and some of the 
physical sciences make particularly heavy use of <code>where</code> in program 
code. Because <code>where</code> is a keyword in SQL, C++ code that composes SQL 
commands is particularly hard hit. Because industrial code is proprietary, it is 
not present in the code database that was searched, so the impact of adding <code>where</code> 
as a keyword may be even worse that indicated in the table above.</p>

<h2>Possible <a name="alternatives">alternatives</a> for problem keywords</h2>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="15%" align="center"><b><i>Proposed keyword</i></b></td>
    <td width="26%" align="center"><b><i>Alternatives</i></b></td>
    <td width="109%" align="center"><b><i>Comments on Alternative</i></b></td>
  </tr>
  <tr>
    <td width="15%"><code>_Char16_t</code> </td>
    <td width="26%"><code>char16_t</code> </td>
    <td width="109%">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1823.html">
    N1823</a> proposes a typedef instead</td>
  </tr>
  <tr>
    <td width="15%"> <code>_Char32_t</code></td>
    <td width="26%"> <code>char32_t</code></td>
    <td width="109%">
    <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1823.html">
    N1823</a> proposes a typedef instead</td>
  </tr>
  <tr>
    <td width="15%"><code>constexpr</code> </td>
    <td width="26%"><code>const_expr</code></td>
    <td width="109%">Consistent with <code>const_cast</code>, <code>
    const_iterator</code>, etc.</td>
  </tr>
  <tr>
    <td width="15%"><code>decltype</code></td>
    <td width="26%"><code>decl_type</code></td>
    <td width="109%">Consistent with 
<code>size_type</code>, <code>value_type</code>,&nbsp; <code>result_type</code>, 
    etc. The case is weaker, however, because other type related keywords (<code>typedef</code>,
    <code>typeid</code>, <code>typename</code>) do not have underscores.</td>
  </tr>
  <tr>
    <td width="15%"><code>nullptr</code></td>
    <td width="26%"><code>null_ptr</code></td>
    <td width="109%">Consistent with <code>auto_ptr</code>, <code>shared_ptr</code>, 
    etc.</td>
  </tr>
  <tr>
    <td width="15%"><code>import</code></td>
    <td width="26%">?</td>
    <td width="109%">No useful alternative comes to mind.</td>
  </tr>
  <tr>
    <td width="15%"><code>concept</code></td>
    <td width="26%"><code>type_concept, typeconcept</code></td>
    <td width="109%" rowspan="2">Although the case is weak since the impact on 
    existing code is fairly minor, these would reduce impact to essentially 
    zero, and avoid tramping on useful names. (0 files found).</td>
  </tr>
  <tr>
    <td width="15%"><code>axiom</code></td>
    <td width="26%"><code>type_axiom, typeaxiom</code></td>
  </tr>
  <tr>
    <td width="15%"><code>where</code></td>
    <td width="26%"><code>requires</code></td>
    <td width="109%">Cuts impact on existing code by factor of 64 (11,678 files 
    to 183 files). Arguably does a better job of denoting semantics.</td>
  </tr>
</table>

<h2><a name="Code-search-web-sites">Code-search web sites</a></h2>
<p>Code-search web sites are starting to become available. These sites allow 
automated searches of publicly available source code. 
The files usually have some form of open-source license.</p>
<p>The ability to search vast amounts of source code allows quantitative 
analysis of the impact on existing code of a proposed C++ keyword.</p>
<p>Code-search sites include:</p>
<blockquote>
<p><b>Google Code Search</b> - <a href="http://www.google.com/codesearch">
www.google.com/codesearch</a> - A search for &quot;include&quot; finds 809,000 C++ 
files and 4 million C files. Google is mistakenly classifying at least some C++ 
code as C code. For example, some Boost code is classified as C code. No 
apparent way to exclude comments from search.</p>
<p><b>codesearch.net</b> - <a href="http://csourcesearch.net/">csourcesearch.net</a> 
- 283 million lines of C/C++ code in 1.1 million files. Searches do not yield 
total hit counts, making the site less useful than it might otherwise be.</p>
<p><b>koders</b> - <a href="http://www.koders.com/">www.koders.com</a> - Claims 
424 million lines of code, but doesn't appear to have as much C/C++ code as 
others. No apparent way to exclude comments from search.</p>
<p><b>krugle</b> - <a href="http://www.krugle.com">www.krugle.com</a> - Appears 
to have 1,388,870 files classified as C++ code. Allows comments to be excluded 
from search.</p>
</blockquote>
<h2><a name="Methodology">Methodology</a></h2>
<p>The <a href="http://www.krugle.com">krugle</a> database was studied because 
it distinguishes between source code and comments, gives files found counts, 
appears to have done a good job of identifying C++ code, and did not yield 
self-contradictory results for test queries.</p>
<p>For each keyword of interest, the automated search was run on the word, 
selecting C++ as the language and &quot;Source code&quot; as the search area.</p>
<p>For candidates reported in 100 or less files, each search hit was examined to 
determine the actual count. This determination included discarding uses in 
literals, as part of longer names, and anything else that could skew the 
results.</p>
<p>For candidates reported in more than 100 files, the first five search hits on 
the first 20 pages (100 total hits) were examined to determine a percentage of 
correct hits. This determination included discarding uses in literals, as part 
of longer names, and anything else that could skew the results. The percentage 
in the sample was then applied to the total file count to obtain the file count 
reported in the table.</p>
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
<p>Gennaro Prota pointed out the <code>nullptr</code> naming inconsistency in a 
comp.std.c++ posting.</p>

<h2><a name="Existing-keywords">Existing keywords</a></h2>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="100%" align="center"><b><i>Existing C++ Keywords</i></b></td>
  </tr>
  <tr>
    <td width="100%">
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="20%" valign="top"><code>asm<br>
    auto<br>
    bool<br>
    break<br>
    case<br>
    catch<br>
    char<br>
    class<br>
    const<br>
    const_cast<br>
    continue<br>
    default<br>
    delete</code></td>
    <td width="20%" valign="top"><code>do<br>
    double<br>
    dynamic_cast<br>
    else<br>
    enum<br>
    explicit<br>
    export<br>
    extern<br>
    false<br>
    float<br>
    for<br>
    friend<br>
    goto</code></td>
    <td width="20%" valign="top"><code>if<br>
    inline<br>
    int<br>
    long<br>
    mutable<br>
    namespace<br>
    new<br>
    operator<br>
    private<br>
    protected<br>
    public<br>
    register<br>
    reinterpret_cast</code></td>
    <td width="20%" valign="top"><code>return<br>
    short<br>
    signed<br>
    sizeof<br>
    static<br>
    static_cast<br>
    struct<br>
    switch<br>
    template<br>
    this<br>
    throw<br>
    true<br>
    try</code></td>
    <td width="20%" valign="top"><code>typedef<br>
    typeid<br>
    typename<br>
    union<br>
    unsigned<br>
    using<br>
    virtual<br>
    void<br>
    volatile<br>
    wchar_t<br>
    while</code></td>
  </tr>
</table>
    </td>
  </tr>
</table>
<hr>
<p> Beman Dawes 2006</p>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->23 October 2006<!--webbot bot="Timestamp" endspan i-checksum="32473" --></p>

</body>

</html>
