<?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>Honest to a Segfault &#187; JIT</title>
	<atom:link href="http://blog.cdleary.com/tag/jit/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cdleary.com</link>
	<description>__author__ = &#039;Chris Leary&#039;</description>
	<lastBuildDate>Sun, 05 Sep 2010 20:41:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Thoughts on self-modifying code and Futurist Programmers</title>
		<link>http://blog.cdleary.com/2008/09/thoughts-on-self-modifying-code-and-futurist-programmers/</link>
		<comments>http://blog.cdleary.com/2008/09/thoughts-on-self-modifying-code-and-futurist-programmers/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 08:36:51 +0000</pubDate>
		<dc:creator>cdleary</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Efficiency]]></category>
		<category><![CDATA[Futurist Programmers]]></category>
		<category><![CDATA[JIT]]></category>
		<category><![CDATA[Self-Modifying]]></category>

		<guid isPermaLink="false">http://blog.cdleary.com/?p=177</guid>
		<description><![CDATA[Around 8th grade I read an article about a faction of programmers &#8212; the Futurist Programmers &#8212; whose rallying cry is paraphrased in the following quotation: Why does computer science reject self modifying programs? Why have some departments stopped teaching assembly language programming? On what scientific basis has this been done? Where is the experimental [...]]]></description>
			<content:encoded><![CDATA[<p>Around 8th grade I read an article about a faction of programmers &#8212; the Futurist Programmers &#8212; whose <a class="reference external" href="http://www.graficaobscura.com/future/index.html">rallying cry</a> is paraphrased in the following quotation:</p>
<blockquote><p>
Why does computer science reject self modifying programs?  Why have some departments stopped teaching assembly language  programming?  On what scientific basis has this been done? Where is the experimental evidence to support these actions?</p></blockquote>
<p>As far as I remember, this movement attempted to emphasize the <em>purity</em> of computer programming, which they believed was a form of artistry. This was posed as a throwback to the tenets Italian Futurism, which were opposed to tradition and commoditization, in the context of computer programming. A <a class="reference external" href="http://en.wikipedia.org/wiki/Futurism_(art)">Wikipedia excerpt</a> will probably be helpful:</p>
<blockquote><p>
The Futurists admired <a class="reference external" href="http://en.wikipedia.org/wiki/Speed">speed</a>, <a class="reference external" href="http://en.wikipedia.org/wiki/Technology">technology</a>, youth and <a class="reference external" href="http://en.wikipedia.org/wiki/Violence">violence</a>, the car, the plane and the industrial city, all that represented the technological triumph of humanity over <a class="reference external" href="http://en.wikipedia.org/wiki/Nature">nature</a>, and they were passionate nationalists.</p></blockquote>
<p>Thinking about JavaScript Just In Time compilers (JITs) today &#8212; like <a class="reference external" href="https://wiki.mozilla.org/JavaScript:TraceMonkey">TraceMonkey</a> &#8212; reminded me of this philosophy. I believe that their line of questioning was insightful, but the formulation was misdirected. Technological triumph stems primarily from computers doing what humans want them to do. It&#8217;s additionally awesome if the computers can do these things extra quickly; however, if they do things incorrectly very quickly, humanity comes out much less triumphant. Perhaps we even come out <a class="reference external" href="http://en.wikipedia.org/wiki/Therac-25">worse for the experience</a>.</p>
<p>Secondly, we note that humanity strives for the ability to make further progress based on the <em>success</em> of past experiences. This is the concept of <em>extensibility</em> and <em>reusability</em>. <a class="reference external" href="http://en.wikipedia.org/wiki/Standing_on_the_shoulders_of_giants">Standing on the shoulders of giants</a>, if you will. Self modifying code that I have encountered is often very <em>clever</em>; however, programming cleverness tends to be at odds with readability. <a class="footnote-reference" href="#id4" id="id1"><tt>[*]</tt></a> This is not to say that all self-modifying code is unreadable: in languages with dynamic method dispatch, swapping a object&#8217;s methods out (with some kind of locking mechanism) is a recognized idiom that can lead to beneficial efficiency/complexity trade-offs. <a class="footnote-reference" href="#id6" id="id2"><tt>[†]</tt></a></p>
<p>Ultimately, you&#8217;d have trouble finding computer enthusiasts who find speed unimportant. Everybody loves it when their computers are more efficient! The caveat is that most computer enthusiasts will, in many situations, put speed down here: after correctness and extensibility. As a testament to this, there is continuing emergence and acceptance of Very High Level Languages (VHLLs) over low level programming languages in non-academic contexts.</p>
<p>So how did the futurists have the right idea? &quot;Introspective&quot; programs are important. There&#8217;s lots of information at runtime that we can use to more efficiently execute programs. <a class="footnote-reference" href="#id10" id="id7"><tt>[‡]</tt></a> <a class="reference external" href="http://en.wikipedia.org/wiki/HotSpot">Hotspot JITs</a>, such as the aforementioned TraceMonkey,  know this well: the basic premise is that <a class="reference external" href="http://en.wikipedia.org/wiki/Self-modifying_code#Just-in-time_compilers">they dynamically rewrite the code they&#8217;re executing</a> or, in recent developments with Google&#8217;s V8, <a class="reference external" href="http://en.wikipedia.org/wiki/V8_JavaScript_engine">rewrite it before executing</a>. The key here is that we can now:</p>
<ol class="arabic simple">
<li>Write correct, extensible programs.</li>
<li>Write correct, extensible programs to optimize the programs from 1.</li>
<li>Run the more efficient result of combining 2 and 1.</li>
</ol>
<p><a class="reference external" href="http://en.wikipedia.org/wiki/Self-hosting">Self-hosting platforms</a> such as <a class="reference external" href="http://en.wikipedia.org/wiki/Pypy">PyPy</a> and <a class="reference external" href="http://en.wikipedia.org/wiki/LLVM">intermediary representation JITs such as LLVM</a> also show astonishing insight into introspective techniques. These platforms can be used to a number of ends, including, but not limited to, the increases in speed that the Futurist Programmers seem to be longing for.</p>
<p>In the end, I only have one rebuttal question for the Futurist Programmers: What kind of science disregards the accuracy and reproducibility of results for the sake of fast &quot;experiments&quot;? <a class="footnote-reference" href="#id15" id="id14"><tt>[§]</tt></a> We don&#8217;t reject self-modifying programs without consideration &#8212; there are very important maintainability and extensibility concerns that have to be taken into account before making a decision. It&#8217;s not always a choice between making <a class="reference external" href="http://en.wikipedia.org/wiki/Self-modifying_code#Henry_Massalin.27s_Synthesis_kernel">something artistically beautiful</a> or performing <a class="reference external" href="http://www.kernel.org/pub/linux/kernel/">a feat of engineering</a>: if most computer enthusiasts are like me, they&#8217;re searching for a way to produce an appropriate <a class="reference external" href="http://docs.python.org/dev/tutorial/index.html">mix of the two</a>.</p>
<div class="section" id="footnotes">
<h3>Footnotes</h3>
<table class="docutils footnote" frame="void" id="id4" rules="none">
<colgroup>
<col class="label" />
<col /></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id1"><tt>[*]</tt></a></td>
<td>This is generally recognized <a class="reference external" href="http://en.wikipedia.org/wiki/Python_(programming_language)#Programming_philosophy">within the Python community</a>.</td>
</tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id6" rules="none">
<colgroup>
<col class="label" />
<col /></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id2"><tt>[†]</tt></a></td>
<td>As an example of this, think of the singleton access pattern in a multithreaded application. After <tt class="docutils literal"><span class="pre">Singleton.get_instance()</span></tt> has instantiated the class on the first call, you could swap <tt class="docutils literal"><span class="pre">get_instance()</span></tt> with a method that simply returns the created reference. This avoids subsequent locking and singleton-instantiation checking that you would incur from the old <tt class="docutils literal"><span class="pre">get_instance()</span></tt> method.</td>
</tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id10" rules="none">
<colgroup>
<col class="label" />
<col /></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id7"><tt>[‡]</tt></a></td>
<td>I recommend the <a class="reference external" href="http://www.stanford.edu/class/ee380/ay0708.html">Steve Yegge talk on dynamic languages</a> for some more background on this topic.</td>
</tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id15" rules="none">
<colgroup>
<col class="label" />
<col /></colgroup>
<tbody valign="top">
<tr>
<td class="label"><a class="fn-backref" href="#id14"><tt>[§]</tt></a></td>
<td>What is an application if not a software engineer&#8217;s big, scary experiment?</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.cdleary.com/2008/09/thoughts-on-self-modifying-code-and-futurist-programmers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
