<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mark Nelson &#187; Standards</title>
	<atom:link href="http://marknelson.us/category/standards/feed/" rel="self" type="application/rss+xml" />
	<link>http://marknelson.us</link>
	<description>Programming, mostly.</description>
	<lastBuildDate>Fri, 13 Apr 2012 19:25:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Visual Studio 11 and Modern C++</title>
		<link>http://marknelson.us/2012/03/13/visual-studio-11-and-modern-c/</link>
		<comments>http://marknelson.us/2012/03/13/visual-studio-11-and-modern-c/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 13:13:08 +0000</pubDate>
		<dc:creator>Mark Nelson</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Standards]]></category>

		<guid isPermaLink="false">http://marknelson.us/?p=1467</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://marknelson.us/2012/03/13/visual-studio-11-and-modern-c/' addthis:title='Visual Studio 11 and Modern C++' ><a class="addthis_button_twitter"></a><a class="addthis_button_favorites"></a><a class="addthis_button_print"></a><a class="addthis_button_facebook_like"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_compact"></a></div>Despite some harsh words about Visual Studio 11, I&#8217;m finding that it makes my heart go pitter-pat every time I use it. Why? Because this early release is finally incorporating a decent set of long-awaited C++11 features. In this article I&#8217;ll show you how a little thing like a lambda can make a big difference [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://marknelson.us/2012/03/13/visual-studio-11-and-modern-c/' addthis:title='Visual Studio 11 and Modern C++' ><a class="addthis_button_twitter"></a><a class="addthis_button_favorites"></a><a class="addthis_button_print"></a><a class="addthis_button_facebook_like"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_compact"></a></div><p>Despite some <a href="http://drdobbs.com/windows/232602205" class="newpage">harsh words</a> about Visual Studio 11, I&#8217;m finding that it makes my heart go pitter-pat every time I use it. Why?  Because this early release is finally incorporating a decent set of long-awaited C++11 features. In this article I&#8217;ll show you how a little thing like a lambda can make a big difference in your coding style.<br />
<span id="more-1467"></span></p>
<h4>Microsoft and C++ &#8211; We Have History</h4>
<p>Microsoft has a cyclic relationship with C++. In the early MFC days, the love was there big time &#8211; you had access to most of the system API using C++. However, around the turn of the millennium, Microsoft came under the Rasputin-like influence of Anders Hejlsberg and his beloved offspring, C#. Now it appears that maybe the pendulum is swinging back a bit, and C++ is no longer viewed as an afterthought. Great news.</p>
<p>Although Visual Studio 11 is a developer&#8217;s preview, Microsoft is <a href="http://herbsutter.com/2012/02/29/vc11-beta-on-feb-29/" class="newpage">saying</a> that it is production ready &#8211; you can use this to create programs that are ready for release. In addition to touting a complete implementation of the C++11 standard library, an <a href="http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx" class="newpage">impressive list</a> of language features have been turned on as well. (N.B. the path ahead is still long and arduous.)</p>
<h4>Modern C++</h4>
<p>Before even using Visual Studio C++ 11 to test a single line of code, I really appreciated reading <a href="http://msdn.microsoft.com/en-us/library/hh279654(v=vs.110).aspx" class="newpage">Welcome Back to C++ (Modern C++)</a>, a manifesto that includes the following bullet points:</p>
<blockquote><p>
Modern C++ emphasizes:</p>
<ul>
<li>Stack-based scope instead of heap or static global scope.</li>
<li>Auto type inference instead of explicit type names.</li>
<li>Smart pointers instead of raw pointers.</li>
<li>std::string and std::wstring types instead of raw char[] arrays.</li>
<li>Standard template library (STL) containers—for example, vector, list, and map—instead of raw arrays or custom containers.</li>
<li>STL algorithms instead of manually coded ones.</li>
<li>Exceptions, to report and handle error conditions.</li>
<li>Inline lambda functions instead of small functions implemented separately.</li>
</blockquote>
<p>I feel that all of these changes result in safer code that is easier to read and maintain, without giving up the type-safety and efficiency that we love so much. Fully implementing these features either leans heavily on C++11 or requires it outright.</p>
<h4>A Simple Example Using Naive C++98</h4>
<p>It&#8217;s interesting to watch the evolution of code from C++ 98 to C++11 and see how it affects your code. You&#8217;ll see that the transformation can make it look like you are literally using a new programming language.</p>
<p>In this simple program, I&#8217;m taking a Scrabble rack of tiles and whipping through the Scrabble dictionary to find matches. Since it is a one-time call, I&#8217;m not storing the words, just doing a quick online comparison. In C++ 98, my code might have looked like this:</p>
<pre>
void find_matches( std::string rack, const std::string &amp;filename )
{
    std::sort( rack.begin(), rack.end() );
    std::ifstream sowpods( filename.c_str() );
    std::string word;
    while ( sowpods &gt;&gt; word ) {
        std::string sorted = word;
        std::sort( sorted.begin(), sorted.end() );
        if ( sorted == rack )
            std::cout &lt;&lt; word &lt;&lt; &quot; &quot;;
    }
}

int main(int argc, char* argv[])
{
    find_matches( &quot;etaionsr&quot;, &quot;sowpods.txt&quot; );
    return 0;
}
</pre>
<p>This works properly and I get what looks like correct output:</p>
<pre>
anoestri arsonite notaries notarise rosinate senorita
</pre>
<h4>Classes Good, Templates Better</h4>
<p>As people started to get more comfortable with templates and iterators, algorithms like this were commonly rewritten to take an range of iterators as input &#8211; much as the standard library algorithm functions do. This meant changing the function to a template function, but it did make it a lot more flexible. I could now call the function to operate on data from a file, just as before, but I can also now use any other container, or even an array as input:</p>
<pre>
template&lt;typename ITERATOR&gt;
void find_matches( std::string rack, ITERATOR ii, ITERATOR jj )
{
    std::sort( rack.begin(), rack.end() );
    for ( ; ii != jj ; ii++ ) {
        std::string sorted = *ii;
        std::sort( sorted.begin(), sorted.end() );
        if ( sorted == rack )
            std::cout &lt;&lt; *ii &lt;&lt; &quot; &quot;;
    }
}

int main(int argc, char* argv[])
{
    std::ifstream sowpods( &quot;sowpods.txt&quot; );
    find_matches( &quot;etaionsr&quot;,
                  std::istream_iterator&lt;std::string&gt;( sowpods ),
                  std::istream_iterator&lt;std::string&gt;() );
    return 0;
}
</pre>
<p>More or less the same number of lines of code, but it is now generic.</p>
<p>Of course, just like with OOP, you need to take some care with template programming. Generic programming can&#8217;t be beat when it makes sense, but programmers have a particularly strong susceptibility to <a href="http://en.wikipedia.org/wiki/Pro-innovation_bias" class="newpage">pro-innovation bias</a>. </p>
<h4>Using the Algorithms Library</h4>
<p>Again, prodded by changing styles in the C++ world, my next step is to use a standard library algorithm to do the work. We&#8217;re told over and over that turning to the algorithms library allows you to use code that has been optimized to the n-th degree by the clever library teams. </p>
<p>In order to make this work, I have to call an algorithm with a predicate functor, seen below as class <code>sorted_not_equal</code>. Note also that I can&#8217;t use the logical function for this, which would be <code>copy_if()</code>. Why not? The committee forgot to put it in back in 1998, 2003, and 2005, a mistake that was fortunately remedied in C++11. So I have to use the inverse function, <code>remove_copy_if()</code>, and invert the logical sense of my functor:</p>
<pre>
class sorted_not_equal {
    std::string str;
public :
    sorted_not_equal( const std::string &amp; test )
    {
        str = test;
        sort( str.begin(), str.end() );
    }
    bool operator()( std::string test )
    {
        sort( test.begin(), test.end() );
        return ( str != test );
    }
};

template&lt;typename INPUT_ITERATOR, typename OUTPUT_ITERATOR&gt;
void find_matches( std::string rack,
                   INPUT_ITERATOR ii,
                   INPUT_ITERATOR jj,
                   OUTPUT_ITERATOR kk )
{
    std::sort( rack.begin(), rack.end() );
    std::remove_copy_if( ii, jj, kk, sorted_not_equal( rack ) );
}

int main(int argc, char* argv[])
{
    std::ifstream sowpods( &quot;sowpods.txt&quot; );
    find_matches( &quot;etaionsr&quot;,
                  std::istream_iterator&lt;std::string&gt;( sowpods ),
                  std::istream_iterator&lt;std::string&gt;(),
                  std::ostream_iterator&lt;std::string&gt;(std::cout,  &quot;\n&quot; ) );
    return 0;
}
</pre>
<h4>Functors Not So Hot</h4>
<p>So this new approach is supposed to soup up my code by taking advantage of the algorithms that come with the standard library. But if you look around at the code people have been writing for the past 10 years, you&#8217;ll find that this style is pretty common in textbooks and magazine articles, but no so much in the real world.</p>
<p>Why not? Well, it&#8217;s pretty obvious. The generic algorithms in the library need lots of predicate glue to make them useful, and the work to create these predicates is just a pain. My code is almost twice as long, and the functionality that took two lines of code earlier is now bloated into a complete class definition. It pollutes my namespace, takes up a lot of space, and has to be defined somewhere distant from where it is actually used. Not a win.</p>
<p>This is obviously a problem when you look at the history of Linux, C, and C++. An entire family of technologies and infrastructure was developed with the implicit goal of reducing the number of keystrokes programmers had to enter. (I&#8217;m kidding, but only somewhat.) Functors are a step in the wrong direction.</p>
<h4>Lambda to the Rescue</h4>
<p>So it is with much relief that C++11 delivers lambdas, which allow us to write short sweet predicates exactly where we need them, as shown in this C++11 version of the example:</p>
<pre>
template&lt;typename INPUT_ITERATOR, typename OUTPUT_ITERATOR&gt;
void find_matches( std::string rack,
                   INPUT_ITERATOR ii,
                   INPUT_ITERATOR jj,
                   OUTPUT_ITERATOR kk )
{
    std::sort( rack.begin(), rack.end() );
    std::copy_if( ii, jj, kk,
                  [&amp;rack](std::string str) -&gt;bool
                  {
                      std::sort( str.begin(), str.end() );
                      return rack == str;
                  }
                );
}

int main(int argc, char* argv[])
{
    std::ifstream sowpods( &quot;sowpods.txt&quot; );
    find_matches( &quot;etaionsr&quot;,
                  std::istream_iterator&lt;std::string&gt;( sowpods ),
                  std::istream_iterator&lt;std::string&gt;(),
                  std::ostream_iterator&lt;std::string&gt;(std::cout,  &quot;\n&quot; ) );
	return 0;
}
</pre>
<p>Yes, I now have to get used to a new syntax for writing lambda functions &#8211; I think that was unavoidable. But my lambda function is short, it is quite easy to see exactly what it is doing, and it replaces a gangly and awkward functor class. </p>
<p>Best of all, I use the lambda exactly where I need it &#8211; as the predicate parameter to an algorithm used in the standard library. Locality rules.</p>
<h4>Using Lambdas</h4>
<p>Visual C++ 11 provides a great framework for experimenting with lambdas, as they are supporting the 1.1 definition that was ratified as part of the standard. If you want the gory details, I believe the <a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2927.pdf" class="newpage">working group&#8217;s</a> proposal has essentially the same wording that went into the standard. For a detailed tutorial, <a href="http://herbsutter.com/2011/05/20/my-lambdas-talk-nwcpp-is-now-online/" class="newpage">Herb Sutter&#8217;s talk</a> can&#8217;t be beat.</p>
]]></content:encoded>
			<wfw:commentRss>http://marknelson.us/2012/03/13/visual-studio-11-and-modern-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Free ITU Documents?</title>
		<link>http://marknelson.us/2006/08/10/free-itu-docs/</link>
		<comments>http://marknelson.us/2006/08/10/free-itu-docs/#comments</comments>
		<pubDate>Thu, 10 Aug 2006 17:18:37 +0000</pubDate>
		<dc:creator>Mark Nelson</dc:creator>
				<category><![CDATA[Standards]]></category>
		<category><![CDATA[Web Articles]]></category>

		<guid isPermaLink="false">/2006/08/10/free-itu-docs/</guid>
		<description><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://marknelson.us/2006/08/10/free-itu-docs/' addthis:title='Free ITU Documents?' ><a class="addthis_button_twitter"></a><a class="addthis_button_favorites"></a><a class="addthis_button_print"></a><a class="addthis_button_facebook_like"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_compact"></a></div>Dr. Dobb&#8217;s Portal August, 2006 Article on DDJ site International standards are good, we all love them, sure. But if you aren&#8217;t lucky enough to be employed by a big company or a university, getting your hands on these standards can be a real pain. Typically the standards bodies sell electronic copies of their work [...]]]></description>
			<content:encoded><![CDATA[<div class="addthis_toolbox addthis_default_style" addthis:url='http://marknelson.us/2006/08/10/free-itu-docs/' addthis:title='Free ITU Documents?' ><a class="addthis_button_twitter"></a><a class="addthis_button_favorites"></a><a class="addthis_button_print"></a><a class="addthis_button_facebook_like"></a><a class="addthis_button_google_plusone"></a><a class="addthis_button_compact"></a></div><table border="0" width="500">
<tr>
<td width="300"><img alt="DDJ Portal Logo" src="http://marknelson.us/attachments/misc/logo_ddj.gif" /></td>
<td><strong>Dr. Dobb&#8217;s Portal</strong> August, 2006<br />
         <a href="http://www.ddj.com/architect/192201183" class="newpage">Article on DDJ site</a>
  </td>
</tr>
</table>
<p><img src="http://marknelson.us/attachments/free-itu-docs/itu.gif" class="alignleft"/><br />
International standards are good, we all love them, sure. But if you aren&#8217;t lucky enough to be employed by a big company or a university, getting your hands on these standards can be a real pain. Typically the standards bodies sell electronic copies of their work for fairly high prices, justifying it as one of the only ways they can subsidize their activities.</p>
<p>Just an example, if you want to buy a hardcopy of the C++ standard, you can end up paying as much as <a href="http://www.techstreet.com/cgi-bin/detail?product_id=1143945">$US 175</a> for the privilege &#8211; which is a killer if you are just doing this for personal use.</p>
<p>This turns into a FAQ in public newsgroups and forums when the uninitiated start operating under the idea that they ought to be able to just find a copy on the web. <a href="http://groups.google.com/group/comp.compression/browse_thread/thread/fdbc21de7039363a">This thread</a> on comp.compression is a classic example, where Nils Haeck is looking for free copies of some of the JPEG documents.</p>
<p>But oddly enough, later on in the thread Nils sheds a piece of light on the discussion, disclosing a piece of news that I hadn&#8217;t heard before. It turns out that the ITU has a program in which individuals can get up to three free electronic copies of their standards documents per year. This is exciting!</p>
<p>I thought I&#8217;d give it a try by first signing in at the <a href="https://ecs.itu.ch/cgi-bin/run/ebookshop?choice=">ITU Bookstore</a>. You&#8217;ll note on this page there is a button that says: <em>I wish to REGISTER in order to download up to three (3) Recommendations free of charge</em>. Yes, I certainly do. I selected the button and went to the registration page. The registration, shown below, has a bit of a problem being rather corporate-oriented, so I tried to steer it into the notion that I am an a company of one:</p>
<p><center><br />
<img src="http://marknelson.us/attachments/free-itu-docs/ScreenShot001.gif"><br />
Figure 1 &#8211; The registration form<br />
</center></p>
<p>All went well and the ITU blessed me immediately. My email was almost instantaneous, and I was ready to shop.</p>
<p><center><br />
<img src="http://marknelson.us/attachments/free-itu-docs/ScreenShot002.gif"><br />
Figure 2 &#8211; The ITU loves me<br />
</center></p>
<p>Just to test the system, I first downloaded a spec I knew I would find handy, <a href="http://www.itu.int/rec/T-REC-T.800-200208-I/en">JPEG 2000 image coding system: Core coding system</a>. Sure enough, a few minutes later I had my personal copy in hand. Now I just have to decide where to spend my precious remaining two downloads:</p>
<ul>
<li><a href="http://www.itu.int/rec/T-REC-T.81-199209-I/en">JPEG &#8211; Digital compression and coding of continuous-tone still images</a>
<li><a href="http://www.itu.int/rec/T-REC-T.804-200208-I/en">JPEG 2000 image coding system: Reference software</a>
<li><a href="http://www.itu.int/rec/T-REC-T.851-200509-I/en">ITU-T T.81 (JPEG-1)-based still-image coding using an alternative arithmetic coder</a>
<li><a href="http://www.itu.int/rec/T-REC-V.24-200002-I/en">List of definitions for interchange circuits between data terminal equipment (DTE) and data circuit-terminating equipment (DCE) (aka RS-232)</a>
<li><a href="http://www.itu.int/rec/T-REC-H.323-200606-P/en">H.323 &#8211; Packet-based multimedia communications systems</a>
<li><a href="http://www.itu.int/rec/T-REC-G.722/en">G.722 : 7 kHz audio-coding within 64 kbit/s</a>
<li><a href="http://www.itu.int/rec/T-REC-G.729-199603-I/en">Coding of speech at 8 kbit/s using conjugate-structure algebraic-code-excited linear prediction (CS-ACELP)</a>
<li><a href="http://www.itu.int/rec/T-REC-G.191-200509-I/en">Software tools for speech and audio coding standardization</a>
</ul>
<p>It&#8217;s nice to at least have a choice, isn&#8217;t it? Now if we could get the ISO and ANSI to adopt similarly enlightened policies the world would be a much better place.</p>
]]></content:encoded>
			<wfw:commentRss>http://marknelson.us/2006/08/10/free-itu-docs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

