<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Weiqi Gao&#039;s Observations - scripting tag</title>
  <link>http://www.weiqigao.com/blog/tags/scripting/</link>
  <description>Sharing My Experience...</description>
  <language>en</language>
  <copyright>Weiqi Gao</copyright>
  <lastBuildDate>Fri, 11 May 2012 12:48:36 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  <image>
    <url>http://pebble.sourceforge.net/common/images/powered-by-pebble.gif</url>
    <title>Weiqi Gao&#039;s Observations</title>
    <link>http://www.weiqigao.com/blog/</link>
  </image>
  
  
  <item>
    <title>Unit Tests Are Not Enough</title>
    <link>http://www.weiqigao.com/blog/2007/09/26/unit_tests_are_not_enough.html</link>
    
      
        <description>
          &lt;p&gt;The new and improved &lt;a href= &#034;http://stuffthathappens.com/blog/&#034; &gt;It&#039;s Just a Bunch of Stuff That Happens&lt;/a&gt;&amp;mdash;which went off the air briefly, as I noted &lt;a href= &#034;http://www.weiqigao.com/blog/2007/08/20/my_shrinking_blogroll.html&#034; &gt;37 days ago&lt;/a&gt;&amp;mdash;is back with renewed, focused energy and is as penetratingly insightful as ever.&lt;/p&gt;

&lt;p&gt;In a &lt;a href= &#034;http://stuffthathappens.com/blog/2007/09/25/paying-my-taxes/&#034; &gt;post yesterday&lt;/a&gt;, Eric gave a concrete example of the drawback of lack of static typing in Ruby:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;The second bug took me far longer to understand and was more insidious. In Ruby you don’t even have to say “return” at the end of a method. Instead, the result of whatever expression happened last is automatically returned. Invisible magic is the quintessential example of a feature that saves the original coder a few extra keystrokes but makes every downstream programmer pay the continuous tax for years to come.&lt;/p&gt;

&lt;p&gt;I made the problem worse by adding a simple “if” statement to the end of the method, thinking I could explicitly change a bogus error message to nil. But now the method didn’t even return a string any more…I inadvertently changed the return type from a string to a boolean.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To which I commented without too much thinking:&lt;/p&gt;

&lt;blockquote&gt;Had you made a similar return-type-altering change in Java, the compiler would have caught it as an error.  In that regard, the static typing works just like unit tests&amp;mdash;it prevents you from breaking your code.&lt;/blockquote&gt;

&lt;p&gt;This post became the topic of discussion at OCI North this morning.  Brian mentioned that he has been bitten by the same problem in a Ruby script he wrote recently.  He also pointed out that no amount of unit tests will guarantee that a function will return data of a specific type.&lt;/p&gt;

&lt;p&gt;Suppose you want to write a function that takes a string and return a boolean in a dynamically typed language, and you want the function to return &lt;tt&gt;true&lt;/tt&gt; for inputs like &lt;tt&gt;&#034;yes&#034;&lt;/tt&gt;, &lt;tt&gt;&#034;true&#034;&lt;/tt&gt; and &lt;false&lt;/tt&gt; for inputs like &lt;tt&gt;&#034;no&#034;&lt;/tt&gt;, &lt;tt&gt;&#034;false&#034;&lt;/tt&gt;.  So you write your unit tests stating these requirements.   And you may choose to implement this function like this (in pseudo-code):&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;def foo(input) {
  if input is &#034;yes&#034; return true
  if input is &#034;true&#034; return true
  if input is &#034;no&#034; return false
  if input is &#034;false&#034; return false
}&lt;/pre&gt;

&lt;p&gt;However, you cannot write a unit test that will make sure this function always returns a boolean.  You can write a specific test that prevents the following code from spoiling the function:&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;  if input is &#034;weiqi&#034; return &#034;gao&#034;&lt;/pre&gt;

&lt;p&gt;But that test cannot prevent the next spoiler, and the next, and the next, ...&lt;/p&gt;

&lt;p&gt;In this sense, a statically declared return type of boolean for the function can be thought of as the equivalent of an infinitely many unit tests.&lt;/p&gt;

&lt;p&gt;The conclusion:&lt;/p&gt;

&lt;center&gt;&lt;span style=&#034;color:red;font-size:Large&#034;&gt;If unit tests are good, static typing is better!&lt;/span&gt;&lt;/center&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2007/09/26/unit_tests_are_not_enough.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2007/09/26/unit_tests_are_not_enough.html</guid>
    <pubDate>Thu, 27 Sep 2007 04:20:16 GMT</pubDate>
  </item>
  
  <item>
    <title>Widening The JVM Language Group: They Need Us!</title>
    <link>http://www.weiqigao.com/blog/2007/08/09/widening_the_jvm_language_group_they_need_us.html</link>
    
      
        <description>
          &lt;p&gt;&lt;em&gt;(Via &lt;a href= &#034;http://www.tbray.org/ongoing/When/200x/2007/08/08/Tech-Tab-Sweep&#034; &gt;Tim Bray&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;&lt;h4&gt;Widening the JVM Languages Group: We Need You!&lt;/h4&gt;
&lt;p&gt;&lt;a href= &#034;http://headius.blogspot.com/2007/08/widening-jvm-languages-group-we-need.html&#034; &gt;Charles Nutter&lt;/a&gt;: We need diversity in the &lt;a href=&#034;http://groups.google.com/group/jvm-languages&#034;&gt;JVM Languages group&lt;/a&gt;, and it&#039;s been brought to my attention that some popular/key/interesting languages may not have representation. So we need to change that.&lt;/p&gt;

&lt;p&gt;If you are interested in the future of non-Java languages on the JVM, you should be on this list. Yes, we talk about a lot of JVM lanuage implementation challenges, we discuss compilers and stack frames and call-site optimizations, but we also talk about features peripheral to language implementation like package indexing and retrofitting Java 5+ code. We need your help.&lt;/p&gt;

&lt;p&gt;Once you&#039;ve joined, or if you&#039;re already member, you have a second task&lt;/p&gt;

&lt;p&gt;I respectfully request that each of you search out one individual you think would be interested in the list and try to get them involved. Toss them a quick email, invite them to describe their project or language or implementation to us, and promise them they&#039;re joining a very interesting and entertaining community. History will thank you, and so will I.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I joined the &lt;a href= &#034;http://groups.google.com/group/jvm-languages&#034; &gt;JVM Language Group&lt;/a&gt; project when Charles &lt;a href= &#034;http://headius.blogspot.com/2007/05/jvm-languages-future.html&#034; &gt;announced it&lt;/a&gt; the first time around 74 days ago.  Although language design and implementation is not my specialty, watching others discuss it is still a lot of fun.&lt;/p&gt;

&lt;p&gt;One thing I noticed, for a long time now, is Charles&#039;s healthy respect for the other JVM languages, especially &lt;a href= &#034;http://headius.blogspot.com/2006/11/jython-alive-and-well-and-looking-for.html&#034; &gt;Jython&lt;/a&gt;, which has been around for more than ten years now.  That is so unlike the other Ruby guys that I encounter online.&lt;/p&gt;

&lt;p&gt;The goal of the group is to come up with something, some sort of a library or &amp;lt;shudder&amp;gt;framework&amp;lt;/shudder&amp;gt;, that would aid the implementation of JVM languages, as well as a forum for other discussions.&lt;/p&gt;

&lt;p&gt;I think you want to join even if you are not a language guy.  After all, JRuby, (or Jython, or Groovy, or whatever), is just a big Java program.&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2007/08/09/widening_the_jvm_language_group_they_need_us.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2007/08/09/widening_the_jvm_language_group_they_need_us.html</guid>
    <pubDate>Thu, 09 Aug 2007 12:54:56 GMT</pubDate>
  </item>
  
  <item>
    <title>Kawa 1.9.0 Released</title>
    <link>http://www.weiqigao.com/blog/2007/01/22/kawa_1_9_0_released.html</link>
    
      
        <description>
          &lt;blockquote&gt;
&lt;p&gt;&lt;a href= &#034;http://sources.redhat.com/ml/kawa/2007-q1/msg00021.html&#034; &gt;Per Bothner on the Kawa mailing list&lt;/a&gt;: I&#039;ve released Kawa 1.9.0, and updated the web pages.  Please try the .tar.gz and/or .jar and let me know of any problems.  Here is the list of recent (and not-so-recent) changes.  &lt;a href=&#034;http://www.gnu.org/software/kawa/news.html&#034;&gt;http://www.gnu.org/software/kawa/news.html&lt;/a&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For people who are not familiar with it, Kawa is language development framework for the JVM together with an implementation of the &lt;a href= &#034;http://www.schemers.org/&#034; &gt;Scheme&lt;/a&gt; programming language and an implementation of the &lt;a href= &#034;http://www.w3.org/XML/Query/&#034; &gt;XQuery&lt;/a&gt; language.  It compiles these languages into Java bytecodes.&lt;/p&gt;

&lt;p&gt;It is in Kawa that I first saw the technique of compiling scripts from the interactive shell into Java bytecode and then load and execute them.&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2007/01/22/kawa_1_9_0_released.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2007/01/22/kawa_1_9_0_released.html</guid>
    <pubDate>Mon, 22 Jan 2007 16:25:33 GMT</pubDate>
  </item>
  
  </channel>
</rss>

