<?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>Josh Haberman &#187; upb</title>
	<atom:link href="http://blog.reverberate.org/tag/upb/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.reverberate.org</link>
	<description>parsing, performance, minimalism with C99</description>
	<lastBuildDate>Wed, 02 Dec 2009 20:45:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Porting upb to C++?</title>
		<link>http://blog.reverberate.org/2009/11/28/porting-upb-to-c/</link>
		<comments>http://blog.reverberate.org/2009/11/28/porting-upb-to-c/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 20:53:02 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[upb]]></category>

		<guid isPermaLink="false">http://blog.reverberate.org/?p=287</guid>
		<description><![CDATA[I am on the verge of trying something I never thought I&#8217;d do.  I&#8217;m considering porting upb to C++.
My reasons aren&#8217;t ideological, they are highly practical.  Basically I am realizing that while object-oriented C is OK for a while, it&#8217;s very weak at inheritance.  Inheritance in C involves a lot of casting, [...]]]></description>
			<content:encoded><![CDATA[<p>I am on the verge of trying something I never thought I&#8217;d do.  I&#8217;m considering porting upb to C++.</p>
<p>My reasons aren&#8217;t ideological, they are highly practical.  Basically I am realizing that while object-oriented C is OK for a while, it&#8217;s very weak at inheritance.  Inheritance in C involves a lot of casting, duplicated code and/or macros, and careful discipline.  The main problems with this are:
<ul>
<li>the code gets longer and less readable</li>
<li>the code involves more possibly-unsafe operations like casts</li>
</ul>
<p>Both of these problems make the code ultimately more difficult to audit for security.  And getting upb audited for security is something I plan to do very soon.</p>
<p>I am coming to believe that porting to C++ would make upb smaller (in lines of code) and easier for verify for security.  However, there are a few major disadvantages that are giving me pause:
<ul>
<li>there are still some contexts in which C++ is a no-go, like the Linux kernel, embedded systems that only have a C compiler (but no C++), or projects that want to stay C-only.  Doing this port would make upb unsuitable for these contexts.</li>
<li>projects that are currently C-only would need to create C++ source files to call upb APIs, and will have to link in the C++ runtime
<li>(possible) C++ could result in a larger binary.</li>
</ul>
<p>When I look at the downsides though, they don&#8217;t seem to pertain to my initial goals of making upb useful for Python, Lua, Ruby, etc. extensions, and for use inside Google.  Being useful for really restricted embedded systems is a far-off use case.  So it&#8217;s sounding like porting to C++ is the right thing to do.</p>
<p>I hope it significantly reduces the line count, as I expect it will.  That will make me feel better about giving up the minimalism of C.  I will definitely be compiling with <tt>-fno-exceptions -fno-rtti -fvisibility-inlines-hidden</tt> on gcc.  I also won&#8217;t be using any of the C++ standard library (not even &lt;string&gt;).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.reverberate.org/2009/11/28/porting-upb-to-c/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
