<?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>Code Improved &#187; C++</title>
	<atom:link href="http://blog.codeimproved.net/tag/cpp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codeimproved.net</link>
	<description></description>
	<lastBuildDate>Sun, 18 Dec 2011 18:50:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Virtual machines on telephones: Google didn&#8217;t have much choice</title>
		<link>http://blog.codeimproved.net/2010/10/virtual-machines-on-telephones-google-didnt-have-much-choice/</link>
		<comments>http://blog.codeimproved.net/2010/10/virtual-machines-on-telephones-google-didnt-have-much-choice/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 18:31:28 +0000</pubDate>
		<dc:creator>razvanpetru</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.codeimproved.net/?p=254</guid>
		<description><![CDATA[An interesting discussion was sparked on HN by a blog entry on apenwarr.ca. I&#8217;ve also been a little&#8230; surprised by Google&#8217;s choice of technology, but when you think about it, they didn&#8217;t have much choice. What were the options? They needed a widely-used, performant, reasonably easy to understand programming language. Web apps? No, Apple tried [...]]]></description>
			<content:encoded><![CDATA[<p>An <a href="http://news.ycombinator.com/item?id=1636943" target="_blank">interesting discussion</a> was sparked on HN by a blog entry on apenwarr.ca. I&#8217;ve also been a little&#8230; surprised by Google&#8217;s choice of technology, but when you think about it, they didn&#8217;t have much choice.</p>
<p>What were the options? They needed a widely-used, performant, reasonably easy to understand programming language.</p>
<p>Web apps? No, Apple tried at first to use HTML + JS, but it didn&#8217;t work so they moved to Objective-C. Ruby, Python? Ruby is memory hungry, on the slow side and web-focused. Python is a little faster, which might work if one or two, or even six mobile Python apps were running at the same time. But what about 20 apps?</p>
<p>Objective-C might as well be owned by Apple. C is much too low level and other languages are either niche languages or too domain specific. The only realistic choices for a mobile platform were and still are C++, C# and Java.</p>
<p>Should Google have picked C++? They didn&#8217;t have a programming library: by the time Android 1.1 was released, Trolltech had already been bought by Nokia. It&#8217;s really hard to create a quality C++ library from scratch, and they probably didn&#8217;t care to deal with a third party like Nokia.</p>
<p>What about C#? Google (and pretty much any company) prefers to own the core technologies and decide their fates. If they would have picked C#, Microsoft would have had an important word to say when it came to Android&#8217;s future. That left them with Java. It&#8217;s popular. It&#8217;s also easy to learn, has good enough performance and a massive class library. The only problem were the licensing fees that they had to pay to Sun, but they got around them &#8211; or so they thought before Oracle &#8211; with Dalvik.</p>
<p>In the end, was Java a good choice? Before the Oracle lawsuit, it seemed so, but Google couldn&#8217;t know that Oracle would buy the friendly Sun. They will bitterly fight Oracle, since they have too much of an investment in Java and Dalvik now.</p>
<p>In the mean time, I wonder if anyone inside Google is looking at Java alternatives. There&#8217;s already a Qt port for Android, and some official Google love wouldn&#8217;t hurt at all.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeimproved.net/2010/10/virtual-machines-on-telephones-google-didnt-have-much-choice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What&#8217;s wrong with C++</title>
		<link>http://blog.codeimproved.net/2010/07/whats-wrong-with-c/</link>
		<comments>http://blog.codeimproved.net/2010/07/whats-wrong-with-c/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 21:37:50 +0000</pubDate>
		<dc:creator>razvanpetru</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://blog.codeimproved.net/?p=202</guid>
		<description><![CDATA[&#8230;from the point of view of someone that actually uses it? The bits from my last post haven&#8217;t even dried up yet, and another fascinating rant about C++ has popped up, this time from Zed Shaw. What&#8217;s interesting about these rants is that the ranter isn&#8217;t really using C++. They&#8217;re C hackers, or they program [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230;from the point of view of someone that actually uses it? The bits from my last post haven&#8217;t even dried up yet, and  another fascinating rant about C++ has popped up, this time from Zed Shaw.</p>
<p>What&#8217;s interesting about these rants is that the ranter isn&#8217;t really using C++. They&#8217;re C hackers, or they program mostly in Python, or they used C++ at the beginning of the 90s. So I thought it would be interesting to write about my experience with C++.</p>
<p>First, a little background info&#8230;</p>
<p>I started learning C++ about 10 years ago, first the C part and then the ++ part. Nothing serious, just toying around with small projects to learn and have fun. I didn&#8217;t use it professionally until about four and a half years ago, when I started working on a large scale C++ project. Since then I&#8217;ve used it almost daily.</p>
<p>Two and a half years ago I came across Qt almost by accident: the large scale project that I was working on was being ported to Linux and the port was enabled by Qt. Since then, I&#8217;ve used Qt almost daily too.</p>
<p>Right now I&#8217;m working on a  Qt C++ project that&#8217;s about 25KLOC in size and growing. It&#8217;s a multi-platform, threaded client-server and it&#8217;s a line of bussiness app if you&#8217;d believe it. Working on it is fun, and I&#8217;m glad that I picked Qt and C++.</p>
<p>Okay, enough with the history, what about C++ and its warts?</p>
<h3>Issues that bother me in practice</h3>
<ul>
<li>Compile times and the include dependency specification: this is a problem that every C++ programmer will have sooner or later. It can be delayed and mitigated with a <a href="http://blog.codeimproved.net/2009/03/the-large-scale-c-software-design-rules-in-practice/" target="_blank">good physical design</a>, precompiled headers and distributed compilers/linkers, but it can&#8217;t be solved without throwing away compatibility to existing code completely.</li>
<li>The small standard library: not a big issue in itself, since you can find other libraries for anything you might want to do, but it&#8217;s unpleasant to install all those libraries and make sure that they work together nicely. Using more libraries instead of a large standard library also means that you have to wait on each library vendor to port the library to different OSes/compilers, upgrade it and so on.</li>
<li>lack of reflection: I like <a href="http://doc.trolltech.com/latest/moc.html">Qt&#8217;s moc</a> and I miss it in standard C++. I also wish it had more features.</li>
<li>lack of type inference: even with typedefs I&#8217;m typing more than I have to. C++0x will thankfully fix this.</li>
<li>localization &amp; internationalization support in the standard library: the implementation is complicated and difficult to use. After browsing through <a href="http://www.angelikalanger.com/iostreams.html" target="_blank">C++ IOstreams and locales</a> I&#8217;ve decided to just use Qt and not worry about it.</li>
<li>template error messages: they&#8217;re long and hard to understand. I usually  parse a template error message in about 10-20 seconds depending on the  difficulty. The worst offenders are metaprogramming-heavy libraries such  as Boost Spirit. In that case, I try to analyze the code first and see  what might be wrong. <a href="http://www.bdsoft.com/tools/stlfilt.html">STLFilt</a> can  help.</li>
<li>functional programming support: this will get better in C++0x, but I  can&#8217;t use C++0x now, at least not on all platforms and with the other  libraries I&#8217;m using. Functors and free functions are cumbersome to use with algorithms.</li>
<li>tools and parsing: C++ has access to solid, mature tools, but those  tools are much harder to develop than for other languages and generally  don&#8217;t have as many features.</li>
</ul>
<h3>Issues that don&#8217;t bother me at all, but are regularly brought up in rants</h3>
<ul>
<li>memory management: never a problem for me. The last time I&#8217;ve had a memory leak was about two years ago and it got caught at code review. C++ has good support for memory management and good tools that can be used for runtime debugging. It might as well have GC, I wouldn&#8217;t be able to tell the  difference.</li>
<li>memory corruption: memory corruption can be both exciting and scary. Exciting because you have to go down to the memory address level and do some sleuthing, scary because it can take days or weeks to find some bugs. I usually don&#8217;t sweat these bugs, they were very rare in the code I&#8217;ve worked on, and when they occurred they were easily found. e.g: the last one I&#8217;ve solved in maybe  30 seconds, the tools have gotten very good. The worst I&#8217;ve encountered was a problem with an embedded STL in a large project that took a week to figure out and only because of my lack of experience at that time. <a href="http://www.dumpanalysis.org/">Some people</a> love debugging.</li>
<li>multi-threading: it is hard in most languages. The trick is using higher-level libraries such as QtConcurrent, Intel&#8217;s TBB or OpenMP. Sure, if you&#8217;re doing PThreads it&#8217;s going to be painful.</li>
<li>string formatting and string support: I generally don&#8217;t use iostreams or std::string, but when I did I found them acceptable. Unicode support was the biggest issue, but &#8220;there&#8217;s a <span style="text-decoration: line-through">app</span>lib for that&#8221;. Now I use Qt&#8217;s strings and streams; they&#8217;re as easy to use as Python as far as I&#8217;m concerned. Don&#8217;t want Qt? Use boost::format or any other of the nice formatting libraries.</li>
<li>templates in general: I use them when needed to break dependencies, write generic code, etc. I try to keep template code manageable, without going into the metaprogramming stuff; they are one of my favourite C++ features.</li>
<li>exception rules: I don&#8217;t see any problem with exceptions in C++ as long as you&#8217;re using RAII. Other languages (e.g.: Python) use them extensively for error handling.</li>
<li>STL &amp; Boost: I&#8217;ve used both for a lot of time and I find them very useful. Contrary to popular belief, most templates don&#8217;t use metaprogramming techniques. You don&#8217;t have to install Boost, it&#8217;s mostly headers. A large part of Boost became TR1 so it should even ship with your compiler now.</li>
<li>const: This one came from Zed, I don&#8217;t think I&#8217;ve seen that many people complain about const. Personally, I constify everything that I can, even const type* const.</li>
<li>everybody learns a different 10% of C++: strange, because I use all of it and always have. It&#8217;s not that hard either, I&#8217;m not a genius&#8230; Sane projects have coding guidelines and architectural documents. If your teammate can waltz right in with a template metaprogram or is generally macro-happy and it doesn&#8217;t raise eyebrows at code review, you have bigger problems than using C++. I&#8217;ve had to fix two C++ projects so far; my only job was to do what it takes to make the programs work and ship them to the customer. Most problems were memory leaks, superfluous use of casts, functions that didn&#8217;t compile on all platforms and so on. Fixable. What I couldn&#8217;t fix &#8211; and had to patch up as best as possible &#8211; were issues with the program logic and architecture. Those were not caused by C++.</li>
</ul>
<h3>Ok, but what about&#8230;</h3>
<p>You probably have your favourite C++ misfeatures.  Odds are that they don&#8217;t matter than much in practice, or workarounds are available. Maybe I just got used to them and consider them a C++ tax.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeimproved.net/2010/07/whats-wrong-with-c/feed/</wfw:commentRss>
		<slash:comments>66</slash:comments>
		</item>
		<item>
		<title>Getting rid of the Nokia Qt SDK warnings</title>
		<link>http://blog.codeimproved.net/2010/06/getting-rid-of-the-nokia-qt-sdk-warnings/</link>
		<comments>http://blog.codeimproved.net/2010/06/getting-rid-of-the-nokia-qt-sdk-warnings/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 15:31:58 +0000</pubDate>
		<dc:creator>razvanpetru</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Nokia]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[Symbian]]></category>

		<guid isPermaLink="false">http://blog.codeimproved.net/?p=180</guid>
		<description><![CDATA[When the SDK beta came out, I posted a topic on Forum Nokia about the warnings emitted when compiling Qt Symbian programs. I also opened a bug report in the Qt bug tracker at the suggestion of Christian Kamm, but the warnings come from the Symbian headers, so it is unlikely that the Qt team [...]]]></description>
			<content:encoded><![CDATA[<p>When the SDK beta came out, I <a href="http://discussion.forum.nokia.com/forum/showthread.php?199397-Nokia-Qt-SDK-Compiler-warnings-and-breakpoints-not-working&amp;p=730244" target="_blank">posted a topic</a> on Forum Nokia about the warnings emitted when compiling Qt Symbian programs. I also opened a bug report in the Qt bug tracker at the suggestion of Christian Kamm, but the warnings come from the Symbian headers, so it is unlikely that the Qt team can do much about it.</p>
<p>Here&#8217;s a workaround:</p>
<ul>
<li>Add the flags  -Wno-attributes -Wno-parentheses to the Symbian compiler flags. This will fix the <em>dllimport </em>warnings and the <em>&#8220;recommend parentheses around&#8230;&#8221;</em> warnings. e.g: <em>symbian {QMAKE_CXXFLAGS += -Wno-attributes -Wno-parentheses}</em></li>
<li>Edit the file e32cmn.inl and replace the C-casts at the warning lines with reinterpret_cast. e.g: <em>(const TSecureId&amp;)iId</em> will become <em>reinterpret_cast&lt;const TSecureId&amp;&gt;(iId). </em>The conversion seems to be correct, even though the implementation is hack-ish.<em><br />
</em></li>
</ul>
<p>In one project &#8211; after doing the two changes outlined above &#8211; the warning count was cut from ~4000 to about 41. There weren&#8217;t 4000 real warnings, more like ~100 but Qt Creator counts each warning line as a warning (this might be a bug).</p>
<p>The remaining warnings were:</p>
<ol></ol>
<ul>
<li>d32locd.h:189: warning: invalid access to non-static data member &#8216;TLocalDriveCaps::iSize&#8217; of NULL object</li>
<li>d32locd.h:190: warning: invalid access to non-static data member &#8216;TLocalDriveCapsV3::iFormatInfo&#8217; of NULL object</li>
<li>openfont.h:2549: warning: invalid access to non-static data member &#8216;COpenFontRasterizer::iDtor_ID_Key&#8217; of NULL object</li>
<li>openfont.h:2571: warning: invalid access to non-static data member &#8216;CShaperFactory::iDtor_ID_Key&#8217; of NULL object</li>
<li>biditext.h:12: warning: declaration &#8216;enum CGraphicsContext::TTextAlign&#8217; does not declare anything</li>
</ul>
<ol></ol>
<p>1-4 seem to be related to the use of the _FOFF macro., but I didn&#8217;t do any detailed analysis.</p>
<div style="width: 1px;height: 1px;overflow: hidden">
<p>symbian {</p>
<pre style="margin: 0px;text-indent: 0px">    QMAKE_CXXFLAGS += -Wno-attributes -Wno-parentheses</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeimproved.net/2010/06/getting-rid-of-the-nokia-qt-sdk-warnings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QsLog now on Symbian</title>
		<link>http://blog.codeimproved.net/2010/05/qslog-now-on-symbian/</link>
		<comments>http://blog.codeimproved.net/2010/05/qslog-now-on-symbian/#comments</comments>
		<pubDate>Sat, 15 May 2010 12:44:49 +0000</pubDate>
		<dc:creator>razvanpetru</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[Symbian]]></category>

		<guid isPermaLink="false">http://blog.codeimproved.net/?p=150</guid>
		<description><![CDATA[I have ported my Qt logger to Symbian and it&#8217;s available for download from the usual bitbucket repository. The port didn&#8217;t involve many changes: I have fixed a bunch of warnings caused  by the Symbian GCC not liking if(); These could have probably been disabled with compiler options, but I just replaced the ; with [...]]]></description>
			<content:encoded><![CDATA[<p>I have ported my Qt logger to Symbian and it&#8217;s available for download from the usual <a href="http://bitbucket.org/razvanpetru/qt-components/downloads" target="_blank">bitbucket repository</a>.</p>
<p>The port didn&#8217;t involve many changes:</p>
<ul>
<li>I have fixed a bunch of warnings caused  by the Symbian GCC not liking if(); These could have probably been disabled with compiler options, but I just replaced the ; with an empty block.</li>
<li>I have added Symbian-specific debug output. The logging output will be captured by Qt Creator and shown in the &#8220;Application output&#8221; view.</li>
</ul>
<p>Via Lucian from Symbian dev foundation I found out that the recommended folder to place your logs on Symbian  is c:/Logs/&lt;dir&gt;. I use the program name as &lt;dir&gt;, but it&#8217;s not mandatory.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeimproved.net/2010/05/qslog-now-on-symbian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)

Served from: blog.codeimproved.net @ 2012-02-05 19:32:02 -->
