<?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>Cognitive Consonance &#187; Programming</title>
	<atom:link href="http://tiago.org/cc/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://tiago.org/cc</link>
	<description>Software engineering in a computational biology environment</description>
	<lastBuildDate>Mon, 06 Sep 2010 14:09:49 +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>A phylogenetic tree viewer in clojure</title>
		<link>http://tiago.org/cc/2009/11/16/a-phylogenetic-tree-viewer-in-clojure/</link>
		<comments>http://tiago.org/cc/2009/11/16/a-phylogenetic-tree-viewer-in-clojure/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 19:44:11 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[phylogenetics]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=160</guid>
		<description><![CDATA[Here is my first clojure application: A phylogenetic tree viewer (PhyloXML format). The obligatory screenshot: Preamble: This is newbie code: Handle with care! My main objective is not to make a tree viewer but a tree comparer. So this is no more than a learning step. You can test it yourself as it is a [...]]]></description>
			<content:encoded><![CDATA[<p>Here is my first clojure application: A phylogenetic tree viewer (PhyloXML format). The obligatory screenshot:</p>
<div id="attachment_172" class="wp-caption alignnone" style="width: 461px"><img src="http://tiago.org/cc/wp-content/uploads/2009/11/Screenshot-Simple.png" alt="Simple Phylogenetic viewer" title="Simple" width="451" height="480" class="size-full wp-image-172" /><p class="wp-caption-text">Simple Phylogenetic viewer</p></div>
<p>Preamble:</p>
<ol>
<li>This is newbie code: Handle with care! My main objective is not to make a tree viewer but a tree comparer. So this is no more than a learning step.</li>
<li>You can test it yourself as it is a Java WebStart application, just click <a href="http://popgen.eu/soft/tV/launch.jnlp">here</a>. You don&#8217;t need to have a phylogenetic tree file yourself. I supply an example inside.
         </li>
<li>This makes use of JGraph and Archaeopteryx (the PhyloXML parser)
</li>
</ol>
<p>I do maintain this code on github. I have <a href="http://github.com/tiagoantao/treeHugger">one project for the viewer</a> and <a href="http://github.com/tiagoantao/cljUtils">another for general utilities</a>. All the code is still very crude, but you might be interesting in stealing some of the <a href="http://github.com/tiagoantao/cljUtils/blob/master/src/org/tiago/swing.clj">swing code</a>, either as a crude example of how to interact with swing or taking my <a href="http://tiago.org/cc/2009/10/27/swing-menus-in-clojure/">micro-DSL for menus</a>. If you want to interact with JGraph, <a href="http://github.com/tiagoantao/cljUtils/blob/master/src/org/tiago/graph_vis.clj">this</a> might be a starting point. I don&#8217;t want, in any way, suggest that this code is any good. </p>
<p>Some lessons that I&#8217;ve learned and that I would like to share:</p>
<ol>
<li>Some of the clojure.contrib code is a bit green. I tried to use the graph library, but it is very small and specific. I ended up starting doing my own. Mine is even smaller and specific, no claims of generality.</li>
<li>I don&#8217;t appreciate some of the core functions of Clojure (I&#8217;ve written on this before and will write more in the near future). The great thing about Clojure is that you can import only what you want from the core and extend it yourself. I intend to do just that for my personal use. This is a PLUS point for Clojure: the flexibility that is made available to change many of the decisions of the language implementor (in the great tradition of declarative and homoiconic languages)
  </li>
<li>While I can change the core for my uses, I think defnk should really be core for everybody! I fact I wander if defn should not become defnk&#8230;</li>
<li>I am pretty sure that when *warn-on-reflection* is activated and action taken to correct the warnings, lots of code will increase in performance. With the more important side effect of annotating the code with type info.</li>
<li>I have quite a lot of recursive code that doesn&#8217;t use recur. Something to learn and master&#8230;</li>
<li>JGraph layout algorithms are not fantastic. I&#8217;ve tried with much bigger trees and the result was far from perfect (I also noticed performance problems in my own code).</li>
</ol>
<p>The biggest hurdle that I&#8217;ve found was the construction of user interfaces and how verbose Clojure Java interop can become. Of course one can create functions (and that was done) to create buttons, frames, menus, etc. But the creation of Java container structures (think frame contains menubar which contains menu with menus inside and so on) would benefit from a dialect where, when a certain (container) object was created it&#8217;s (Java) namespace would become easily available.</p>
<p>Imagine constructing a Structure like this:</p>
<pre>
MenuBar[
    Menu(File) [
        Menu(New)
        Menu(Close)
        Separator
        Menu
    ]
    Menu(Edit) [
        Menu(Cut)
        Menu(Paste)
    ]
]
</pre>
<p>it would be nice to be able to write something like:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>new JMenuBar<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;File&quot;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;New&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;Close&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>addSeparator<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;Edit&quot;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;Cut&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;Paste&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>&#8220;add&#8221; and &#8220;addSeparator&#8221; are Java methods. All this would be dynamic against the Java object hierarchy (not a hand-written library!). Note that there is no doto special form (or variants) and, most importantly, note that, given a list (a b c d), if a is a Java object b c d are evaluated as methods of a. If b is (i (y x s)), x and s would be evaluated as methods of y, if they failed then as methods of a, if this fails interpreted as normal Clojure. Something like this (rough sketch).<br />
This would be useful, e.g., to construct Swing hierarchies by hand in a expedient way (not suggesting anything more, especially not to do big programs with outside scope).<br />
I am going to try to write some code that does this in the next few days.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;bodytext=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;notes=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;t=A%20phylogenetic%20tree%20viewer%20in%20clojure" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;annotation=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;description=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=A%20phylogenetic%20tree%20viewer%20in%20clojure%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;t=A%20phylogenetic%20tree%20viewer%20in%20clojure&opener=bm&amp;ei=UTF-8&amp;d=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/11/16/a-phylogenetic-tree-viewer-in-clojure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The 99 Prolog problems in Clojure</title>
		<link>http://tiago.org/cc/2009/11/11/the-99-prolog-problems-in-clojure/</link>
		<comments>http://tiago.org/cc/2009/11/11/the-99-prolog-problems-in-clojure/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 12:33:45 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[prolog]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=167</guid>
		<description><![CDATA[Here can be found an interesting effort to implement the 99 Prolog problems in Clojure. It is not clear to me that the exercise is conducted in the same way as the original one [Update: the author actually says this in the preamble]. Let me explain: The original Prolog problems are solved without the help [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://m.3wa.com/?p=426">Here</a> can be found an interesting effort to implement the <a href="https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/">99 Prolog problems</a> in Clojure.</p>
<p>It is not clear to me that the exercise is conducted in the same way as the original one [Update: the author actually says this in the preamble]. Let me explain:</p>
<p>The original Prolog problems are solved without the help of the (existing) Prolog libraries, just using the basic language mechanisms. They are a good at illustrating the underlying declarative power of Prolog.</p>
<p>For instance, problem 1, finding the last element of a list is solved with this in Prolog:</p>

<div class="wp_syntax"><div class="code"><pre class="prolog" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">% P01 (*): Find the last element of a list</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% my_last(X,L) :- X is the last element of the list L</span>
<span style="color: #666666; font-style: italic;">%    (element,list) (?,?)</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% Note: last(?Elem, ?List) is predefined</span>
&nbsp;
my<span style="color: #008080;">_last</span><span style="color: #009900;">&#40;</span><span style="color: #008080;">X</span><span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #008080;">X</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
my<span style="color: #008080;">_last</span><span style="color: #009900;">&#40;</span><span style="color: #008080;">X</span><span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span><span style="color: #008080;">_</span><span style="color: #339933;">|</span><span style="color: #008080;">L</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:-</span> my<span style="color: #008080;">_last</span><span style="color: #009900;">&#40;</span><span style="color: #008080;">X</span><span style="color: #339933;">,</span><span style="color: #008080;">L</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span></pre></div></div>

<p>Notice the in-code comment that &#8220;last is predefined&#8221;. In fact, using the Prolog library this could be done with a one liner:</p>

<div class="wp_syntax"><div class="code"><pre class="prolog" style="font-family:monospace;"><span style="color: #339933;">?-</span> last<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #800080;">1</span><span style="color: #339933;">,</span><span style="color: #800080;">2</span><span style="color: #339933;">,</span><span style="color: #800080;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #008080;">E</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
<span style="color: #008080;">E</span> <span style="color: #339933;">=</span> <span style="color: #800080;">3.</span></pre></div></div>

<p>The offered solution in Clojure is also a one liner:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">user<span style="color: #66cc66;">=&gt;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">last</span> <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">5</span> <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #cc66cc;">8</span></pre></div></div>

<p>Given a sufficiently large and clever library (and Clojure has a very nice library) all problems on the list could be solved with a one-liner.</p>
<p>In my opinion, an apples-to-apples comparison with the original solutions would not use the core library.<br />
It would probably be like this for the same problem:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>defn mylast <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">l</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>mynext <span style="color: #66cc66;">&#40;</span>next <span style="color: #b1b100;">l</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">nil</span>? mynext<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>first <span style="color: #b1b100;">l</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>mylast mynext<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Yep, next is in the core library also, but being a call to clojure.lang.RT, I think it is fair game to use it.</p>
<p>Ok, better yet, with recur, as it is on core (this is essentially a copy of the core version):</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>defn mylast <span style="color: #66cc66;">&#91;</span>s<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>next s<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>recur <span style="color: #66cc66;">&#40;</span>next s<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>first s<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The Prolog exercise exposes the declarativeness and expressive power of Prolog. The Clojure example exposes mostly the cleverness of the core library.</p>
<p>Both are interesting points of view (I am not criticizing the Clojure solution), but they cannot be used for comparison purposes.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;bodytext=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;notes=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;t=The%2099%20Prolog%20problems%20in%20Clojure" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;annotation=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=The%2099%20Prolog%20problems%20in%20Clojure&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;description=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=The%2099%20Prolog%20problems%20in%20Clojure&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=The%2099%20Prolog%20problems%20in%20Clojure%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;t=The%2099%20Prolog%20problems%20in%20Clojure&opener=bm&amp;ei=UTF-8&amp;d=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/11/11/the-99-prolog-problems-in-clojure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Concurrency and multicore CPU/GPUs are overhyped</title>
		<link>http://tiago.org/cc/2009/11/02/concurrency-and-multicore-cpugpus-are-overhyped/</link>
		<comments>http://tiago.org/cc/2009/11/02/concurrency-and-multicore-cpugpus-are-overhyped/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 14:07:47 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[concurrrent programming]]></category>
		<category><![CDATA[multicore]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=130</guid>
		<description><![CDATA[More than 10 years ago I participated in the development of an University IT system (the front- and backend to maintain grades and that sort of stuff). The system was based on a DB/2 backend (a very nice database system) with the business code stored on a Prolog interpreter (Prolog interpreter which was in-house developed) [...]]]></description>
			<content:encoded><![CDATA[<p>More than 10 years ago I participated in the development of an University IT system (the front- and backend to maintain grades and that sort of stuff). The system was based on a DB/2 backend (a very nice database system) with the business code stored on a Prolog interpreter (Prolog interpreter which was in-house developed) and the web backend being a Java servlet engine (the old JServ, the thingy pre-Tomcat from Apache). Prolog is famed to be slow, and Java (at that point in time) was very slow. Surprise, surprise&#8230; the bottleneck was on the DB/2 server. Eventually, as the system grow (and the database hardware was beefed up) the bottleneck come forward to the business and web tiers, but the problem was sorted by just adding more machines: The contention was on a bunch of parallel independent process, they could be run on separate machines.</p>
<p>The example above illustrates why the concurrency problem posed by multiple core CPUs and GPUs, might not be that much important:</p>
<ol>
<li>Many problems are not CPU bound anyway, and even if they are, the bottleneck might be elsewhere. Another example: I am the proud owner of 3 cheap, slow laptops (one being a netbook). For my use case I really don&#8217;t need faster applications, I wonder how many users really need more than they already have?</li>
<li>Even if more CPU/GPU power is needed, a loosely coupled model (without much interprocess communication and contention issues) might be enough. This is typically the case of many web apps, which can scale by just adding more computers which run independent processes.</li>
</ol>
<p>Concurrency, even with modern abstractions, is hard. It should be avoided if possible and it can be avoided in many applications. If it cannot be avoided, maybe a loosely coupled model is enough&#8230; Guido van Rossum <a href="http://mail.python.org/pipermail/python-3000/2007-May/007414.html">has a nice take on this issue</a>.</p>
<p>This is important as concurrency is being touted as an important criteria to evaluate languages. Modern functional languages (think Scala and Clojure) are being touted as a better option precisely because they are better to do concurrency (both because of functional &#8211; &#8220;no changing state&#8221; &#8211; programming and the availability of libraries implementing nice concurrency paradigms like actors).</p>
<p>When addressing this importance of this issue, I would propose, that people would ask themselves this: &#8220;Am I developing computationally intensive software?&#8221; and &#8220;If I am developing computationally intensive software, can I live with loosely coupled models of computation, preferably processes with no shared memory?&#8221;</p>
<p>This is not to say that there are not some cases where tightly coupled computing is a good idea. It is just that, this complex solution might be an overkill for many problems.</p>
<p>I would just like to add that I am not defending my cause, in fact it is quite the opposite. There is actually some content produced here, in the past, on how to tackle concurrent programming:</p>
<ol>
<li><a href="http://popgen.eu/soft/lositan">LOSITAN</a> &#8211; A multicore-aware Jython-based (Python for the JVM) Web Start application to do selection detection.</li>
<li>An introductory tutorial on concurrent computing targeting computational biologists &#8211; Part <a href="http://tiago.org/ps/2007/07/06/bioinformatics-multi-core-cpus-and-grid-computing-introduction-14/">1</a>, <a href="http://tiago.org/ps/2007/07/17/bioinformatics-multi-core-cpus-and-grid-computing-user-perspective-24/">2</a> and <a href="http://tiago.org/ps/2007/07/31/bioinformatics-multi-core-cpus-and-grid-computing-developer-perspective-34/">3</a></li>
</ol>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;bodytext=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;notes=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;t=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;annotation=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;description=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;t=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&opener=bm&amp;ei=UTF-8&amp;d=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/11/02/concurrency-and-multicore-cpugpus-are-overhyped/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Swing menus in Clojure</title>
		<link>http://tiago.org/cc/2009/10/27/swing-menus-in-clojure/</link>
		<comments>http://tiago.org/cc/2009/10/27/swing-menus-in-clojure/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 22:19:39 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=110</guid>
		<description><![CDATA[I am doing some development in Clojure (a Lisp type language for the JVM). Lisp as in a clone tailored for the JVM, not Lisp as only &#8220;functional programming&#8221;. I note, by the way, that more than functional programming, Lisp is an homoiconic language. I developed a simple system to specify Swing menus in clojure, [...]]]></description>
			<content:encoded><![CDATA[<p>I am doing some development in Clojure (a Lisp type language for the JVM). Lisp as in a clone tailored for the JVM, not Lisp as only &#8220;functional programming&#8221;. I note, by the way, that more than functional programming, Lisp is an homoiconic language.</p>
<p>I developed a simple system to specify Swing menus in clojure, here is an example:</p>
<div id="attachment_116" class="wp-caption alignnone" style="width: 155px"><img src="http://tiago.org/cc/wp-content/uploads/2009/10/Screenshot-treeHugger.png" alt="Simple Menu" title="menuSimple" width="145" height="145" class="size-full wp-image-116" /><p class="wp-caption-text">Simple Menu</p></div>
<p>The following &#8220;micro-language&#8221; was developed to specify this:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"> <span style="color: #66cc66;">&#40;</span>getMenuBar actionManager '<span style="color: #66cc66;">&#40;</span>
    <span style="color: #66cc66;">&#40;</span>menu <span style="color: #66cc66;">&#123;</span>
      <span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Project&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;P&quot;</span>
      <span style="color: #66cc66;">:</span><span style="color: #555;">content</span> <span style="color: #66cc66;">&#40;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;New&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;N&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Open&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;O&quot;</span>  <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Close&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;O&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">id</span> <span style="color: #ff0000;">&quot;Close&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">enabled</span> false<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Recent&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;R&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>separator<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Exit&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;E&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>menu <span style="color: #66cc66;">&#123;</span>
      <span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Options&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;O&quot;</span>
      <span style="color: #66cc66;">:</span><span style="color: #555;">content</span> <span style="color: #66cc66;">&#40;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Rendering&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;R&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The code is very easy to read, I hope: two menu items, with a few menu entries with text, ability to enable/disable and accelerator keys, plus a separator.</p>
<p>Notice the actionManager on top, is it the (very simple) event processing function which receives only a text as parameter (to identify the selection). The text is simply the menu text, or, if specified an id. Not the most general solution, but enough for simple menu structures.</p>
<p>The code? Below is the _complete_ implementation.</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">&nbsp;
<span style="color: #66cc66;">&#40;</span>ns org<span style="color: #66cc66;">.</span>tiago<span style="color: #66cc66;">.</span>swing
  <span style="color: #808080; font-style: italic;">;(:require clojure.contrib.def)</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">use</span>
    <span style="color: #66cc66;">&#91;</span>clojure<span style="color: #66cc66;">.</span>contrib<span style="color: #66cc66;">.</span>seq-utils <span style="color: #66cc66;">:</span><span style="color: #555;">only</span> <span style="color: #66cc66;">&#40;</span>flatten<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span>clojure<span style="color: #66cc66;">.</span>contrib<span style="color: #66cc66;">.</span>def <span style="color: #66cc66;">:</span><span style="color: #555;">only</span> <span style="color: #66cc66;">&#40;</span>defnk<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">import</span>
    <span style="color: #66cc66;">&#40;</span>java<span style="color: #66cc66;">.</span>awt<span style="color: #66cc66;">.</span>event ActionListener KeyEvent<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>javax<span style="color: #66cc66;">.</span>swing JFrame JMenu JMenuBar JMenuItem<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defnk createFrame <span style="color: #66cc66;">&#91;</span>title <span style="color: #66cc66;">:</span><span style="color: #555;">menuBar</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span>def frame <span style="color: #66cc66;">&#40;</span>new JFrame title<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> frame setDefaultCloseOperation <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> JFrame EXIT_ON_CLOSE<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> menuBar <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> frame setJMenuBar menuBar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> frame pack<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> frame setVisible true<span style="color: #66cc66;">&#41;</span>
  frame
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defmulti addMItem <span style="color: #66cc66;">&#40;</span>fn <span style="color: #66cc66;">&#91;</span>manager x <span style="color: #66cc66;">&amp;</span> rst<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span>first x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmethod addMItem 'item <span style="color: #66cc66;">&#91;</span>manager content menu<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>params <span style="color: #66cc66;">&#40;</span>second content<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#40;</span>def mItem <span style="color: #66cc66;">&#40;</span>new JMenuItem <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>contains? params <span style="color: #66cc66;">:</span><span style="color: #555;">id</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> mItem putClientProperty <span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">id</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>contains? params <span style="color: #66cc66;">:</span><span style="color: #555;">key</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> mItem setMnemonic <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">key</span> params<span style="color: #66cc66;">&#41;</span> charAt <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menu add mItem<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> mItem addActionListener manager<span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmethod addMItem 'separator <span style="color: #66cc66;">&#91;</span>manager sep menu<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menu addSeparator<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defmulti getMBItem first<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmethod getMBItem 'menu <span style="color: #66cc66;">&#91;</span>desc<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>params <span style="color: #66cc66;">&#40;</span>second desc<span style="color: #66cc66;">&#41;</span> manager <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">last</span> desc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#40;</span>def menu <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #808080; font-style: italic;">;Assuming mnemonic is ASCII CODE.</span>
    <span style="color: #808080; font-style: italic;">;java7 has . KeyEvent getExtendedKeyCodeForChar</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>contains? params <span style="color: #66cc66;">:</span><span style="color: #555;">key</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menu setMnemonic <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">key</span> params<span style="color: #66cc66;">&#41;</span> charAt <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>contains? params <span style="color: #66cc66;">:</span><span style="color: #555;">id</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menu putClientProperty <span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">id</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>dorun <span style="color: #66cc66;">&#40;</span>map #<span style="color: #66cc66;">&#40;</span>addMItem manager <span style="color: #66cc66;">%</span> menu<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">content</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    menu
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmethod getMBItem <span style="color: #66cc66;">:</span><span style="color: #555;">default</span> <span style="color: #66cc66;">&#91;</span>arg<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;UNK&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defn getMenuBar <span style="color: #66cc66;">&#91;</span>actionManager menuItems<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>manager <span style="color: #66cc66;">&#40;</span>
      proxy <span style="color: #66cc66;">&#91;</span>ActionListener<span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#40;</span>actionPerformed <span style="color: #66cc66;">&#91;</span>e<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>obj <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>getSource e<span style="color: #66cc66;">&#41;</span>
                                 id <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>getClientProperty obj <span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
        <span style="color: #66cc66;">&#40;</span>actionManager <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">nil</span>? id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> obj getText<span style="color: #66cc66;">&#41;</span> id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
   <span style="color: #66cc66;">&#40;</span>def menuBar <span style="color: #66cc66;">&#40;</span>new JMenuBar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>dorun <span style="color: #66cc66;">&#40;</span>map #<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menuBar add <span style="color: #66cc66;">%</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#40;</span>map #<span style="color: #66cc66;">&#40;</span>getMBItem <span style="color: #66cc66;">&#40;</span>concat <span style="color: #66cc66;">%</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> manager <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> menuItems<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    menuBar
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>OK, comments have to be added <img src='http://tiago.org/cc/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  .<br />
From a declarative point of view, not bad at all.</p>
<p>My first Lisp program. It completely baffles me that, 25 years of programming with all the languages imaginable (including some functional like Caml or highly declarative like Prolog), I never tried Lisp.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;bodytext=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;notes=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;t=Swing%20menus%20in%20Clojure" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;annotation=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Swing%20menus%20in%20Clojure&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;description=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=Swing%20menus%20in%20Clojure&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=Swing%20menus%20in%20Clojure%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;t=Swing%20menus%20in%20Clojure&opener=bm&amp;ei=UTF-8&amp;d=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/10/27/swing-menus-in-clojure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Toying with processing</title>
		<link>http://tiago.org/cc/2009/08/11/toying-with-processing/</link>
		<comments>http://tiago.org/cc/2009/08/11/toying-with-processing/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 17:30:16 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual]]></category>
		<category><![CDATA[processing]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=90</guid>
		<description><![CDATA[I have been toying with Processing. Processing is.. &#8230;an open source programming language and environment for people who want to program images, animation, and interactions. It is used by students, artists, designers, researchers, and hobbyists for learning, prototyping, and production. Processing is actually a full blown IDE with a language based on Java (it is [...]]]></description>
			<content:encoded><![CDATA[<p>I have been toying with <a href="http://processing.org">Processing</a>. Processing is..</p>
<blockquote><p>
&#8230;an open source programming language and environment for people who want to program images, animation, and interactions. It is used by students, artists, designers, researchers, and hobbyists for learning, prototyping, and production.
</p></blockquote>
<p>Processing is actually a full blown IDE with a language based on Java (it is JVM based).</p>
<p>I am fascinated by its community and how most things seems to cleverly done.</p>
<p>Here is my first example (applet alert!). After it loads, move the mouse over the applet to see it in action (you might have to mouse click for it to start on some browsers, like Opera):</p>
<p><applet name="door" WIDTH="400" HEIGHT="200" archive="http://tiago.org/pstmp/door/door.jar" standby="Loading Processing software..." CODE="door" mayscript="true" scriptable="true" image="http://tiago.org/pstmp/door/loading.gif" boxmessage="Loading Processing software..." boxcolor="#FFFFFF"><br />
Please install Java!<br />
</applet> </p>
<p>The code for the above is just:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span>, <span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
color elColor <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> delta <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1.0</span><span style="color: #339933;">*</span>mouseY<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>height<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      elColor <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span>random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span>, random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span>, random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  fill<span style="color: #009900;">&#40;</span>elColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ellipse<span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">80.0</span><span style="color: #339933;">*</span>mouseY<span style="color: #339933;">/</span>height, <span style="color: #cc66cc;">50.0</span><span style="color: #339933;">*</span>mouseX<span style="color: #339933;">/</span>width<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255.0</span><span style="color: #339933;">*</span>mouseY<span style="color: #339933;">/</span>width,<span style="color: #cc66cc;">255.0</span><span style="color: #339933;">*</span>mouseX<span style="color: #339933;">/</span>width, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">255</span><span style="color: #339933;">*</span>mouseX<span style="color: #339933;">/</span>width<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  quad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>,
      delta<span style="color: #339933;">*</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span>delta<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>,
      delta<span style="color: #339933;">*</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span>delta<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>,
      <span style="color: #cc66cc;">0</span>, height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  quad<span style="color: #009900;">&#40;</span>width, <span style="color: #cc66cc;">0</span>,
      width <span style="color: #339933;">-</span> delta<span style="color: #339933;">*</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span>delta<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>,
      width <span style="color: #339933;">-</span> delta<span style="color: #339933;">*</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span>delta<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>,
      width, height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The vibrant community behind seems to produce quite a lot of really neat examples. <a href="http://processing.org">Go and check for yourself</a>&#8230;</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;bodytext=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;notes=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;t=Toying%20with%20processing" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;annotation=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Toying%20with%20processing&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;description=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=Toying%20with%20processing&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=Toying%20with%20processing%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;t=Toying%20with%20processing&opener=bm&amp;ei=UTF-8&amp;d=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/08/11/toying-with-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multicore (and GPU) approaches</title>
		<link>http://tiago.org/cc/2009/08/09/multicore-and-gpu-approaches/</link>
		<comments>http://tiago.org/cc/2009/08/09/multicore-and-gpu-approaches/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 19:18:00 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[concurrrent programming]]></category>
		<category><![CDATA[multicore]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=86</guid>
		<description><![CDATA[It is interesting to see how different people tackle the ongoing multicore (and GPU) software &#8220;revolution&#8221;. There are strong philosophical differences on how to develop for these new concurrent architectures. Lets start with the extremes. The most interesting extreme comes from Guido van Rossum (aka Python benevolent dictator for life): He suggests that if you [...]]]></description>
			<content:encoded><![CDATA[<p>It is interesting to see how different people tackle the ongoing multicore (and GPU) software &#8220;revolution&#8221;. There are strong philosophical differences on how to develop for these new concurrent architectures. Lets start with the extremes.</p>
<p>The most interesting extreme comes from Guido van Rossum (aka Python benevolent dictator for life): He <a href="http://mail.python.org/pipermail/python-3000/2007-May/007414.html">suggests</a> that if you want to use the available processing power of multiple cores you should have separated processes, let me quote:</p>
<blockquote><p>[...] doesn&#8217;t mean that multiple processes (with judicious use of IPC) aren&#8217;t a much better approach to writing apps for multi-CPU boxes than threads.</p>
<p>Just Say No to the combined evils of locking, deadlocks, lock granularity, livelocks, nondeterminism and race conditions.</p></blockquote>
<p>Some similar arguments are made by the message passing crowd, which seems to be quite happy with a model based on explicit message passing between separated processes.</p>
<p>The fundamental idea here is that shared memory between parallel computing threads can lead to a lot of grief and sorrow, thus is is better if all the data memory space is the sole propriety of a single thread. Communication occurs in a explicit form (e.g., message passing among executing code) between threads that do not share anything (other than messages).</p>
<p>The opposite idea can be found on the typical C/C++/Fortran, lower-level crowd: One single process, many threads, a single memory space shared among threads with concurrent access controlled through a low level mechanism like semaphores. This seems also to be the underlying idea of the OpenMP system. These folks believe that programmers can tackle parallel complexity easily (well, at least it is not an impossible, daunting task according to this philosophy).</p>
<p>The point of contention comes from the fact that multiple execution flows introduce a completely new class of bugs coming from the need to coordinate a lot of things going on in parallel. The worst problem introduced is non-determinism: You can execute the same program twice, WITH THE SAME INPUT and get different results. Why? Because the different threads/processes will be scheduled in unpredicted ways by the operating system (or virtual machine) which can yield different results. This severely increases the difficulty to test and debug software. The shared memory crowd (the shared memory model is more efficient and flexible as, well, memory is directly shared) will say that we can deal with this. The message passing crowd suggests that having some restrictions and explicit communication will make life easier (or, less complicated).</p>
<p>The Java crowd is where you can find the most variety of opinions, but the core JVM and Java language itself seems to follow the C/C++ philosophy (though with some candy thrown in, like the Fork/Join framework). But on top of that you can find everything with a vocal support community: Tuple spaces, Map/Reduce, Message passing, etc. This is not to say that the Python and C/C++ communities are monolithic (they are not! Just check the C implementations of MPI and PVM), but you really can find a lot alternatives with vibrant communities on top of the JVM.</p>
<p>A sort of middle of the ground approach was introduced de facto with the programming language Erlang: Erlang allows for multiple threads, but the communication is shared-nothing and based on message passing. I.e. while there is one single process with multiple threads, there is no shared-memory per se and all inter-thread communication is based on message passing. This Actor model based language has influenced some recent language libraries in Scala, Groovy and Clojure, among others where the actor model is the main concurrent programming model.</p>
<p>Many functional languages (like Erlang, Scala and Clojure) proponents also suggest that mutability (ie, the concept of variable stemming from imperative languages like C, Java, C#, Basic, C++, 99% of used languages) is not easily amenable to parallel programming and suggest that immutable data structures make life much easier: If what is shared cannot be changed then much less bugs can be introduced.</p>
<p>To sum it up: Some people suggest concurrent programming is difficult and it is better to minimize communication to tackle that difficulty. Others suggest that concurrent programming is workable and tightly-coupled memory-sharing systems are OK. Some also suggest (functional crowd) that immutable data structures help.</p>
<p>Further reading:<br />
<a href="http://en.wikipedia.org/wiki/Concurrent_computing">Concurrent computing</a> (Wikipedia)<br />
<a href="http://www.scala-lang.org/node/242">Scala actors</a> &#8211; My preferred introduction to Actors (which happens to be based on Scala)<br />
<a href="http://en.wikipedia.org/wiki/Erlang_(programming_language)#Concurrency_and_distribution_oriented_language">Erlang Concurrency</a> Message passing (Wikipedia)</p>
<p>My opinion: Shared memory models are for real men! I am just a regular bloke, so I stick with message passing models. The complexity of bugs introduced by concurrent programming is much much worse compared to the existing sequential paradigm. In most of the cases that I have encountered, the restrictions imposed by message passing are acceptable compared to the benefits. Even with message passing and immutable data structures, concurrent programming is still very hard and bug prone (non-determinism is still quite possible with message passing). I expect (hope) that new R&#038;D will allow us to tame this complexity. Avoid shared memory/tightly coupled systems like the plague!</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;bodytext=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;notes=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;t=Multicore%20%28and%20GPU%29%20approaches" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;annotation=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Multicore%20%28and%20GPU%29%20approaches&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;description=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=Multicore%20%28and%20GPU%29%20approaches&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=Multicore%20%28and%20GPU%29%20approaches%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;t=Multicore%20%28and%20GPU%29%20approaches&opener=bm&amp;ei=UTF-8&amp;d=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/08/09/multicore-and-gpu-approaches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DSLs and IDEs</title>
		<link>http://tiago.org/cc/2009/01/12/dsls-and-ides/</link>
		<comments>http://tiago.org/cc/2009/01/12/dsls-and-ides/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 18:05:59 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[ioke]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[prolog]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=78</guid>
		<description><![CDATA[If you search the web you can find some discussions on whether IDEs for dynamic languages can be as helpful as IDEs for static languages. The issue is that static languages like Java have compile-time (thus easy to get at IDE-time) information in order to provide that fundamental code-completion functionality (among many others). If the [...]]]></description>
			<content:encoded><![CDATA[<p>If you search the web you can find some discussions on whether IDEs for dynamic languages can be as helpful as IDEs for static languages. The issue is that static languages like Java have compile-time (thus easy to get at IDE-time) information in order to provide that fundamental code-completion functionality (among many others). If the IDE knows that a certain parameter is a String, than it is simple: it will present to you all the String methods when you type in the dot. For dynamic languages things get more complex are there is formally no (by definition) compile-time information. Some people would argue that there are ways around it (which you can already find in existing IDEs, I remember having some sort of code completion, years ago, on SPE &#8211; for Python). I will not add anything to that discussion here, this preamble was mainly for putting the reader in context. I am more interested in discussing good IDEs for DSLs.</p>
<p>With DSLs you get, most of the times, added syntax. Worse than that, you might fall into situations where you have changed (not only added) the initial language syntax; furthermore those syntax changes might even become valid only in runtime (imagine that a method is added to a class that is supplying DSL methods).</p>
<p>One example comes from Ioke and Prolog operator precedence and associativity rules which are changeable (see the previous post). It is not trivial to know if something like 1+2 is even syntactically valid (*). Even if it is syntactically valid things like association rules might change. In languages like Groovy you can add (e.g., through categories) methods to code blocs (from classes that can be dynamically changed). Then there is dynamic dispatching and macros. What is valid in a certain piece of code can be different from what is valid a few lines below. In fact, complete information of what is valid in a certain code block might require code execution. Or, to put in another way, it might be very difficult to have a completely helpful IDE! In this scenario there are 3 considerations that I think are worth being done:</p>
<p>1. One should not be discouraged for not having perfect solutions. Maybe it is not possible to determine all that can be expressed in a certain code block, but sometimes good approximations are enough.<br />
2. On this issue, one good example comes from Prolog: In Prolog, syntax can be changed mainly through the use of the <img src='http://tiago.org/cc/wp-includes/images/smilies/icon_surprised.gif' alt=':-o' class='wp-smiley' /> p directive (and through asserts and retracts). The <img src='http://tiago.org/cc/wp-includes/images/smilies/icon_surprised.gif' alt=':-o' class='wp-smiley' /> p directive changes operators but is very easy to analyze pre-compilation/interpretation. So, the way DSLs are normally be constructed lend themselves very easily to code analysis which can be used by IDEs. This unfortunately not the case in most real-world languages.<br />
3. It would be cool to have a language where DSL specifications could be automatically used to construct IDEs. The current real-world DSL-able languages (Ruby, Groovy, &#8230;) are DSL-enabled through indirect techniques which can be used to build DSLs (Dynamic reception, operator overload, whatever), in fact many of these techniques exist with other objectives than creating DSLs. If there was a declarative and explicit way to create DSLs, that information could be used to inform IDEs on parsing and other issues. An embedded, core way, to explicitly specify DSLs.</p>
<p>(*) I suppose some will see this as an argument for the fact that you can do pretty stupid (or at least unintuitive) things with DSLs. Well, you can do stupid things with everything. The question is not if you can or not, but the extent of bad use cases and how bad uses can creep in easily. Another (interesting) discussion, but not for now.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;bodytext=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;notes=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;t=DSLs%20and%20IDEs" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;annotation=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=DSLs%20and%20IDEs&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;description=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=DSLs%20and%20IDEs&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=DSLs%20and%20IDEs%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;t=DSLs%20and%20IDEs&opener=bm&amp;ei=UTF-8&amp;d=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/01/12/dsls-and-ides/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy type crazyness</title>
		<link>http://tiago.org/cc/2009/01/05/groovy-type-crazyness/</link>
		<comments>http://tiago.org/cc/2009/01/05/groovy-type-crazyness/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 17:36:07 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=56</guid>
		<description><![CDATA[Before I start, please remember the finesse of numbers in groovy: 0.1 is a BigDecimal, if you want a Double, you have to write 0.1D. Also, I might be seeing something completely wrong here, corrections are more than welcome! So, what is the result of code below? List lst = [0.1, 0.1D] println lst[0].class println [...]]]></description>
			<content:encoded><![CDATA[<p>Before I start, please remember the <i>finesse</i> of numbers in groovy: 0.1 is a BigDecimal, if you want a Double, you have to write 0.1D.</p>
<p>Also, I might be seeing something completely wrong here, corrections are more than welcome!</p>
<p>So, what is the result of code below?</p>
<p><code><br />
List<double> lst = [0.1, 0.1D]<br />
println lst[0].class<br />
println lst[1].class<br />
println 0.1 == lst[0]<br />
println 0.1 == lst[1]<br />
println 0.1 in [lst[0]]<br />
println 0.1 in [lst[1]]<br />
</double></code></p>
<p>Well, in my book the interpreter should whine on the first line and stop. I am declaring a List of doubles and putting a BigDecimal in. But it doesn&#8217;t. I suppose this is either a bug or some type messing coming from a the not very clear way (for me) Groovy handles types: If I say the type of lst is a List of Doubles, I expect it to behave statically. Either that or the language is misguiding me is allowing me to specify the type and then ignoring it, not good.<br />
So, the result:</p>
<p><code><br />
class java.math.BigDecimal<br />
class java.lang.Double<br />
true<br />
true<br />
true<br />
false<br />
</code></p>
<p>Note that 0.1 is equal to 0.1D (i.e. BigDecimal is equal to Double. For me it makes sense as they have the same value) BUT 0.1 is not in [0.1D]. This, I suppose can only be categorized as a bug (or as something completely unintuitive). </p>
<p>I understand that numbers are not an easy thing to address (precision vs efficiency), but this strikes me as nonintuitive in 2 fronts (type declaration  and number/equality behavior) </p>
<p>Correct me if I am wrong (I can see myself doing a big blunder with equality operator semantics, but I have trouble accepting that groovy lets me put a BigDecimal inside a list of double)&#8230;</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;bodytext=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;notes=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;t=Groovy%20type%20crazyness" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;annotation=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Groovy%20type%20crazyness&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;description=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=Groovy%20type%20crazyness&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=Groovy%20type%20crazyness%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;t=Groovy%20type%20crazyness&opener=bm&amp;ei=UTF-8&amp;d=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/01/05/groovy-type-crazyness/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Prototyping, performance and declarative languages</title>
		<link>http://tiago.org/cc/2008/12/29/prototyping-performance-and-declarative-languages/</link>
		<comments>http://tiago.org/cc/2008/12/29/prototyping-performance-and-declarative-languages/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 17:31:47 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=31</guid>
		<description><![CDATA[During my &#8220;silent months&#8221; (for details see this post) I&#8217;ve been developing a simple system to study the spread of of antimalarial drug resistance. It is a &#8220;typical&#8221; scientific application with a core (which simulates genetic recombination of individuals reproducing) which is computationally very demanding. As it is common in these scenarios I started by [...]]]></description>
			<content:encoded><![CDATA[<p>During my &#8220;silent months&#8221; (for details see <a href="http://tiago.org/cc/2008/12/26/the-library-over-engineering-syndrome/">this post</a>) I&#8217;ve been developing a simple system to study the spread of of antimalarial drug resistance. It is a &#8220;typical&#8221; scientific application with a core (which simulates genetic recombination of individuals reproducing) which is computationally very demanding.</p>
<p>As it is common in these scenarios I started by developing a prototype in a high-level, declarative language (in my case Groovy). I was pretty sure that the first solution would be slow as hell, and part of of that slowness would be due to using a &#8220;scripting&#8221; language (although algorithm complexity is the cause of slowness, changing the language should at least get running times down 1 order of magnitude). The initial solution was in fact slow. So I proceeded to do the usual thing: identify the expensive part (easy in my case) and rewrite that part in Java. My intention was to end up with a typical hybrid system: core, computational intensive code in Java and high-level functions in Groovy, for easy and productive manipulation.</p>
<p>Converting from Groovy to Java is easy, in fact it is too easy: The final Java code was full of Groovyisms: legacy generics code (things like Map&lt;String,List&lt;Integer&gt;&gt;) and strange looking (from a Java perspective) code originating on .each constructs among other things that made the Java code look very strange.</p>
<p>Needless to say, there were not that much speed improvements. In order to improve things I started to try to be sure that the data structures below List&lt;&gt; had the required complexity for my most used operations. Not much improvement. I then decided to completely convert things like List&lt;List&lt;Integer&gt;&gt; to the typical Java int[][]. Spaghetti and semantic chaos followed (just think of the not-so-minor differences in semantics between lists of lists and [][]).</p>
<p>Being a member of the fundamentalist church of refactoring I decided to do the unthinkable: throw the code away and rewrite it from scratch. I would rewrite the whole code, starting from the core in Java in a Java idiomatic way targeting performance. Then, on top of that I would grow a set of Groovy wrappers in order to easily manipulate the said core. Worked perfectly! Actually I am running that code in the background (on a Asus EEE) as I write this.</p>
<p>The (somewhat elusive) lesson that I took from this is that going from prototype to production code, when the fundamental difference is performance, can be cumbersome if the prototype language is too close to the production language (and Groovy and Java and close enough). The temptation to do a line by line code conversion is too good for comfort (I actually did rename the computationally intensive .groovy to .java and translated line by line &#8211; feel free to call me silly) and can have very upseting results.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;title=Prototyping%2C%20performance%20and%20declarative%20languages&amp;bodytext=During%20my%20%22silent%20months%22%20%28for%20details%20see%20this%20post%29%20I%27ve%20been%20developing%20a%20simple%20system%20to%20study%20the%20spread%20of%20of%20antimalarial%20drug%20resistance.%20It%20is%20a%20%22typical%22%20scientific%20application%20with%20a%20core%20%28which%20simulates%20genetic%20recombination%20of%20individu" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;title=Prototyping%2C%20performance%20and%20declarative%20languages&amp;notes=During%20my%20%22silent%20months%22%20%28for%20details%20see%20this%20post%29%20I%27ve%20been%20developing%20a%20simple%20system%20to%20study%20the%20spread%20of%20of%20antimalarial%20drug%20resistance.%20It%20is%20a%20%22typical%22%20scientific%20application%20with%20a%20core%20%28which%20simulates%20genetic%20recombination%20of%20individu" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;t=Prototyping%2C%20performance%20and%20declarative%20languages" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;title=Prototyping%2C%20performance%20and%20declarative%20languages&amp;annotation=During%20my%20%22silent%20months%22%20%28for%20details%20see%20this%20post%29%20I%27ve%20been%20developing%20a%20simple%20system%20to%20study%20the%20spread%20of%20of%20antimalarial%20drug%20resistance.%20It%20is%20a%20%22typical%22%20scientific%20application%20with%20a%20core%20%28which%20simulates%20genetic%20recombination%20of%20individu" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;title=Prototyping%2C%20performance%20and%20declarative%20languages" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;title=Prototyping%2C%20performance%20and%20declarative%20languages" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Prototyping%2C%20performance%20and%20declarative%20languages&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;title=Prototyping%2C%20performance%20and%20declarative%20languages" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;title=Prototyping%2C%20performance%20and%20declarative%20languages&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=During%20my%20%22silent%20months%22%20%28for%20details%20see%20this%20post%29%20I%27ve%20been%20developing%20a%20simple%20system%20to%20study%20the%20spread%20of%20of%20antimalarial%20drug%20resistance.%20It%20is%20a%20%22typical%22%20scientific%20application%20with%20a%20core%20%28which%20simulates%20genetic%20recombination%20of%20individu" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;title=Prototyping%2C%20performance%20and%20declarative%20languages&amp;description=During%20my%20%22silent%20months%22%20%28for%20details%20see%20this%20post%29%20I%27ve%20been%20developing%20a%20simple%20system%20to%20study%20the%20spread%20of%20of%20antimalarial%20drug%20resistance.%20It%20is%20a%20%22typical%22%20scientific%20application%20with%20a%20core%20%28which%20simulates%20genetic%20recombination%20of%20individu" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=Prototyping%2C%20performance%20and%20declarative%20languages&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=Prototyping%2C%20performance%20and%20declarative%20languages%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F12%2F29%2Fprototyping-performance-and-declarative-languages%2F&amp;t=Prototyping%2C%20performance%20and%20declarative%20languages&opener=bm&amp;ei=UTF-8&amp;d=During%20my%20%22silent%20months%22%20%28for%20details%20see%20this%20post%29%20I%27ve%20been%20developing%20a%20simple%20system%20to%20study%20the%20spread%20of%20of%20antimalarial%20drug%20resistance.%20It%20is%20a%20%22typical%22%20scientific%20application%20with%20a%20core%20%28which%20simulates%20genetic%20recombination%20of%20individu" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2008/12/29/prototyping-performance-and-declarative-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DSLs involving existing classes in Groovy</title>
		<link>http://tiago.org/cc/2008/04/30/dsls-involving-existing-classes-in-groovy/</link>
		<comments>http://tiago.org/cc/2008/04/30/dsls-involving-existing-classes-in-groovy/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 13:28:34 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=9</guid>
		<description><![CDATA[Preamble: In order to understand this post you should know a little bit (a little is enough, that is how much I know) about ExpandoMetaClass and Categories in Groovy. DSLs that involve existing classes might be a source of long term sorrow. Let me give an example: Imagine that you want to make a small [...]]]></description>
			<content:encoded><![CDATA[<p>Preamble: In order to understand this post you should know a little bit (a little is enough, that is how much I know) about ExpandoMetaClass and Categories in Groovy.</p>
<p>DSLs that involve existing classes might be a source of long term sorrow. Let me give an example: Imagine that you want to make a small DSL to handle equations, like</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">x <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Symbol<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;x&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">*</span> x<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">differentiate</span><span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">//Result is 2</span></pre></div></div>

<p>The problem is that the * operator of Numbers doesn&#8217;t know how to handle Symbols, therefore an exception would be raised. The obvious solutions as discussed before on mailing lists and blog posts are:</p>
<p><b>Categories</b></p>
<p>Categories would solve the problem, but at the expense of polluting the source with things like</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #993399;">use</span> <span style="color: #66cc66;">&#40;</span>Something.<span style="color: #006600;">Category</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #808080; font-style: italic;">//code here</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Not a disaster, but not pretty too&#8230;</p>
<p>Talking about disasters&#8230;</p>
<p><b>Expando over Numbers</b></p>
<p>The idea here would be to change the behavior of Numbers to be able to handle Symbols. Code would be very clean, no need for uses&#8230;</p>
<p>As somebody said on the groovy mailing list: This is disaster in the making. The problem is that I change Numbers, then, for another valid reason you change Numbers, somebody else also changes Numbers&#8230; This is chaos. Or at least it would make code from different sources potentially not inter operable or exhibiting very strange, buggy, behavior. This is clearly akin to the &#8220;global variable&#8221; problem. I believe that in the long term and with big software projects, this approach is a dead end.</p>
<p><b>Enter Python</b></p>
<p>Python actually has a workaround (I will not call it a clear, beautiful solution) that might be somewhat useful here. Imagine that you do</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff4500;">1</span> + x</pre></div></div>

<p>The default 1 (default class for number) is not able to handle the symbol. For python that is OK, it will try to call a &#8220;right add&#8221; method of x (Search for __radd__ in <a href="http://docs.python.org/ref/numeric-types.html">this page</a>). So, the default behavior is not to raise an exception if the left object cannot handle the operator, but to try to call the &#8220;right&#8221; version on the right object (if it fails then raise).</p>
<p>Not perfect, but might be just enough to avoid Expando in anger.</p>
<p>I do believe that people still don&#8217;t appreciate the consequences of Expanding core classes and the interop disaster that that can entail.</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Social network sharing</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;title=DSLs%20involving%20existing%20classes%20in%20Groovy&amp;bodytext=Preamble%3A%20In%20order%20to%20understand%20this%20post%20you%20should%20know%20a%20little%20bit%20%28a%20little%20is%20enough%2C%20that%20is%20how%20much%20I%20know%29%20about%20ExpandoMetaClass%20and%20Categories%20in%20Groovy.%0D%0A%0D%0ADSLs%20that%20involve%20existing%20classes%20might%20be%20a%20source%20of%20long%20term%20sorrow.%20Let%20me" title="Digg"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;title=DSLs%20involving%20existing%20classes%20in%20Groovy&amp;notes=Preamble%3A%20In%20order%20to%20understand%20this%20post%20you%20should%20know%20a%20little%20bit%20%28a%20little%20is%20enough%2C%20that%20is%20how%20much%20I%20know%29%20about%20ExpandoMetaClass%20and%20Categories%20in%20Groovy.%0D%0A%0D%0ADSLs%20that%20involve%20existing%20classes%20might%20be%20a%20source%20of%20long%20term%20sorrow.%20Let%20me" title="del.icio.us"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;t=DSLs%20involving%20existing%20classes%20in%20Groovy" title="Facebook"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;title=DSLs%20involving%20existing%20classes%20in%20Groovy&amp;annotation=Preamble%3A%20In%20order%20to%20understand%20this%20post%20you%20should%20know%20a%20little%20bit%20%28a%20little%20is%20enough%2C%20that%20is%20how%20much%20I%20know%29%20about%20ExpandoMetaClass%20and%20Categories%20in%20Groovy.%0D%0A%0D%0ADSLs%20that%20involve%20existing%20classes%20might%20be%20a%20source%20of%20long%20term%20sorrow.%20Let%20me" title="Google Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;title=DSLs%20involving%20existing%20classes%20in%20Groovy" title="DZone"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;title=DSLs%20involving%20existing%20classes%20in%20Groovy" title="Reddit"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=DSLs%20involving%20existing%20classes%20in%20Groovy&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F" title="Slashdot"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;title=DSLs%20involving%20existing%20classes%20in%20Groovy" title="StumbleUpon"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F" title="Technorati"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;title=DSLs%20involving%20existing%20classes%20in%20Groovy&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=Preamble%3A%20In%20order%20to%20understand%20this%20post%20you%20should%20know%20a%20little%20bit%20%28a%20little%20is%20enough%2C%20that%20is%20how%20much%20I%20know%29%20about%20ExpandoMetaClass%20and%20Categories%20in%20Groovy.%0D%0A%0D%0ADSLs%20that%20involve%20existing%20classes%20might%20be%20a%20source%20of%20long%20term%20sorrow.%20Let%20me" title="LinkedIn"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;title=DSLs%20involving%20existing%20classes%20in%20Groovy&amp;description=Preamble%3A%20In%20order%20to%20understand%20this%20post%20you%20should%20know%20a%20little%20bit%20%28a%20little%20is%20enough%2C%20that%20is%20how%20much%20I%20know%29%20about%20ExpandoMetaClass%20and%20Categories%20in%20Groovy.%0D%0A%0D%0ADSLs%20that%20involve%20existing%20classes%20might%20be%20a%20source%20of%20long%20term%20sorrow.%20Let%20me" title="connotea"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/connotea.png" title="connotea" alt="connotea" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.friendfeed.com/share?title=DSLs%20involving%20existing%20classes%20in%20Groovy&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F" title="FriendFeed"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://twitter.com/home?status=DSLs%20involving%20existing%20classes%20in%20Groovy%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F" title="Twitter"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Ftiago.org%2Fcc%2F2008%2F04%2F30%2Fdsls-involving-existing-classes-in-groovy%2F&amp;t=DSLs%20involving%20existing%20classes%20in%20Groovy&opener=bm&amp;ei=UTF-8&amp;d=Preamble%3A%20In%20order%20to%20understand%20this%20post%20you%20should%20know%20a%20little%20bit%20%28a%20little%20is%20enough%2C%20that%20is%20how%20much%20I%20know%29%20about%20ExpandoMetaClass%20and%20Categories%20in%20Groovy.%0D%0A%0D%0ADSLs%20that%20involve%20existing%20classes%20might%20be%20a%20source%20of%20long%20term%20sorrow.%20Let%20me" title="Yahoo! Bookmarks"><img src="http://tiago.org/cc/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2008/04/30/dsls-involving-existing-classes-in-groovy/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
