<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: The Ascendency of Dynamic X vs. Static X, where X = ...</title>
    <link>http://blog.objectmentor.com/articles/2008/07/26/the-ascendency-of-dynamic-x-_vs-_-static-x-where-x</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>The Ascendency of Dynamic X vs. Static X, where X = ...</title>
      <description>&lt;p&gt;I noticed a curious symmetry the other day. For several values of &lt;em&gt;X&lt;/em&gt;, a dynamic approach has been gaining traction over a static approach, in some cases for several years.&lt;/p&gt;


	&lt;h2&gt;X = Languages&lt;/h2&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&lt;em&gt;The Ascendency of Dynamic Languages vs. Static Languages&lt;/em&gt;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;This one is pretty obvious. It&amp;#8217;s hard not to notice the resurgent interest in dynamically-typed languages, like Ruby, Python, Erlang, and even stalwarts like Lisp and Smalltalk.&lt;/p&gt;


	&lt;p&gt;There is a healthy debate about the relative merits of dynamic &lt;em&gt;vs.&lt;/em&gt; static typing, but the &amp;#8220;hotness&amp;#8221; factor is undeniable.&lt;/p&gt;


	&lt;h2&gt;X = Correctness Analysis&lt;/h2&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&lt;em&gt;The Ascendency of Dynamic Correctness Analysis vs. Static Correctness Analysis&lt;/em&gt;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;Analysis of code to prove correctness has been a research topic for years and the tools have become pretty good. If you&amp;#8217;re in the Java world, tools like &lt;a href="http://pmd.sourceforge.net/"&gt;&lt;span class="caps"&gt;PMD&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://findbugs.sourceforge.net/"&gt;FindBugs&lt;/a&gt; find a lot of real and potential issues.&lt;/p&gt;


	&lt;p&gt;One thing none of these tools have ever been able to do is to analyze conformance of your code to your project&amp;#8217;s &lt;em&gt;requirements&lt;/em&gt;. I suppose you could probably build such tools using the same analysis techniques, but the cost would be too prohibitive for individual projects.&lt;/p&gt;


	&lt;p&gt;However, while analyzing the code statically is very hard, watching what the code actually does at runtime is more tractable and cost-effective, using automated tests.&lt;/p&gt;


	&lt;p&gt;Test-driving code results in a suite of unit, feature, and acceptance tests that do a good enough job, for most applications, of finding logic &lt;em&gt;and&lt;/em&gt; requirements bugs. The way test-&lt;em&gt;first&lt;/em&gt; development improves the design helps ensure correctness in the first place.&lt;/p&gt;


	&lt;p&gt;It&amp;#8217;s worth emphasizing that automated tests exercise the code using &lt;em&gt;representative&lt;/em&gt; data sets and scenarios, so they don&amp;#8217;t constitute a proof of correctness. However, they are good enough for most applications.&lt;/p&gt;


	&lt;h2&gt;X = Optimization&lt;/h2&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&lt;em&gt;The Ascendency of Dynamic Optimization vs. Static Optimization&lt;/em&gt;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;Perhaps the least well known of these &lt;em&gt;X&lt;/em&gt;&amp;#8217;s is optimization. Mature compilers like &lt;a href="http://gcc.gnu.org/"&gt;gcc&lt;/a&gt; have sophisticated optimizations based on static analysis of code (you can see where this is going&amp;#8230;).&lt;/p&gt;


	&lt;p&gt;On the other hand, the javac compiler does not do a lot of optimizations. Rather, the &lt;span class="caps"&gt;JVM&lt;/span&gt; does.&lt;/p&gt;


	&lt;p&gt;The &lt;span class="caps"&gt;JVM&lt;/span&gt; watches the code execute and it performs optimizations the compiler could never do, like speculatively inlining polymorphic method calls, based on which types are actually having their methods invoked. The &lt;span class="caps"&gt;JVM&lt;/span&gt; puts in low-overhead guards to confirm that its assumptions are valid for each invocation. If not, the &lt;span class="caps"&gt;JVM&lt;/span&gt; &lt;em&gt;de-optimizes&lt;/em&gt; the code.&lt;/p&gt;


	&lt;p&gt;The &lt;span class="caps"&gt;JVM&lt;/span&gt; can do this optimization because it sees how the code is really used at runtime, while the compiler has no idea when it looks at the code.&lt;/p&gt;


	&lt;p&gt;Just as for correctness analysis, static optimizations can only go so far. Dynamic optimizations simply bypass a lot of the difficulty and often yield better results.&lt;/p&gt;


	&lt;p&gt;Steve Yegge provided a nice &lt;a href="http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html"&gt;overview&lt;/a&gt; recently of &lt;span class="caps"&gt;JVM&lt;/span&gt; optimizations, as part of a larger discussion on dynamic languages.&lt;/p&gt;


	&lt;p&gt;&lt;br/&gt;
There are other dynamic &lt;em&gt;vs.&lt;/em&gt; static things I could cite (think networking), but I&amp;#8217;ll leave it at these three, for now.&lt;/p&gt;</description>
      <pubDate>Sat, 26 Jul 2008 21:48:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:80de9d7c-10cc-41a1-8d98-eb71a637b37a</guid>
      <author>Dean Wampler</author>
      <link>http://blog.objectmentor.com/articles/2008/07/26/the-ascendency-of-dynamic-x-_vs-_-static-x-where-x</link>
      <category>Dean's Deprecations</category>
      <category>Dynamic Languages</category>
      <category>dynamic</category>
      <category>static</category>
      <category>languages</category>
      <category>correctness</category>
      <category>optimization</category>
    </item>
  </channel>
</rss>
