<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Raw Block</title>
	
	<link>http://www.rawblock.com</link>
	<description>Random braindumps vaguely related to coding</description>
	<lastBuildDate>Tue, 21 Apr 2009 02:48:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/RawBlock" /><feedburner:info uri="rawblock" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>My MXUG Erlang Presentation</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/lA7sy1KqfGk/</link>
		<comments>http://www.rawblock.com/2009/04/21/my-mxug-erlang-presentation/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 02:48:51 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[mxug]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/?p=81</guid>
		<description><![CDATA[I did a quick talk on Erlang at last week&#8217;s MXUG meet up.
A couple of people have asked for the slides. There isn&#8217;t much to them, as they&#8217;re really just placeholder text to talk around. But anyway, you can grab them and have a read.
Download presentation notes (PDF)
If you&#8217;re wondering exactly what &#8220;MXUG&#8221; is, it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I did a quick talk on Erlang at last week&#8217;s <a href="http://groups.google.com.au/group/mxug">MXUG</a> meet up.</p>
<p>A couple of people have asked for the slides. There isn&#8217;t much to them, as they&#8217;re really just placeholder text to talk around. But anyway, you can grab them and have a read.</p>
<p><a href='http://www.rawblock.com/wp-content/uploads/2009/04/erlang_mxug_20090415.pdf'>Download presentation notes (PDF)</a></p>
<p>If you&#8217;re wondering exactly what &#8220;MXUG&#8221; is, it&#8217;s the <em>&#8220;Melbourne X User Group&#8221;</em> where <em>X</em> stands for pretty much anything tech/geek related. It&#8217;s a newish group (only been 2 meetings so far). Meetings are monthly, and you can grab more details on the <a href="http://groups.google.com.au/group/mxug">MXUG google group</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2009/04/21/my-mxug-erlang-presentation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2009/04/21/my-mxug-erlang-presentation/</feedburner:origLink></item>
		<item>
		<title>One reason static typing doesn’t suck</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/jEVVuuqBZRM/</link>
		<comments>http://www.rawblock.com/2007/09/08/one-reason-static-typing-doesnt-suck/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 14:49:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[dynamic typing]]></category>
		<category><![CDATA[static typing]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/09/08/one-reason-static-typing-doesnt-suck/</guid>
		<description><![CDATA[Eric Redmond over at Death by Overcoding has posted a discussion on 5 Reasons Static Typing Sucks
It&#8217;s a great article, and I agree with pretty much all of it. For the most part excessive static typing is a PITA. The illusion of safety is just that. Static compile time checks only catch the most trivial [...]]]></description>
			<content:encoded><![CDATA[<p>Eric Redmond over at Death by Overcoding has posted a discussion on <a href="http://coderoshi.blogspot.com/2007/09/5-reasons-static-typing-sucks.html">5 Reasons Static Typing Sucks</a>
<p>It&#8217;s a great article, and I agree with pretty much all of it. For the most part excessive static typing is a PITA. The illusion of safety is just that. Static compile time checks only catch the most trivial of bugs, and even then, most of those would have manifested themselves the first time the code was even run. When it comes down to it, the trade offs of the traditional benefits of static typing (you don&#8217;t shoot yourself in the foot; you and the compiler always know what&#8217;s going on), are often outweighed by the disadvantages discussed in the article.</p>
<p>However, the one thing I&#8217;ve always liked when working with static type systems, and one that is often glossed over when discussing dynamic typing systems, is how easily tools can interpret and navigate code. When coding Java in Eclipse, it&#8217;s amazing how easy understanding a massive code base can become. You&#8217;ve got simple hyperlink navigation, sophisticated refactorings, and smart code analysis that can show you what is called from where and how. Even interfaces and figuring out which implementation is used (which is kinda dynamic typing for Java) can be groked easily with a good IDE.</p>
<p>Got a class with some methods? Want to find where it&#8217;s called from? Check. Want to find what methods can be called on the argument you&#8217;ve been passed? Check. Want to refactor a whole class hierarchy? Check.</p>
<p>I really love Ruby, but the first thing that struck me when I sat down to code is  how much you&#8217;re on your own figuring out what is happening. Got a method with an argument passed in? What is it? What can you do with it? Dunno. Want to call another method? What arguments does it take? What about the block it accepts? What does it return? Dunno.</p>
<p>Dynamic languages are great for quickly writing simple elegant code, but not always so great for following and debugging existing code (especially code someone else has written).</p>
<p>Try digging into the internals of Rails, and you&#8217;ll become very familiar with the free text search of your text editor. What the hell is that variable? Where was it even instantiated? Dunno. Once you understand the general layout of the classes and modules its pretty straight forward, and thankfully Rails has a pretty well laid out architecture. Which is probably the whole point. If your Ruby code is clean and well designed, then obviously it&#8217;s going to be easier to navigate. </p>
<p>So really it comes down to good developers doing smart things. The size and complexity of a good Ruby code base is significantly less than something comparable written in Java for instance. As with most things in software development, this is about trade offs. Ruby is smaller and simpler, but the tools don&#8217;t allow you to refactor as easily as Java (the agile purists will say your unit tests allow you to refactor, but it&#8217;s still a lot more manual and involved than the automatic refactorings you can do in Java).</p>
<p>It means that in dynamic languages, its more important to have a good design so you don&#8217;t get lost in dynamic spaghetti down the track. But at the same time you&#8217;re more likely to have a good architecture in the first place because you&#8217;re not wasting mental energy focusing on satisfying the static typing system. One of the weakness of static typing discussed in the original article touches on that &#8211; the fact that more design must be done up front to predict the future when using static typing. With dynamic typing you&#8217;ve got less baggage stopping you from evolving your design as you work, so you can apply the <a href="http://en.wikipedia.org/wiki/YAGNI">YAGNI</a> principle more easily.</p>
<p>&#8230;Although I do still miss being able to zip around Ruby code like I can in Java.<br />
(Yeah, I know Netbeans is getting there, but it&#8217;s still a long way behind what you can do with tools analysing and refactoring static typed code).
<p>A decade ago, people said you couldn&#8217;t do refactorings and static code analysis with Java. Maybe IDEs will evolve enough over the next few years will make this true for Ruby as well, and we&#8217;ll get the best of both worlds.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/09/08/one-reason-static-typing-doesnt-suck/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/09/08/one-reason-static-typing-doesnt-suck/</feedburner:origLink></item>
		<item>
		<title>Looking for OOP in Erlang is like looking for religious icons in a cheese sandwich</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/q8beYoHmr58/</link>
		<comments>http://www.rawblock.com/2007/08/23/looking-for-oop-in-erlang-is-like-looking-for-religious-icons-in-a-cheese-sandwich/#comments</comments>
		<pubDate>Wed, 22 Aug 2007 21:32:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[erlang]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/08/23/looking-for-oop-in-erlang-is-like-looking-for-religious-icons-in-a-cheese-sandwich/</guid>
		<description><![CDATA[Recently there&#8217;s been a lot of discussion around how processes in Erlang could be considered to be objects and that Erlang can therefore be considered an object oriented language. I really think that&#8217;s stretching the definition. They&#8217;re kind of right, but in the same way that the people who saw a vision of the Virgin [...]]]></description>
			<content:encoded><![CDATA[<p>Recently there&#8217;s been a lot of discussion around how processes in Erlang could be considered to be objects and that Erlang can therefore be considered an object oriented language. I really think that&#8217;s stretching the definition. They&#8217;re kind of right, but in the same way that the people who saw a vision of the <a href="http://news.bbc.co.uk/2/hi/americas/4034787.stm">Virgin Mary in a cheese sandwich</a> were right.</p>
<p><a href="http://news.bbc.co.uk/2/hi/americas/4034787.stm"><img src="http://newsimg.bbc.co.uk/media/images/40534000/jpg/_40534689_toastie-afp203.jpg"/></a></p>
<p>Way back in 2004 you may remember some crazy woman announced she had a 10 year old toasted cheese sandwich which miraculously had the face of the Virgin Mary cooked onto it. The sandwich eventually sold on ebay for $28,000, which just added to the circus factor.</p>
<p>I&#8217;m not going to get into a theological debate over snack food, but I really just see a random burn marking. But then I&#8217;m not particularly religious, so I&#8217;m not looking for images of the virgin in the first place. If you were a devout Catholic with a love of toasted treats, you might be. If you were a Beatles fan, you might see the face of John Lennon or Ringo Starr.
<p>As for me, I did see a kiwifruit with a mark the shape of New Zealand the other day. But then I am a New Zealander and kiwifruits come from New Zealand, so I&#8217;m more inclined to see that. Other people might miss it.</p>
<p>People look for patterns that are already familiar to them. When they encounter new things, first instinct is to apply existing knowledge to it. It happens with cheese sandwiches and kiwi fruit, and it happens with programming languages.</p>
<p>First up, Ralph Johnson wrote in <a href="http://www.cincomsmalltalk.com/userblogs/ralph/blogView?entry=3364027251&#038;showComments=true">Erlang, the next Java</a></p>
<blockquote><p>Processes certainly support data abstraction and polymorphism. An Erlang process is a function that reads from the incoming message queue, pattern matches to find a particular message, and then responds to it. A function structured in this particular way is similar to a class in Smalltalk. Moreover, given several kinds of processes that have a common protocol and that share some things in common, it is easy to factor out the commonality into a function that they can both call. This is similar to class inheritance. So, you could even say that Erlang supports inheritance, though it does it very differently than in Java or Smalltalk. I imagine that many Erlang programmers think about programming as modeling. So, Erlang fits all the characteristics of an OO system, even though sequential Erlang is a functional language, not an OO language.</p></blockquote>
<p>Kirit Sælensminde picked that up and ran with it in <a href="http://www.kirit.com/Blog:/2007-08-09/Erlang%20as%20an%20OO%20language">Erlang as an OO language</a>.</p>
<blockquote><p>As I&#8217;ve been looking more and more at Erlang it strikes me more and more that there is an object oriented language hiding just below the surface.</p></blockquote>
<p>Chris Petrilli also commented in <a href="http://blog.amber.org/2007/08/16/object-oriented-processes/">Object-oriented processes</a> comparing Joe Armstrong&#8217;s comments on how Erlang is <em>not</em> considered to be OO, and comments by Dr. Alan Kay on the original definition of OO.</p>
<blockquote><p>So, messaging is a core of both OOP and what Armstrong calls Concurrency Oriented Programming. In both cases, the concept of messages are used as a strong isolation mechanism to keep one piece from peering into another and fiddling with the internals. In the case of Smalltalk, for example, that piece is an Object. In Erlang, its a Process.</p></blockquote>
<p>So are these guys right? Well, yeah. Technically. It&#8217;s more than possible to shoehorn an OO mindset into Erlang. I have to admit I thought exactly the same thing when I started looking at processes receiving and acting on messages. You can definitely apply OO thinking to the concept, and yes I have be doing mostly OO work for the last few years. This linking is a pretty useful human skill for picking up new knowledge, but you have to be careful though to stop and ask how much of that is accurate, and how much is from the mental filters inherent from previous experience.</p>
<p>You can apply pretty much any programming metaphor to any language you like if you shine the light the right way and squint hard enough: You can do Object Oriented programming in C if you want (it&#8217;s ugly and involves passing lots of &#8220;this&#8221; structs, but you can do it); you can do functional programming in Java (kind of, but without most of the power and elegance), or even duck-typing if you love your keyboard; and you can even fake a static typing system in Ruby if you&#8217;re a masochist. Does that mean those languages are actually productive writing code in that style? No. Sure it&#8217;s an interesting academic comparison, but of little value at the end of the day except to highlight the shortcomings in using those languages in that way.</p>
<p>So what about the cheese sandwich?</p>
<p>When I say that finding the OO in Erlang is like finding the Virgin in the cheese sandwich, I mean that if you look hard enough expecting to find something, then you probably will.</p>
<p>This is mostly all pretty harmless, and its a big benefit to learning a new skill to build on top of existing knowledge. However, we need to be wary of the fact that there are different ways of thinking about things. If we go applying all the old thought patterns because that&#8217;s what we&#8217;re most comfortable with, we risk missing a huge opportunity to do things in new and better ways. And Erlang does definitely provide that. There are numerous valuable and unique concepts that would be missed by examining it through just through the lens of an OO expert and nothing else.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/08/23/looking-for-oop-in-erlang-is-like-looking-for-religious-icons-in-a-cheese-sandwich/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/08/23/looking-for-oop-in-erlang-is-like-looking-for-religious-icons-in-a-cheese-sandwich/</feedburner:origLink></item>
		<item>
		<title>How to send SMTP mail in Ruby using ActionMailer (outside Rails)</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/sUldIz6313Q/</link>
		<comments>http://www.rawblock.com/2007/07/31/how-to-send-smtp-mail-in-ruby-using-actionmailer-outside-rails/#comments</comments>
		<pubDate>Mon, 30 Jul 2007 13:22:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[actionmailer]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/07/31/how-to-send-smtp-mail-in-ruby-using-actionmailer-outside-rails/</guid>
		<description><![CDATA[Like most bits of Rails, ActionMailer has an elegant and coder friendly interface. With a bit of set up, it&#8217;s remarkably quick and easy to get running from vanilla Ruby outside of Rails.
Recently I&#8217;ve needed to bulk email a bunch of files to an internal server for testing purposes. I&#8217;ve used ActionMailer inside Rails in [...]]]></description>
			<content:encoded><![CDATA[<p>Like most bits of Rails, <a href="http://wiki.rubyonrails.org/rails/pages/ActionMailer">ActionMailer</a> has an elegant and coder friendly interface. With a bit of set up, it&#8217;s remarkably quick and easy to get running from vanilla Ruby outside of Rails.</p>
<p>Recently I&#8217;ve needed to bulk email a bunch of files to an internal server for testing purposes. I&#8217;ve used ActionMailer inside Rails in the past, and wondered how hard it would actually be to get it up and running standalone. Sure, there are a stack of other mail gems and libraries in Ruby to do this, but they expose a lot of the internals of STMP and can be a pain to use. Definitely overkill when all you want to do is quickly fire off some mails from a script. (ActionMailer is actually built on top of a lot of those libraries, and acts like a coder friendly wrapper).</p>
<p>My requirements were pretty simple: Iterate over a bunch of files, and attach each one to a separate email and send to some address.</p>
<p>Here&#8217;s what the code looks like for the ActionMailer class:</p>
<pre><span class="ident">require</span> <span class="punct">'</span><span class="string">action_mailer</span><span class="punct">'</span>

<span class="constant">ActionMailer</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">smtp_settings</span> <span class="punct">=</span>
<span class="punct">{</span><span class="symbol">:address</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">smtp.example.com</span><span class="punct">',</span>
 <span class="symbol">:domain</span>  <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">example.com</span><span class="punct">'}</span>

<span class="keyword">class </span><span class="class">FileMailer</span> <span class="punct">&lt;</span> <span class="constant">ActionMailer</span><span class="punct">::</span><span class="constant">Base</span>
  <span class="keyword">def </span><span class="method">file</span><span class="punct">(</span><span class="ident">to</span><span class="punct">,</span> <span class="ident">sender</span><span class="punct">,</span> <span class="ident">file_name</span><span class="punct">,</span> <span class="ident">content_type</span><span class="punct">,</span> <span class="ident">strip_ext</span> <span class="punct">=</span> <span class="constant">true</span><span class="punct">)</span>
    <span class="comment"># strip any directory fluff </span>
    <span class="ident">subj</span> <span class="punct">=</span> <span class="ident">file_name</span><span class="punct">.</span><span class="ident">gsub</span><span class="punct">(/</span><span class="regex">.*<span class="escape">\/</span></span><span class="punct">/,'</span><span class="string"></span><span class="punct">')</span>
    <span class="comment">#remove the file extension if required</span>
    <span class="ident">subj</span> <span class="punct">=</span> <span class="ident">subj</span><span class="punct">.</span><span class="ident">gsub</span><span class="punct">(/</span><span class="regex"><span class="escape">\.\w</span>*</span><span class="punct">/,'</span><span class="string"></span><span class="punct">')</span> <span class="keyword">if</span> <span class="ident">strip_ext</span>

    <span class="comment">#standard ActionMailer message setup</span>
    <span class="ident">recipients</span>  <span class="ident">to</span>
    <span class="ident">from</span>        <span class="ident">sender</span>
    <span class="ident">subject</span>     <span class="ident">subj</span>
    <span class="comment">#setting the body explicitly means we don't have to provide a separate template file</span>
    <span class="ident">body</span>        <span class="punct">'</span><span class="string"></span><span class="punct">'</span>

    <span class="comment">#set up the attachment</span>
    <span class="ident">attachment</span>  <span class="symbol">:content_type</span> <span class="punct">=&gt;</span> <span class="ident">content_type</span><span class="punct">,</span>
                <span class="symbol">:body</span>         <span class="punct">=&gt;</span> <span class="constant">File</span><span class="punct">.</span><span class="ident">read</span><span class="punct">(</span><span class="ident">file_name</span><span class="punct">),</span>
                <span class="symbol">:filename</span>     <span class="punct">=&gt;</span> <span class="ident">file_name</span><span class="punct">.</span><span class="ident">gsub</span><span class="punct">(/</span><span class="regex">.*<span class="escape">\/</span></span><span class="punct">/,'</span><span class="string"></span><span class="punct">')</span>
  <span class="keyword">end</span>
<span class="keyword">end</span>
</pre>
<p>The only thing different from Rails, is that you need to explicitly configure the SMTP details via <code>ActionMailer::Base#smtp_settings</code>.</p>
<p>It&#8217;s worth noting that you don&#8217;t actually need to create a .rhtml view file if you specify the <code>body</code> attribute of your message. I ran into a few blogs claiming there was no way to turn off the .rhtml requirement &#8211; a quick inspection of the ActionMailer source code proves otherwise. I&#8217;m sure it violates good MVC design, but if you&#8217;re just throwing together a quick script, who cares. I&#8217;ve left the body in the example as an empty string (the server at the other end was only interested in the attachement), but you can specify whatever string you want there.</p>
<p>To use the mailer class, you just call it in the normal Rails ActionMailer manner. With ActionMailer you don&#8217;t call the mail action method you implemented, but a generated method prefixed with <code>deliver_</code>. So in our example, even though we implemented a method <code>file</code>, we actually call <code>deliver_file</code> (passing it the same parameters).</p>
<pre><span class="constant">FileMailer</span><span class="punct">.</span><span class="ident">deliver_file</span><span class="punct">('</span><span class="string">recipient@example.com</span><span class="punct">','</span><span class="string">julian@example.com</span><span class="punct">','</span><span class="string">my_file.csv</span><span class="punct">','</span><span class="string">text/csv</span><span class="punct">')</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/07/31/how-to-send-smtp-mail-in-ruby-using-actionmailer-outside-rails/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/07/31/how-to-send-smtp-mail-in-ruby-using-actionmailer-outside-rails/</feedburner:origLink></item>
		<item>
		<title>Java 6 on Mac OS X Leopard?</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/XMy-3gvkZYc/</link>
		<comments>http://www.rawblock.com/2007/06/15/java-6-on-mac-os-x-leopard/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 23:44:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[mac os x]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[wwdc]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/06/15/java-6-on-mac-os-x-leopard/</guid>
		<description><![CDATA[An interesting bit of digging on damnhandy into the WWDC session list points out that Java on Leopard (Mac OS X 10.5) is going to sport a 64 bit Java VM, along with Swing support for the new Leopard UI features. The WWDC notes are pretty brief and just buried in the general session listing [...]]]></description>
			<content:encoded><![CDATA[<p>An interesting bit of digging on <a href="http://www.damnhandy.com/2007/06/13/java-on-mac-os-x-leopard-to-be-64-bit-resolution-independent/">damnhandy</a> into the <a href="http://developer.apple.com/wwdc/sessions/index.html#138">WWDC session list</a> points out that Java on Leopard (Mac OS X 10.5) is going to sport a 64 bit Java VM, along with Swing support for the new Leopard UI features. The WWDC notes are pretty brief and just buried in the general session listing page, so details are still  sketchy.</p>
<p>javascript:void(0)</p>
<p>The interesting thing damnhandy points out, is that seeing as Leopard Java (Java 6?) is going to be 64 bit, it probably won&#8217;t run on Tiger (Mac OS X 10.4). That&#8217;s kind of a shame, but it&#8217;s better than nothing. I posted a few weeks ago that as a developer, I <a href="/2007/05/java-6-on-mac-os-x-when.html">just want something that lets me develop Java code for other platforms</a> and could care less about Swing support for the new Leopard UI. I wish Apple would either release Java 6 that runs with Tiger (even without Leopard support), or release the source to <a href="http://openjdk.java.net/">OpenJDK</a> if they aren&#8217;t going to maintain it.</p>
<p>The session took place at 9am PDT (about 7 hours ago). Haven&#8217;t been able to find any details yet as to what was in it, but will update when info become available.</p>
<p><strong><em>Update</em></strong> &#8211; actually, there was no new info. So Java 6 on OS X is still out in the wilderness&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/06/15/java-6-on-mac-os-x-leopard/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/06/15/java-6-on-mac-os-x-leopard/</feedburner:origLink></item>
		<item>
		<title>Ruby / Oracle / Mac OS X pain – JRuby and ActiveRecord JDBC to the rescue!</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/k6RVDYoD5QM/</link>
		<comments>http://www.rawblock.com/2007/06/14/ruby-oracle-mac-os-x-pain-jruby-and-activerecord-jdbc-to-the-rescue/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 09:37:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[jruby]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/06/14/ruby-oracle-mac-os-x-pain-jruby-and-activerecord-jdbc-to-the-rescue/</guid>
		<description><![CDATA[A while back I wrote about my frustrations trying to get Ruby to talk to Oracle on Mac OS X. I&#8217;ve tried a new approach using JRuby and ActiveRecord-JDBC with great success.
What I&#8217;m after is quite simple: I just want to use Ruby for some simple housekeeping scripting tasks which occasionally means connecting to Oracle [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I wrote about <a href="http://rawblock.blogspot.com/2007/02/ruby-oracle-mac-os-x-pain.html">my frustrations trying to get Ruby to talk to Oracle on Mac OS X</a>. I&#8217;ve tried a new approach using JRuby and ActiveRecord-JDBC with great success.</p>
<p>What I&#8217;m after is quite simple: I just want to use Ruby for some simple housekeeping scripting tasks which occasionally means connecting to Oracle to shunt data around. So this is all outside of Rails, which adds to the fun.</p>
<p>The basic problem with Oracle on Mac OS X is that Oracle support is lousy (add that to my <a href="http://rawblock.blogspot.com/2007/05/java-6-on-mac-os-x-when.html">list of complaints</a> <img src='http://www.rawblock.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ). There is no standard client install, hence no standard Oracle C libraries. While there is a stripped down version of the libraries &#8211; it is only available compiled for PowerPC. So no go with Intel CPUs (unless you want to recompile Ruby for PowerPC and run in emulation mode &#8211; just to allow you to build the OCI adapter. yech)</p>
<p>So I gave up.</p>
<p>Until I gave it another shot with <a href="http://www.jruby.org/">JRuby</a> and <a href="http://rubyforge.org/projects/jruby-extras">ActiveRecord-JDBC</a>. Here&#8217;s a quick guide:</p>
<h3>Install gems</h3>
<p>From the command line:</p>
<p><code>gem install activerecord</code><br/><br />
<code>gem install ActiveRecord-JDBC</code><br/></p>
<p>A trap for new players is to make sure you&#8217;re using JRuby <code>gem</code> utility, and not the Ruby one &#8211; tripped me up.</p>
<h3>Setup DB</h3>
<p>This can be whatever you&#8217;ve already got, or maybe a new DB. Here&#8217;s what I&#8217;m using for this example:</p>
<pre><code>--our table to test the setup.
--note standard activerecord setup with 'ID' as primary key
create table TEST_MESSAGES
(
  ID      NUMBER not null,
  MESSAGE VARCHAR2(100)
);
alter table TEST_MESSAGES
  add constraint test_messages_pk primary key (ID);

--sequence used to populate PK
create sequence test_messages_seq;</code></pre>
<h3>Setup your classpath</h3>
<p>Make sure you&#8217;ve got your Oracle JDBC driver in a handy directory, and run <code>export CLASSPATH=ojdbc14.jar</code> from your favourite command prompt. You can get the <code>ojdbc14.jar</code> driver file from <a href="http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html">Oracle&#8217;s  JDBC download page</a>, although in general I find Oracle&#8217;s site on a par with trying to <a href="http://en.wikipedia.org/wiki/The_Twelve_Tasks_of_Asterix#The_Twelve_Tasks">Find Permit A-38</a> in terms of frustration&#8230;</p>
<h3>Run some Ruby code against it</h3>
<p>Now for the fun bit.</p>
<pre><span class="comment"># active_record is the standard rails AR require</span>
<span class="ident">require</span> <span class="punct">'</span><span class="string">active_record</span><span class="punct">'</span>

<span class="comment"># jdbc_adapter is in ActiveRecord-JDBC, and makes a JDBC adapter </span>
<span class="comment"># available to ActiveRecord</span>
<span class="ident">require</span> <span class="punct">'</span><span class="string">active_record/connection_adapters/jdbc_adapter</span><span class="punct">'</span>

<span class="comment"># Connect to the database </span>
<span class="comment"># - this is required because we're running without rails.</span>
<span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">establish_connection</span><span class="punct">(</span><span class="symbol">:adapter</span>  <span class="punct">=></span> <span class="punct">'</span><span class="string">jdbc</span><span class="punct">',</span>
                                        <span class="symbol">:driver</span>   <span class="punct">=></span> <span class="punct">'</span><span class="string">oracle.jdbc.driver.OracleDriver</span><span class="punct">',</span>
                                        <span class="symbol">:url</span>      <span class="punct">=></span> <span class="punct">'</span><span class="string">jdbc:oracle:thin:@server:1521:database</span><span class="punct">',</span>
                                        <span class="symbol">:username</span> <span class="punct">=></span>  <span class="punct">'</span><span class="string">username</span><span class="punct">',</span>
                                        <span class="symbol">:password</span> <span class="punct">=></span>  <span class="punct">'</span><span class="string">password</span><span class="punct">')</span>

<span class="comment"># our model class that maps to the table we created</span>
<span class="keyword">class </span><span class="class">TestMessage</span> <span class="punct"><</span> <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span>
<span class="keyword">end</span>

<span class="comment"># insert a record                                </span>
<span class="ident">hi_message</span> <span class="punct">=</span> <span class="constant">TestMessage</span><span class="punct">.</span><span class="ident">new</span>
<span class="ident">hi_message</span><span class="punct">.</span><span class="ident">message</span><span class="punct">=</span> <span class="punct">'</span><span class="string">Hello World!</span><span class="punct">'</span>
<span class="ident">hi_message</span><span class="punct">.</span><span class="ident">save</span>

<span class="comment"># and another one for fun</span>
<span class="ident">ar_message</span> <span class="punct">=</span> <span class="constant">TestMessage</span><span class="punct">.</span><span class="ident">new</span>
<span class="ident">ar_message</span><span class="punct">.</span><span class="ident">message</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">This is activerecord JDBC on Oracle</span><span class="punct">'</span>
<span class="ident">ar_message</span><span class="punct">.</span><span class="ident">save</span>

<span class="comment"># should spit back out both our inserted records</span>
<span class="constant">TestMessage</span><span class="punct">.</span><span class="ident">find</span><span class="punct">(</span><span class="symbol">:all</span><span class="punct">).</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">m</span><span class="punct">|</span>
  <span class="ident">puts</span> <span class="ident">m</span><span class="punct">.</span><span class="ident">message</span>
<span class="keyword">end</span></pre>
<p>In this example I used ActiveRecord standard table structures, but in practice I was connecting to legacy databases. ActiveRecord is still quite useful with legacy databases, but you just have to do a <a href="http://www.robbyonrails.com/articles/2005/07/25/the-legacy-of-databases-with-rails">bit more setup</a>. <code>set_primary_key</code> and <code>set_table_name</code> will get you some of the way. <code>has_many</code> and <code>belongs_to</code> with the <code>:foreign_key</code> option will get you most of the rest of the way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/06/14/ruby-oracle-mac-os-x-pain-jruby-and-activerecord-jdbc-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/06/14/ruby-oracle-mac-os-x-pain-jruby-and-activerecord-jdbc-to-the-rescue/</feedburner:origLink></item>
		<item>
		<title>Ruby vs JRuby Fractal Benchmark</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/PMMlpuCp31o/</link>
		<comments>http://www.rawblock.com/2007/06/07/ruby-vs-jruby-fractal-benchmark/#comments</comments>
		<pubDate>Wed, 06 Jun 2007 13:43:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[jruby]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/06/07/ruby-vs-jruby-fractal-benchmark/</guid>
		<description><![CDATA[After reading about benchmarking various languages generating fractal patterns, I tried throwing the Ruby code at both the standard MRI Ruby and JRuby interpreters to compare relative performance. This is all totally unscientific, but is interesting all the same.
MRI Ruby (Matz Ruby Interpreter)

ruby 1.8.5 (2006-12-25 patchlevel 12) [i686-darwin8.8.1]
Rendering
Ruby Elapsed 6.732136

JRuby

ruby 1.8.5 (2007-06-04 rev 3812) [i386-jruby1.0.0RC3]
Rendering
Ruby [...]]]></description>
			<content:encoded><![CDATA[<p>After reading about benchmarking various languages <a href="http://www.timestretch.com/FractalBenchmark.html">generating fractal patterns</a>, I tried throwing the Ruby code at both the standard MRI Ruby and JRuby interpreters to compare relative performance. This is all totally unscientific, but is interesting all the same.</p>
<p><strong>MRI Ruby (Matz Ruby Interpreter)</strong><br/><br />
<code><br />
ruby 1.8.5 (2006-12-25 patchlevel 12) [i686-darwin8.8.1]<br/><br />
Rendering<br/><br />
Ruby Elapsed <strong>6.732136</strong><br />
</code></p>
<p><strong>JRuby</strong><br/><br />
<code><br />
ruby 1.8.5 (2007-06-04 rev 3812) [i386-jruby1.0.0RC3]<br/><br />
Rendering<br/><br />
Ruby Elapsed <strong>68.757000</strong><br />
</code></p>
<p>C Ruby is the clear winner, but that&#8217;s not so surprising. What is surprising is how far JRuby was behind &#8211; by at least 10 times. I&#8217;ve heard good things about JRuby&#8217;s ability to compile Ruby down to bytecode, but I didn&#8217;t have too much luck with that. Admittedly I didn&#8217;t play around with it for long.</p>
<p>I was curious where the bottlenecks are in both versions. After running the code through both VMs with the <code>-r profile</code> flag, really slow floating point operations turned out to be the culprit. The profile for each was pretty much identical. Lots of float operations (+ / < * etc), with everything multiplied by 10 for the JRuby VM.</p>
<p>So what does this tell us? Pretty much nothing. Most apps won&#8217;t be doing this kind of CPU heavy crunching (and if you&#8217;re using an interpreted language you&#8217;re asking for trouble). Especially the kind of apps you&#8217;d use either MRI Ruby or JRuby for, which spend most of their time waiting for the database. I might have another play and see if I can get JRuby to run using bytecode &#8211; the hype is that it will be as fast if not faster than MRI.</p>
<p><em>Disclaimer &#8211; I&#8217;m actually a huge fan of both MRI Ruby and JRuby and just did this out of curiosity. Put AWAY the flame torches now&#8230;</em></p>
<h2><em>Update &#8211; JRuby can actually be as fast or faster than MRI</em></h2>
<p><a href="http://headius.blogspot.com/">Charles Oliver Nutter</a> (of the JRuby team), has added some suggestions for tuning the JRuby VM. The following is also in the comments, but I&#8217;ve included it in the main post as it is useful information that might get missed. What is really interesting is that JRuby is <em>faster</em> in this case when the VM is tuned and the code gets a chance to run enough for the JIT compiler to kick in.</p>
<blockquote><p>FYI, I grabbed the code in question to try it out myself. These are my numbers using JRuby trunk (not really different from RC3), Java 6 server VM on OS X, and the following command line:</p>
<p>jruby -J-server -J-Djruby.jit.threshold=0 -O fractal.rb</p>
<p>JRuby:<br/><br />
Ruby Elapsed 6.454000</p>
<p>Ruby 1.8.6:<br/><br />
Ruby Elapsed 6.971203</p>
<p>The command line above adds three options:</p>
<p>-J-server turns on the server VM</p>
<p>-J-Djruby.jit.threshold=0 sets the JIT threshold to zero, so it will try to compile methods immediately (critically important for this benchmark since the methods are only called once), and -O turns off ObjectSpace, which is pure overhead for us.</p>
<p>Additionally, if I let the benchmark run ten times, allowing the JVM to optimize it further, I get the following result for JRuby on the tenth iteration:</p>
<p>Ruby Elapsed 5.629000</p>
<p>There&#8217;s a good page in the JRuby Wiki for <a href="http://www.headius.com/jrubywiki/index.php/Performance_Tuning">performance tuning JRuby</a>. The reason this wasn&#8217;t compiling is twofold: the methods weren&#8217;t called enough times to trigger the JIT, and the script itself had a &#8220;class&#8221; definition in it, which the compiler doesn&#8217;t yet handle.</p>
</blockquote>
<p>Cheers Charles, extremely useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/06/07/ruby-vs-jruby-fractal-benchmark/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/06/07/ruby-vs-jruby-fractal-benchmark/</feedburner:origLink></item>
		<item>
		<title>Interview with Shine Technologies, and get a Playstation 3 (or bottle of Grange)!</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/TTrxYCKdlm4/</link>
		<comments>http://www.rawblock.com/2007/06/06/interview-with-shine-technologies-and-get-a-playstation-3-or-bottle-of-grange/#comments</comments>
		<pubDate>Wed, 06 Jun 2007 04:29:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[recruitment]]></category>
		<category><![CDATA[shine]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/06/06/interview-with-shine-technologies-and-get-a-playstation-3-or-bottle-of-grange/</guid>
		<description><![CDATA[Like most Melbourne software shops, Shine Technologies (where I work), is going through a bit of a boom at the moment and is in hiring mode.
To stand out from the crowd, Shine has come up with this idea
If you are successful in securing a second round interview, we are confident you will want to work [...]]]></description>
			<content:encoded><![CDATA[<p>Like most Melbourne software shops, <a href="http://www.shinetech.com">Shine Technologies</a> (where I work), is going through a bit of a boom at the moment and is in hiring mode.</p>
<p>To stand out from the crowd, Shine has come up with <a href="http://www.shinetech.com/display/www/Current+Opportunities">this idea</a></p>
<blockquote><p><em>If you are successful in securing a second round interview, we are confident you will want to work at Shine Technologies&#8230;. and to prove it, we will give you a PS3 or a Bottle of Grange Hermitage!</em></p></blockquote>
<p>That&#8217;s just for getting to the 2nd round interview &#8211; not even as a signing bonus!</p>
<p>When you&#8217;re working at Shine there is a whole host of <a href="http://www.shinetech.com/display/www/Working+At+Shine">things to like</a>. The other pluses that aren&#8217;t mentioned are that you might get to work with me <img src='http://www.rawblock.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  (which may be a negative depending on your point of view&#8230;), and this is the view from Shine&#8217;s main office (where you may end up working, depending on client projects). 34 floors up smack in the middle of the Melbourne CBD:</p>
<p><a href="http://www.flickr.com/photos/8695788@N05/532751941/" title="Photo Sharing"><img src="http://farm2.static.flickr.com/1166/532751941_a68d2cd0f8.jpg" width="500" height="375" alt="View from Shine HQ" /></a></p>
<p><a href="http://www.shinetech.com/display/www/Current+Opportunities">More details</a> at Shine Technologies&#8217; website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/06/06/interview-with-shine-technologies-and-get-a-playstation-3-or-bottle-of-grange/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/06/06/interview-with-shine-technologies-and-get-a-playstation-3-or-bottle-of-grange/</feedburner:origLink></item>
		<item>
		<title>Java 6 on Mac OS X – When?</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/5Cj8Fr_6eyU/</link>
		<comments>http://www.rawblock.com/2007/05/30/java-6-on-mac-os-x-when/#comments</comments>
		<pubDate>Wed, 30 May 2007 12:58:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[mac os x]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/05/30/java-6-on-mac-os-x-when/</guid>
		<description><![CDATA[Developing Java apps on Mac OS X is pretty nice in general: The tools are as good, if not better than other platforms (having a proper command line beats Windows any day); compiling and execution runs fast enough; and the hardware and the OS itself is a pleasure to use.
My only complaint, and one that [...]]]></description>
			<content:encoded><![CDATA[<p>Developing Java apps on Mac OS X is pretty nice in general: The tools are as good, if not better than other platforms (having a proper command line beats Windows any day); compiling and execution runs fast enough; and the hardware and the OS itself is a pleasure to use.</p>
<p>My only complaint, and one that is getting a bit of noise, is that there is no production release of Java 6 available. Sure, there is a preview version from months ago. But the final version has more than a few differences in the API, and I&#8217;m guessing a stack of defect and performance fixes as well.</p>
<p>The rumor is that Apple is not releasing Java 6 till Leopard ships (around October). Supposedly so Java 6 on OS X will support the Leopard look and feel. Which is a pain in the neck &#8211; I couldn&#8217;t care less if Java 6 looks like Leopard. To be honest it&#8217;s a pretty small minority that must use it as a runtime environment. However OS X must get a lot of use as a <em>development</em> environment. Most of the development I do is for apps that are going to run on Windows anyway. Surely Java 6 could just be released first, and then a separate look and feel plugin for Leopard released after the fact? (it&#8217;s not like that is all that hard with Swing)</p>
<p>The rumors about Leopard are just that &#8211; rumors. There hasn&#8217;t been anything official from Apple saying what the release schedule looks like.</p>
<p>Simon Brocklehurst <a href="http://www.psynixis.com/blog/2007/05/29/will-apple-developer-community-take-over-java-on-mac-os-x/">sums it up:</a></p>
<blockquote><p><em>What is particularly frustrating, however, is that Apple remains totally silent on their Java strategy. When will Java 6 see a production release on MacOS X? With the Leopard release? Somtime in 2008? In 2015? Never? No-one has any idea; and Apple isn’t talking &#8211; not to developers; not to customers; not to anyone.</p>
<p>Now, however, the OpenJDK project is… well… open! The Java platform is moving full steam ahead to Open Source under the GPL. All of which begs the question is: will the Apple developer community decide to build their own up-to-date version of Java that runs on MacOS X? If Apple would only make their Java strategy clear, it might help the community figure out if that’s worth doing or not…</em></p>
</blockquote>
<p>I can live with delayed releases, but it makes planning development a bit more difficult when you&#8217;re playing guessing games. A little more certainty would be nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/05/30/java-6-on-mac-os-x-when/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/05/30/java-6-on-mac-os-x-when/</feedburner:origLink></item>
		<item>
		<title>OK, JavaFX Script is pretty cool (the platform is still boring though)</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/oyikATdFcWA/</link>
		<comments>http://www.rawblock.com/2007/05/22/ok-javafx-script-is-pretty-cool-the-platform-is-still-boring-though/#comments</comments>
		<pubDate>Tue, 22 May 2007 12:09:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/05/22/ok-javafx-script-is-pretty-cool-the-platform-is-still-boring-though/</guid>
		<description><![CDATA[Despite my last post, I&#8217;m not actually a raving anti JavaFX maniac &#8211; the script language itself is really pretty cool. I&#8217;ve been following what would become JavaFX script since when it was called F3, and have been impressed by what it can do. Both in terms of the language syntax, and the power it [...]]]></description>
			<content:encoded><![CDATA[<p>Despite my <a href="http://rawblock.blogspot.com/2007/05/flex-silverlight-javafx-who-cares.html">last post</a>, I&#8217;m not actually a raving anti JavaFX maniac &#8211; the script language itself is really pretty cool. I&#8217;ve been following what would become JavaFX script since when it was called <a href="http://rawblock.blogspot.com/2007/01/f3swiby-style-declaration-blocks.html">F3</a>, and have been impressed by what it can do. Both in terms of the language syntax, and the power it gives you in certain areas. </p>
<p>It is very Swing friendly, and the technically, the current version provides a lot of functionality to make life easier building Swing apps. Which kinda reinforces to me that that the JavaFX as an RIA <strong>*platform*</strong> reeks of &#8220;me too!&#8221; from Sun&#8217;s marketing department in response to Flex and Silverlight.</p>
<p>JavaFX&#8217;s <a href="http://www.sun.com/software/javafx/index.jsp">homepage</a> will tell you that <em>&#8220;JavaFX Script is a highly productive scripting language for content developers to create rich media and interactive content&#8221;</em> &#8211; which I don&#8217;t quite follow. Cause it&#8217;s Swing. And while Swing is really good at regular GUIs (once you get your head around the massive API and the traps for new players), it&#8217;s got pretty weak support for &#8220;rich media and interactive content&#8221; (whatever that means) unless you are someone like <a href="http://www.curious-creature.org/">Romain Guy</a> and have time and talent to come up with a bunch of cool hacks and work around more than a few limitations with the technology.</p>
<p>While I&#8217;m dubious of the potential of the platform, I think the scripting language itself is one of the most interesting things to happen around Swing in a long time. It comes about as close as anything to the dream framework I talked about in <a href="http://rawblock.blogspot.com/2007/02/jruby-can-save-swing.html">JRuby Can Save Swing</a>. It&#8217;s a pity that Sun didn&#8217;t push it in the desktop app direction, but I guess straight desktop apps just aren&#8217;t that sexy at the moment&#8230;</p>
<p>Anyway, here&#8217;s a quick round up of some the &#8220;kick ass&#8221; bits in JavaFX Script that caught my attention. <a href="https://openjfx.dev.java.net/JavaFX_Programming_Language.html">The JavaFX Script Programming Language</a> contains details on most of the core concepts. It&#8217;s not 100% complete, as there are a few other tidbits in the demos and the tutorial examples that show other features.</p>
<h3>Calling Java Objects</h3>
<p>OK, this one is kinda a no brainer. If it didn&#8217;t do this there would be trouble. I&#8217;m mentioning it just because it means you&#8217;ve got a lot of existing Java libraries you can hook in without much hassle. Scripting in the JVM is the other big buzz concept these days (and with good cause).</p>
<h3>Cardinality Operators On Variables</h3>
<p>When declaring a variable, you can add the following operators:</p>
<ul>
<li><strong>?</strong> &#8211; optional. may be null (not sure if things that don&#8217;t have ? are non-nullable or not?)</li>
<li><strong>+</strong> &#8211; one or more</li>
<li><strong>*</strong> &#8211; zero or more</li>
</ul>
<p>By themselves these are just another way of declaring arrays, <em>but</em> they tie in nicely with&#8230;</p>
<h3>Inverse Attributes</h3>
<p>Sure, JavaFX Script has your standard OO structure with classes and attributes that everyone knows and loves. The cool part is that you can define bi-directional inverse relationships. The effect is that when the instance on one end of the link is updated, the other end is updated in turn &#8211; kind of like cascading foreign keys. This example is the example given on the <a href="https://openjfx.dev.java.net/JavaFX_Programming_Language.html">reference page</a>:</p>
<pre><code>class Person {
    attribute name: String;
    attribute parent: Person inverse Person.children;
    attribute children: Person* inverse Person.parent;
    function getFamilyIncome(): Number;
    function getNumberOfChildren(): Number;
    operation marry(spouse: Person);
}</code></pre>
<p>The idea is that when a child is added to a parent, the parent value is automagically set. When a child&#8217;s parent is changed (in some strange circumstance&#8230;), the child is automagically added to the list of children on the parent object.</p>
<h3>Array Manipulation</h3>
<p>There is some nice syntax for working with arrays of objects as well. It all feels very SQLish. You can insert like SQL with <code>insert myFoo first into barArray</code> to insert in the first position, or <code>insert myFoo after barArray[.=='foo']</code> to insert myFoo after whatever item in the array has the value of &#8216;foo&#8217;. </p>
<p>Or you can delete like SQL with <code>delete barArray[.=='foo']</code> to remove the item with the value of &#8216;foo&#8217; from the array. (The inverse attribute magic hooks in with these apparently)</p>
<p>You can even select like SQL (or like functional list comprehensions) with <code>select name from album in albums where artist == "Nine Inch Nails"</code> (there is a similar construct with <code>foreach</code> as well).</p>
<h3>Pure Functions</h3>
<p>Not really something you couldn&#8217;t do in plain old Java if you wanted to (except without the side effect guarantee), but it&#8217;s interesting that pure functions are supported as well. A pure function just has variable declarations and a return statement &#8211; which makes sure that pure functions don&#8217;t have any nasty side effects, and can be used in a functional programming style. Don&#8217;t worry, there are still regular procedures in there as well, which are called &#8220;operations&#8221; instead.</p>
<h3>Incremental and Lazy Evaluation</h3>
<p>This is a really nice touch, and will be one of the things that makes Swing a pleasure to work with. The <code>bind</code> operator will cause one variable to be &#8220;bound&#8221; to the other. When the value of the original is changed, the bound variable is automatically updated with the new value. This makes binding GUI views and models together super easy. Here&#8217;s some more code from the <a href="https://openjfx.dev.java.net/Getting_Started_With_JavaFX.html#add_dynamic">tutorials page</a> which shows it off:</p>
<pre><code>class HelloWorldModel {
    attribute saying: String;
}

var model = HelloWorldModel {
    saying: "Hello World"
};

var win = Frame {
    title: "Hello World JavaFX"
    width: 200

    content: Label {
        text: bind model.saying
    }
    visible: true
};</code></pre>
<p>What this means is that whenever the value of <code>saying</code> in the <code>model</code> instance changes, the GUI Label is automagically updated &#8211; no need for messy listener glue code.</p>
<p>Now it gets even cooler. You can even bind strings that contain embedded expressions &#8211; similiar to using the <code>"Hello, I'm #{name}"</code> syntax in Ruby. When the value of a variable in a bound string changes, the variable it is bound to changes as well:</p>
<pre><code>class HelloWorldModel {
    attribute saying: String;
}

var model = HelloWorldModel {
    saying: "Hello World"
};

var win = Frame {
    title: bind "{model.saying} JavaFX"
    width: 200
    content: TextField {
        value: bind model.saying
    }
    visible: true
};</code></pre>
<p>And whenever the value of <code>model.saying</code> changes, the title is automagically updated!</p>
<h3>Triggers</h3>
<p>Related to bind (at least for Swing), is the use of triggers. When a value is changed on a JavaFX script GUI widget, a trigger is fired to set the text etc on the underlying Swing component. There are no custom setters or getters in JavaFX Script, but you can define custom behaviour using triggers. These are pretty similar to a database trigger. It&#8217;s really just some code that gets executed whenever a variable on a class instance is changed</p>
<h3>Swing Event Dispatch Thread Support</h3>
<p>As every Swing developer gets beaten into them DO NOT MESS WITH THE EVENT DISPATCH THREAD. For the non Swing readers, the Event Dispatch Thread (or EDT for short) handles all user input and rendering in a separate thread to the main app thread. In particular, it&#8217;s considered bad form to execute long running tasks on it (users have to wait a long time for response to their action and the GUI appears locked). And it&#8217;s also bad to update the GUI directly from a thread other than the EDT (Swing components aren&#8217;t thread safe).</p>
<p>This is a pain in regular Swing. There are a few frameworks for handling background operations (<a href="https://swingworker.dev.java.net/">SwingWorker</a> etc), and you can use the helper methods in <a href="http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html">SwingUtilities</a> to safely interact with the EDT from other threads. But it means constructing awkward <code>Runnable</code> instances, usually as verbose anonymous inner classes, and passing them around.</p>
<p>JavaFX Script has some nice syntax sugar to take care of this. The <code>do</code> block allows you to execute a block of code asynchronously in another thread to the EDT (avoiding GUI lock up).</p>
<pre><code>import java.lang.StringBuffer;
// in the AWT EDT
var input = getInput();
var calcResult = new StringBuffer();

do {
    // now in a background thread
    calcResult.append(doHeavyCalculationWithInput(input));
}
// now back in the EDT
System.out.println("result = {calcResult}");</code></pre>
<p>This will cause the heavy calcuation to be done in a separate thread, while the EDT can carry on rendering and accepting user input (actually that&#8217;s not quite true as there is a hack with the EventQueue involved &#8211; but close enough). There are some gotchas with it though, so it would pay to read up on how it works first.</p>
<p>The other piece of this puzzle is the <code>do later</code> block which is executed in a piece of code running in a separate thread to update the GUI in a threadsafe manner. The idea is that your background thread goes off and does work, then when it is ready to display the results, it executes some code in a <code>do later</code> block to safely populate it to the GUI.</p>
<h3>Conclusion</h3>
<p>All up, there is some interesting stuff in JavaFX Script. I&#8217;ll have to have a play with it some more as it develops. Although I still don&#8217;t get the marketing blitz, the ease it should add to Swing development will be a welcome addition.</p>
<p>There is even a <a href="http://download.java.net/general/openjfx/demos/javafxpad.jnlp">webstart sandbox app</a> that lets you play around with the language and instantly see the results. Well worth checking out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/05/22/ok-javafx-script-is-pretty-cool-the-platform-is-still-boring-though/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/05/22/ok-javafx-script-is-pretty-cool-the-platform-is-still-boring-though/</feedburner:origLink></item>
		<item>
		<title>Flex, Silverlight, JavaFX – Who cares?</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/zYiwHpq9HNw/</link>
		<comments>http://www.rawblock.com/2007/05/15/flex-silverlight-javafx-who-cares/#comments</comments>
		<pubDate>Tue, 15 May 2007 07:17:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[javafx]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/05/15/flex-silverlight-javafx-who-cares/</guid>
		<description><![CDATA[It seems every Blue Chip and his dog is announcing a post Web2.0 RIA development tool these days. Adobe has Flex (aka Flash), Microsoft has Silverlight (aka ActiveX), and Sun announced JavaFX at JavaOne last week (aka Java applets). Now even Firefox is making noise about how Firefox will have features designed to go head-to-head [...]]]></description>
			<content:encoded><![CDATA[<p>It seems every Blue Chip and his dog is announcing a post Web2.0 <a href="http://en.wikipedia.org/wiki/Rich_Internet_Applications">RIA</a> development tool these days. Adobe has <a href="http://www.adobe.com/products/flex/">Flex</a> (aka Flash), Microsoft has <a href="http://www.microsoft.com/silverlight/default01.aspx">Silverlight</a> (aka ActiveX), and Sun announced <a href ="http://www.sun.com/software/javafx/">JavaFX</a> at JavaOne last week (aka Java applets). Now even Firefox is making noise about how Firefox will have features designed to <a href="http://apcmag.com/6045/firefox_to_go_head_to_head_with_flash_and_silverlight">go head-to-head with Flash and Silverlight</a>! (I had hoped browser builders had learnt their lessons about proprietary browser tech in Browser War I&#8230;)</p>
<p>To me, this just seems like a bunch of old ideas repackaged with new Web2.0 marketing spin. It&#8217;s difficult to find developers genuinely excited about all this. Most of the noise seems to be coming from the big companies themselves.</p>
<p>Browser plugins have been dead for a while now. Java applets were never really that good to begin with and died shortly after birth. ActiveX kinda faded away due to security problems and cross-browser incompatibilities. Flash is still around, but really only used for (annoying) movie trailer sites, obnoxious web ads, and YouTube. It&#8217;s surprising that these ideas are being dredged up again and touted as the Next Big Thing.</p>
<p>It will be interesting to see where these platforms go. My guess is that they&#8217;ll fade into irrelevance before long due to developer apathy (<a href="http://www.microsoft.com/silverlight/images/video_btn_mac.jpg">users hate plugins</a> as well, but thats another post). The main warning sign is that most of the noise out there at the moment isn&#8217;t from excited bloggers writing <i>&quot;Check out this cool Foobar app that I wrote in Silverlight/Flex/JavaFX!&quot;</i>. No. Mostly the blogosphere is talking about press releases with an occasional overview of the technologies at a high level. No killer apps (or even mildly dangerous apps), no new possibilities that weren&#8217;t there before. Just promises of more of the same, except a bit easier and whizzier, and with video content (as if the only thing stopping every 2nd developer launching the next youtube was the current technology&#8230;). All done with a corporate designed feel and colour scheme. There just isn&#8217;t the grassroots enthusiasm there. That has to be grown organically. Not built by a marketing team.</p>
<p>These platforms are all trying to emulate and replace Ajax. The current usage of Ajax wasn&#8217;t engineered. It almost happened by accident through a combination of new uses of existing tech, new ideas, and realisation of new needs. There was no big bang product release, or big marketing campaign, or corporate backing. Just a grassroots momentum that built on its own due to developers seeing value in the technology and users enjoying the results. It helped that the mum and dad users didn&#8217;t have to install any additional plugins to use gmail or youtube as well.</p>
<p>Realistically, I think Ajax will be around for a while. It&#8217;s just that it&#8217;ll get easier to build as new supporting technologies are developed. The tech to watch are the ones that have a slow rumbling build up, then exponentially grow to a roar due to the passionate developers actually getting real value out of them. Look where Rails, Ruby and dynamic languages were a couple of years ago, and you&#8217;d find a few fanatical supporters that were passionate about it just because they could see the value. Look where Erlang and other functional languages are now and you see the same thing. They are the ones to watch. The technologies with the slow groundswell of support rather than the hollow big bang spin fest.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/05/15/flex-silverlight-javafx-who-cares/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/05/15/flex-silverlight-javafx-who-cares/</feedburner:origLink></item>
		<item>
		<title>Make The Right Way Of Doing Software Development The Path Of Least Resistance</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/j7FqsmmacF0/</link>
		<comments>http://www.rawblock.com/2007/05/11/make-the-right-way-of-doing-software-development-the-path-of-least-resistance/#comments</comments>
		<pubDate>Fri, 11 May 2007 01:51:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/05/11/make-the-right-way-of-doing-software-development-the-path-of-least-resistance/</guid>
		<description><![CDATA[Imagine you&#8217;re standing in the middle of the countryside. You&#8217;ve got a place to be which is several kilometers away. How do you get there? You&#8217;ll probably just take the quickest, most easy route. It&#8217;s not necessarily the most direct route (that might go through a swamp or up the side of a mountain), but [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine you&#8217;re standing in the middle of the countryside. You&#8217;ve got a place to be which is several kilometers away. How do you get there? You&#8217;ll probably just take the quickest, most easy route. It&#8217;s not necessarily the most direct route (that might go through a swamp or up the side of a mountain), but it&#8217;s the route with the <a href="http://en.wikipedia.org/wiki/Path_of_least_resistance">path of least resistance.</a><br />
<a href="http://en.wikipedia.org/wiki/Path_of_least_resistance"><img src="http://upload.wikimedia.org/wikipedia/en/9/98/Cartoon_mountain_pass_symbolizing_path_of_least_resistance.gif"/></a><br />
The path of least resistance originally refers to electrons flowing though a circuit &#8211; the amount of current at any point in the circuit is inversely related to the amount of electrical resistance that the path at that point in the circuit has. It&#8217;s the same thing when you&#8217;re walking out in the country. If a given route is easy, you&#8217;re more likely to go that way to get to your destination. You&#8217;re less likely to go through obstacles (unless you&#8217;re into parkour or mountain biking&#8230;)</p>
<h2>Think of the kodos and crocolisks</h2>
<p>Now say that the direct route marches right through the middle of the endangered Giant Kodo habitat grounds, and then through the rare Crocolisk breeding grounds (both of which have been brought to the brink of extinction by over-zealous gold farming). The local environmental groups decide to do something about these rawblockers tramping through. The Kodo protection group constructs a big fence, while the the Crocolisk preservation association has built a paved track around the edge that actually ends up being quicker (but you can still go through if you want).</p>
<p>What is your new path going to look like? You&#8217;ll still take the easiest route. It&#8217;s just that it&#8217;s a different route now. The path of least resistance now involves having to detour around the Kodo&#8217;s, but you&#8217;ve <strong>chosen</strong> to take the new Crocolisk bypass track &#8211; because it&#8217;s quicker. The distinction is important. It&#8217;s all about the path of least resistance, and how it can be manipulated to achieve a result in the desired manner: either by making the undesirable paths harder; or by making the desirable path easier.</p>
<h2>So what does this have to do with coding?</h2>
<p>Exactly the same thing applies when developing software. There are dozens of ways to accomplish a given programming task. Developers are lazy, and will generally choose the solution that fits the constraints with the least amount of work. &#8220;Work&#8221; and &#8220;Constraints&#8221; are incredibly subjective terms, so it&#8217;s worth discussing them.</p>
<h3>Work</h3>
<p>&#8220;Work&#8221; is the measure of how much effort is expended. How hard is it, how long does it take. Some examples:</p>
<ul>
<li>Time spent coding = effort (with some exceptions for doing heavy geeking)</li>
<li>Testing, documentation = effort</li>
<li>Doing tedious boilerplate code = extra effort</li>
<li>Using heavy syntax that requires frequent use of thick documentation = extra effort</li>
<li>5 minute deploy and test cycle = extra effort</li>
<li>Interfacing with a buggy, badly documented external systems = extra <em>extra</em> effort</li>
</ul>
<h3>Constraints</h3>
<p>&#8220;Constraints&#8221; is everything that limits the set of solutions a developer will consider. This includes obvious ones (like the actual software requirements), but also less tangible subconscious constraints. Some examples:</p>
<ul>
<li>The client&#8217;s requirements = constraint</li>
<li>Personal pride in your work = constraint</li>
<li>Desire for respect from peers = constraint</li>
<li>Corporate development process = constraint</li>
<li>Project deadline = constraint</li>
</ul>
<p>When you think about it, the constraints are really just a multiplier that affects the amount of effort. There may be a constraint that says <em>&#8220;This project will be developed in language Foo&#8221;.</em> Now you <em>could</em> go ahead and develop it in language <em>Bar</em>, but you have a lot of work on your hands explaining why you did that, and potentially redoing it all in the specified language &#8211; the effort to develop in language <em>Bar</em> has made it too costly to be considered an option. The path of least resistance is just to go with the flow and develop in the prescribed language.</p>
<h2>Tweaking the path of least resistance to get what you want</h2>
<p>Work and constraints apply at the micro-level of a single developer or a small team. They may end up optimizing on a <a href="http://en.wikipedia.org/wiki/Local_minima">local-minima</a>, and be using an approach that has an overall negative aspect (such as copy/paste coding, or hard coding configuration data). If you&#8217;re in charge of a bunch of programmers, what&#8217;s the way to handle this? (assuming you can spot it &#8211; which is a whole other problem&#8230;)</p>
<p>Like with the Kodos and the Crockolisks, you can tweak the path of least resistance in a couple of ways: </p>
<h3>Adding extra constraints</h3>
<p>The most obvious way is to put extra constraints in that make it harder to do the wrong thing. This is the usual knee-jerk reaction to solve a perceived problem. <em>&#8220;The developers are not using best practice! Lets add an extra layer of process and make 3 layers of management sign off another TPS form so that they are forced to do things properly!&#8221;</em>. The path of least resistance is now to jump through the process hoop, and not do whatever was wrong before. This has a double whammy effect on the poor developers: They have to use a harder solution that doesn&#8217;t have the negative side effects (which is partly good &#8211; they aren&#8217;t trampling Kodos). But it adds even more process work on top the heavier best practice approach that was unattractive before (which is bad for obvious reasons).</p>
<h3>Making best practice easier</h3>
<p>The other option is to make the desired path more attractive. When you look at the root cause for developers not doing things properly, it could be that the key APIs on a project are heavy-weight and difficult to use. The solution may be to refactor these to make them easier to use. This is win-win. The developers are now more productive; are doing things properly; and don&#8217;t have to waste time with excess process (the problem has been reduced, so the process to fix it isn&#8217;t required).</p>
<p>This is similar to the <a href="http://en.wikipedia.org/wiki/Carrot_and_stick">carrot and stick</a> approach, but is subtly different. Carrot and stick rewards/punishes various behavior to get the desired result. Thinking of a process in terms of the path of least resistance means changing the process itself so that the desired behavior is the easiest behavior.</p>
<p>Agile development in general, and Ruby on Rails in particular use exactly this approach to encourage developers to use best practice. When developing a Rails app, it is incredibly easy to use good practices such as proper project structure/test driven development/separation of concerns/DRY etc. Contrast this with J2EE &#8211; which has a multitude of ways for producing a mess, with a smaller more difficult set of approaches for producing a good clean structure. It&#8217;s no surprise that a lot more process is required to keep a J2EE project on track compared with a Rails project.</p>
<p>This is what I was hinting at a while back in <a href="http://rawblock.blogspot.com/2007/02/jruby-can-save-swing.html">JRuby can save Swing</a>. Swing is a great API that gives you a lot of power. It&#8217;s just that the path of least resistance for building Swing apps is not pretty: <a href="http://www.martinfowler.com/eaaDev/AutonomousView.html">autonomous views</a> with tightly coupled, inflexible model and view code. A properly architected Swing app can be a thing of beauty and can elegantly grow and evolve as required. The solution I was talking about would provide a new Railsesque API layer in JRuby that would encourage developers to properly structure their Swing app using best practices.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/05/11/make-the-right-way-of-doing-software-development-the-path-of-least-resistance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/05/11/make-the-right-way-of-doing-software-development-the-path-of-least-resistance/</feedburner:origLink></item>
		<item>
		<title>Shine coverage of JavaOne</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/cOMEclyNhmQ/</link>
		<comments>http://www.rawblock.com/2007/05/10/shine-coverage-of-javaone/#comments</comments>
		<pubDate>Wed, 09 May 2007 13:51:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[shine]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/05/10/shine-coverage-of-javaone/</guid>
		<description><![CDATA[Shine Technologies (my workplace) has sent a couple of international jet setters over to San Francisco for this year&#8217;s JavaOne conference.
Mark Johnson and Ben Teese have been writing about their experiences on Shine&#8217;s blog. Reports on various presentations and the keynote are covered.
Meanwhile I&#8217;ve been sent to lovely Tasmania. Which is kind of overseas&#8230; well [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.shinetech.com">Shine Technologies</a> (my workplace) has sent a couple of international jet setters over to San Francisco for this year&#8217;s <a href="http://java.sun.com/javaone/sf/">JavaOne</a> conference.</p>
<p>Mark Johnson and Ben Teese have been writing about their experiences on <a href="http://blog.shinetech.com/">Shine&#8217;s blog</a>. Reports on various presentations and the keynote are covered.</p>
<p>Meanwhile I&#8217;ve been sent to lovely Tasmania. Which is kind of overseas&#8230; well I mean you fly over the sea to get here from mainland Australia. Anyway, the beer is better here than on the mainland and the cooler climate is more suited to my kiwi body temperature.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/05/10/shine-coverage-of-javaone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/05/10/shine-coverage-of-javaone/</feedburner:origLink></item>
		<item>
		<title>Ruby multiple assignment to create unit test data</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/QIaaGiXvGNk/</link>
		<comments>http://www.rawblock.com/2007/05/02/ruby-multiple-assignment-to-create-unit-test-data/#comments</comments>
		<pubDate>Tue, 01 May 2007 23:39:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/05/02/ruby-multiple-assignment-to-create-unit-test-data/</guid>
		<description><![CDATA[One of the tedious parts of writing unit tests is populating varying test data. Often you can wrap it all up into an array and iterate over it, other times you&#8217;re more interested in the individual objects and their interactions.
It&#8217;s not hard, but it takes up a few lines initializing each one separately. Less typing [...]]]></description>
			<content:encoded><![CDATA[<p>One of the tedious parts of writing unit tests is populating varying test data. Often you can wrap it all up into an array and iterate over it, other times you&#8217;re more interested in the individual objects and their interactions.</p>
<p>It&#8217;s not hard, but it takes up a few lines initializing each one separately. Less typing is better! Luckily, you can use Ruby&#8217;s multiple assignment operator to map all the objects you need in one hit to make your life easier:</p>
<pre><span class="keyword">def </span><span class="method">test_exam_result</span>
  <span class="ident">a</span><span class="punct">,</span><span class="ident">b</span><span class="punct">,</span><span class="ident">c</span><span class="punct">,</span><span class="ident">d</span><span class="punct">,</span><span class="ident">e</span><span class="punct">,</span><span class="ident">f</span> <span class="punct">=</span> <span class="punct">('</span><span class="string">A</span><span class="punct">'..'</span><span class="string">F</span><span class="punct">').</span><span class="ident">map</span><span class="punct">{|</span><span class="ident">v</span><span class="punct">|</span> <span class="constant">MyObject</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="constant">v</span><span class="punct">)}</span>

  <span class="ident">assert</span> <span class="ident">stuff</span><span class="punct">(</span><span class="ident">a</span><span class="punct">,</span><span class="ident">b</span><span class="punct">,</span><span class="ident">c</span><span class="punct">)</span>
  <span class="ident">assert</span> <span class="ident">other_stuff</span><span class="punct">(</span><span class="ident">c</span><span class="punct">,</span><span class="ident">b</span><span class="punct">,</span><span class="ident">f</span><span class="punct">)</span>
  <span class="ident">assert</span> <span class="ident">d_hates_a</span><span class="punct">(</span><span class="ident">d</span><span class="punct">,</span><span class="ident">a</span><span class="punct">)</span>
<span class="keyword">end</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/05/02/ruby-multiple-assignment-to-create-unit-test-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/05/02/ruby-multiple-assignment-to-create-unit-test-data/</feedburner:origLink></item>
		<item>
		<title>List Manipulation in Java and Ruby</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/aORJQf2fI24/</link>
		<comments>http://www.rawblock.com/2007/04/13/list-manipulation-in-java-and-ruby/#comments</comments>
		<pubDate>Fri, 13 Apr 2007 06:13:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/04/13/list-manipulation-in-java-and-ruby/</guid>
		<description><![CDATA[After doing a bit of Ruby coding, I get that &#34;this should be easier&#34; feeling when working in Java for any length of time. An example of that is doing some simple operation on a list. In this case, I&#8217;m wanting to do something trivial.
The task is simple: given an unsorted list of objects, find [...]]]></description>
			<content:encoded><![CDATA[<p>After doing a bit of Ruby coding, I get that &quot;this should be easier&quot; feeling when working in Java for any length of time. An example of that is doing some simple operation on a list. In this case, I&#8217;m wanting to do something trivial.</p>
<p>The task is simple: <em>given an unsorted list of objects, find the lowest value of some property</em>.</p>
<p>In Java this would look something like:</p>
<pre><code>Date startFoo = null;
for(Foo f : getFoos()) {
  if (startFoo == null) {
    startFoo = f.getStartDate();
  } else {
    startFoo = (startFoo.before(f.getStartDate()) ? startFoo : f.getStartDate());
  }
}</code></pre>
<p>And in Ruby, this would look something like:</p>
<pre><code>get_foos.map{|f| f.start_date}.inject{|low,start| low < start ? low : start}</code></pre>
<p>Not a huge difference in code length or complexity, but once you start needing to do this a few times the extra verbosity starts to add up. All that typing makes it harder to build momentum and get into flow while coding. In any example more complicated than this you'd often have to explicitly handle generic declarations or type casting (which means even more typing). In Ruby you can pretty much think of how it's going to work, and just run with it (once you grok how <code><a href="http://www.ruby-doc.org/core/classes/Enumerable.html#M003159">map</a></code> and <code><a href="http://www.ruby-doc.org/core/classes/Enumerable.html#M003160">inject</a></code> work).</p>
<p>There is a lot of talk about adding <a href="http://wiki.java.net/bin/view/JDK/ClosuresSyntaxInJava7">closures</a> to Java 7. That's something I'd love as it would make a lot of the techniques used in Ruby possible in Java. I just hope that it's done better than when <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html">generics</a> were introduced in Java 5. (We've just upgraded one of our products from 1.4 to 5, and I've been exposed to generics in action for the first time. Not so impressed so far... but that's another post.)</p>
<p><em><strong>UPDATE</strong></em></p>
<p>As pointed out by robert in the comments, there is an even simpler approach:</p>
<pre><code>get_foos.map{|f| f.start_date}.min</code></pre>
<p>Cheers <img src='http://www.rawblock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/04/13/list-manipulation-in-java-and-ruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/04/13/list-manipulation-in-java-and-ruby/</feedburner:origLink></item>
		<item>
		<title>Parallels Desktop Build 3188 – external hard drive issue seems fixed</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/y6naaE6bxb8/</link>
		<comments>http://www.rawblock.com/2007/03/21/parallels-desktop-build-3188-external-hard-drive-issue-seems-fixed/#comments</comments>
		<pubDate>Wed, 21 Mar 2007 02:53:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[mac os x]]></category>
		<category><![CDATA[boot camp]]></category>
		<category><![CDATA[parallels]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/03/21/parallels-desktop-build-3188-external-hard-drive-issue-seems-fixed/</guid>
		<description><![CDATA[A while ago I posted Parallels RC2, Boot Camp, Windows XP, OS X &#8211; One Happy Family On My Mac, which was about installing a single Windows XP image and being able to run it either through bootcamp or parallels.
One of the issues I came across was that Parallels wouldn&#8217;t start up if you had [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I posted <a href="http://rawblock.blogspot.com/2007/02/parallels-rc2-boot-camp-windows-xp-os-x.html">Parallels RC2, Boot Camp, Windows XP, OS X &#8211; One Happy Family On My Mac</a>, which was about installing a single Windows XP image and being able to run it either through bootcamp or parallels.</p>
<p>One of the issues I came across was that Parallels wouldn&#8217;t start up if you had an NTFS/FAT32 (aka Windows formatted) external drive attached &#8211; such as an ipod or a USB keyring drive. If a drive was plugged in, Parallels would refuse to start up and would display the cryptic message <i>&quot;More than one Windows partitions are found. This is not a standard Boot Camp configuration&quot;</i>. Judging by the number of Google search hits I get searching for that term, it seems a lot of people have had the same issue (the work around was just to unplug the external drive before starting Parallels).</p>
<p>The good news is that <a href="http://www.parallels.com/en/download/desktop/">Parallels Desktop</a> Build 3188 has been released, and this issue seems to be fixed. There is probably a whole bunch of other cool stuff in there as well, but I couldn&#8217;t see any obvious release notes, and I don&#8217;t have any worries apart from that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/03/21/parallels-desktop-build-3188-external-hard-drive-issue-seems-fixed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/03/21/parallels-desktop-build-3188-external-hard-drive-issue-seems-fixed/</feedburner:origLink></item>
		<item>
		<title>JRuby can save Swing – Follow up</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/eZR_iShXmJg/</link>
		<comments>http://www.rawblock.com/2007/03/09/jruby-can-save-swing-follow-up/#comments</comments>
		<pubDate>Thu, 08 Mar 2007 13:44:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/03/09/jruby-can-save-swing-follow-up/</guid>
		<description><![CDATA[My recent post &#34;JRuby Can Save Swing&#34; generated a bit of discussion around the blogosphere. A few blogs replied, and a lot of good points were made. I was a little disappointed that most of the rebuttal I got was in regard to Joshua Marinachi&#8217;s original 2003 post and his list of why Swing sucks, [...]]]></description>
			<content:encoded><![CDATA[<p>My recent post <a href="http://rawblock.blogspot.com/2007/02/jruby-can-save-swing.html">&quot;JRuby Can Save Swing&quot;</a> generated a bit of discussion around the blogosphere. A few blogs replied, and a lot of good points were made. I was a little disappointed that most of the rebuttal I got was in regard to Joshua Marinachi&#8217;s original 2003 post and his list of why Swing sucks, and not to the points I raised about the potential that a new framework based in JRuby could provide. I guess that is blogging-101 &#8211; put your payload at the front and minimize the lead up. <img src='http://www.rawblock.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>From the <a href="http://rawblock.blogspot.com/2007/02/jruby-can-save-swing.html">original post</a>, my dream list for a higher level GUI framework for Swing are</p>
<ul>
<li>Structured application layout</li>
<li>Proper decoupling of model from view</li>
<li>Automatic binding of model to view without glue code</li>
<li>View logic code separated from layout markup</li>
<li>Application lifecycle support</li>
<li>Minimize the amount of code</li>
<li>Minimize complexity</li>
<li>Testable</li>
<li>Make the <em>Right</em> way of doing things the path of least resistance</li>
</ul>
<h2><a href="http://pinderkent.blogsavy.com/archives/53">JRuby cannot save Swing</a></h2>
<p><a href="http://pinderkent.blogsavy.com/archives/53">pinderkent</a> replied with the idea that Swing is beyond saving, and nothing JRuby or anything else can do can save it. I don&#8217;t think Swing is at that point. I think in the last few years Swing has turned a corner an is improving with each release (5 was great, 6 is good as well). My initial article title was intentionally a little inflammatory. I don&#8217;t actually think Swing &#8220;needs&#8221; saving. All the same I think there are some areas that can be helped out.</p>
<h3>Swing is slow?</h3>
<p>Pinderkent then trots out the tired &#8220;Swing is slow argument&#8221;. This may have been the case&#8230; <em>on a Pentium 2 back in 1998</em>. This has not been true for a long time. Swing itself is more efficient, and CPUs are faster. It just isn&#8217;t an issue anymore. The pinderkent says they haven&#8217;t actually done any profiling. Nuff said.</p>
<p><a href="http://www.shemnon.com/speling/2007/02/groovy-can-save-swing.html">Danno Ferrin</a> responded to pinderkent and makes the point in another follow up:</p>
<blockquote><p>&quot;The stock answer to this is always true: &quot;bad programmers abuse the Event Dispatch Thread.&quot; Seriously, whenever anyone wants to start programming Swing someone else needs to get a stick and beat them until they write in blood the oath &quot;I will not do data processing in the Event Dispatch Thread.&quot; &quot;</p></blockquote>
<p>Which is exactly my experience. It is possible to create snappy, responsive Swing apps &#8211; but the moment anyone does some heavy processing, or a database call, or file operation from a listener &#8211; you&#8217;re wading through mud. Maybe that&#8217;s an extra point for my framework wish list: <em>&quot;Makes using worker threads instead of the EDT the path of least resistance for heavy operations.&quot;</em></p>
<h2><a href="http://www.shemnon.com/speling/2007/02/groovy-can-save-swing.html">Groovy Can Save Swing</a></h2>
<p>Danno Ferrin&#8217;s main point is that Groovy would be a more suitable layer for Swing than JRuby.</p>
<p>The argument is that Groovy is closer to Java and it would mean developers wouldn&#8217;t have to learn all of Ruby&#8217;s weird syntax and <em>&quot;ugly PERLisms&quot;</em>. Maybe. I have to admit I haven&#8217;t had any exposure to Groovy. Ruby isn&#8217;t difficult to pick up though, and the syntax arguments are really just a matter of opinion. What I believe makes Ruby ideal as a DSL/wrapper API layer is the level of meta-programming Ruby affords to achieve things that are impossible in Java. I&#8217;m talking about things like stupidly easy model-view binding. In ruby you can do something like</p>
<pre><span class="ident">model</span> <span class="punct">=</span> <span class="constant">Person</span><span class="punct">.</span><span class="ident">new</span><span class="punct">('</span><span class="string">Julian Doherty</span><span class="punct">',</span> <span class="punct">'</span><span class="string">julian@example.com</span><span class="punct">')</span>

<span class="ident">name_label</span> <span class="punct">=</span> <span class="constant">JLabel</span><span class="punct">.</span><span class="ident">new</span>
<span class="ident">name_label</span><span class="punct">.</span><span class="ident">bind_to</span> <span class="ident">model</span><span class="punct">,</span> <span class="symbol">:name</span>

<span class="ident">email_field</span> <span class="punct">=</span> <span class="constant">JTextField</span><span class="punct">.</span><span class="ident">new</span>
<span class="ident">email_field</span><span class="punct">.</span><span class="ident">bind_to</span> <span class="ident">model</span><span class="punct">,</span> <span class="symbol">:email</span></pre>
<p>And have the text label and field bound to the model so changes on either side are automatically replicated to each other &#8211; all without a single line of event listener glue code. I&#8217;ve got some sample code showing this working, and will write something about it soonish. I&#8217;ve already written about <a href="http://rawblock.blogspot.com/2007/02/transparent-property-change-listeners.html">Transparent Property Change Listeners</a> for Ruby bean-type classes, which shows part of the solution.</p>
<p>I don&#8217;t know if Groovy gives you that or not. If it does, great. If not, then that&#8217;s a reason to consider JRuby over Groovy.</p>
<p>Homework for me: grok Groovy so I&#8217;m better informed on this <img src='http://www.rawblock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2><a href="http://blogs.dzone.com/daniel/2007/02/21/does-swing-need-saving/">Does Swing Need Saving?</a></h2>
<p><a href="http://blogs.dzone.com/daniel/2007/02/21/does-swing-need-saving/">Daniel Spiewak</a> posted a rebuttal of Joshua Marinachi&#8217;s original &#8220;why Swing Sucks posts&#8221; that I reposted.</p>
<p>It&#8217;s a good post and A lot of his points were on the money (which I won&#8217;t discuss much except to say I agree): his discussion of layout managers (GroupLayout etc); native feature integration; and Swing&#8217;s bad perception from a troubled past.</p>
<p>A few didn&#8217;t quite stack up with me though.</p>
<h3>Ruby is the same amount of work as Java?</h3>
<p>In arguing that Swing GUIs are just as easy to construct in Java as JRuby, Daniel Spiewak provides an overly simple UI consisting of a label and three buttons &#8211; implemented both in JRuby and then Java. The two versions are almost identical, and there is no difference in code complexity or length (how surprising!). Problem is, the examples didn&#8217;t have anything done in the real world: no advanced layout, no event handling, no model/view interaction, no validation. It&#8217;s a weak straw man argument that really doesn&#8217;t tell us anything.</p>
<p>A more interesting example would be to compare a straight Java implementation of a reasonably complex application (including any cool 3rd party libraries) and a JRuby framework based implementation (using all the Ruby black magic possible). My guess is that the JRuby version would come out ahead.</p>
<h3>Swing isn&#8217;t slow to build?</h3>
<p>Daniel Spiewak then says that a reasonably complex UI could be coded in a few hours by a himself, and half that by Romain Guy.</p>
<p>So what?</p>
<p>It&#8217;s a pretty arbitrary metric which still doesn&#8217;t say anything. What would be interesting again is the difference between Java and a JRuby framework implementation. Maybe JRuby only takes one hour or maybe it takes five? I don&#8217;t know. My guess though is that again it would take far less code, would be easier to test, and would be finished quicker in JRuby by the same developer.</p>
<h3>Separate markup layout of view is bad?</h3>
<p>Daniel Spiewak also questioned whether using XML to store the GUI config is a good idea. I AGREE! XML is horrible and is abused in Java land (I actually said to use YAML in the original post as it is a bit more human friendly). I wasn&#8217;t advocating to use XML/YAML to create the whole GUI &#8211; just as a mark up to separate the layout from the component instantiation and move layout  out of the view code.</p>
<p>My opinion is that code is good for expressing view logic, but not visual layout. That would be better served by some separate markup.</p>
<h3>Swing apps are hard to maintain because of bad developers?</h3>
<p>One of the main beefs I&#8217;ve got with Java/Swing and one that Daniel Spiewak&#8217;s touched on, is the difficulty maintainability of Swing apps. He says that main problem with bad Swing apps is that bad developers don&#8217;t do a good job &#8211; which I totally agree with! It is definitely possible to structure a good Swing app and develop it in a nice clean way, but to do things the right way is a lot of work. The path of least resistance is to take short cuts and just get it done (especially when deadlines are pressing). Yes, Swing has a nice MVC architecture, and best practice says you should build apps that way &#8211; but it&#8217;s just too much work to use properly in the real world.</p>
<p>I liked a quote from one of Danno Ferrin&#8217;s other related blog posts &#8220;<a href="http://shemnon.com/speling/2004/05/groovy-verbosity-and-swing.html">Groovy, Verbosity, and Swing</a>:</p>
<blockquote><p>&#8220;I think that the greatest problem with the swing APIs are not that they are too complex or too poorly explained. The biggest problem I see is that to do simple things the correct way, it can get quite verbose. Kind of like reliable file I/O, but you get far fewer urgent-1 bug in the GUI than in core I/O routines. Perhaps the best thing isn&#8217;t to change the Swing APIs, but to add more syntactic sugar.&#8221;</p></blockquote>
<p>Which is exactly what I was trying to get at with my original post. Swing is a great low level API, and provides the developer with a lot of power to do things. Problem is, the path of least resistance is to produce ugly crud that barely works. Where as something like Rails provides a path of least resistance that results in elegant and well structured code.</p>
<p>Every API acts like a multiplier for developer productivity, and has a response curve of varying slope. Some frameworks make good developers amazing while making mediocre developers passable (Rails springs to mind).</p>
<p>Swing seems to do the opposite though. It makes amazing developer&#8217;s work merely good, and mediocre developer&#8217;s work unacceptable.</p>
<h2><a href="http://rawblock.blogspot.com/2007/02/jruby-can-save-swing.html">Comments on the original post</a></h2>
<h3>Why not Eclipse/NetBeans RCP? What about JSR-296 application framework?</h3>
<blockquote><p>Steve said&#8230;<br/><br />
I agree with the sentiment, but not to craft yet another solution.<br/><br />
Why don&#8217;t we just call this Eclipse or NetBeans RCP?<br/><br />
Really these things have been done, what we lack is people understanding and using them.<br/><br />
There is a JSR on the table for a Swing framework too &#8211; JSR-296, this will help quite a bit.</p></blockquote>
<p>Good points. I have to plead ignorance on exactly what the Eclipse and NetBeans RCPs provide (more homework for me!). However one of the benefits of JRuby is all the meta-programming that is either impossible or overly verbose in Java. They also both smack of the whole Big Java philosophy (XML configuration and all!) which a lot of developers are getting disillusioned with. As for JSR-296 &#8211; it&#8217;s definitely a good thing, and any framework should build on top of it, not replace it.</p>
<h3>Groovy SwingBuilder?</h3>
<blockquote><p>Anonymous said&#8230;<br/><br />
Groovy already has a SwingBuilder, which I suppose you could duplicate in Ruby&#8230; but most of these are done arleady.</p></blockquote>
<p>Good point, but layout is just a small piece of the puzzle. My understanding is that SwingBuilder just helps you with the layout and still leaves everything else (binding, application structure etc) to you to implement</p>
<h2>So&#8230; now what?</h2>
<p>I&#8217;m keen to experiment with some of my original ideas from <a href="http://rawblock.blogspot.com/2007/02/jruby-can-save-swing.html">JRuby Can Save Swing</a>. I&#8217;m trying to pick a small/medium, low-risk project to roll a basic JRuby Swing framework for and see how it goes. So far I&#8217;ve been doing a few little demos that show off some of the basic concepts (will post some examples soon!). It&#8217;s definitely promising, but it&#8217;s hard to tell from anything that small.</p>
<p>Stay tuned <img src='http://www.rawblock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/03/09/jruby-can-save-swing-follow-up/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/03/09/jruby-can-save-swing-follow-up/</feedburner:origLink></item>
		<item>
		<title>JRuby 0.9.8 Released</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/nRe6tu1G0hk/</link>
		<comments>http://www.rawblock.com/2007/03/07/jruby-098-released/#comments</comments>
		<pubDate>Tue, 06 Mar 2007 22:43:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[jruby]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/03/07/jruby-098-released/</guid>
		<description><![CDATA[JRuby 0.9.8 is out. I&#8217;ll have to download and give it a blast in the next day or two. I&#8217;ve got some more JRuby code snippets to post, so will be interesting to see how it runs.
Looks like it&#8217;s got some nice performance and Java integration improvements. AND 98% of Rails unit tests pass. This [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://docs.codehaus.org/display/JRUBY/2007/03/05/JRuby+0.9.8+Released">JRuby 0.9.8 is out</a>. I&#8217;ll have to download and give it a blast in the next day or two. I&#8217;ve got some more JRuby code snippets to post, so will be interesting to see how it runs.</p>
<p>Looks like it&#8217;s got some nice performance and Java integration improvements. <b>AND</b> 98% of Rails unit tests pass. This is the release they consider to be stable enough for Rails developers to start playing with seriously to help the JRuby team get over the line.</p>
<p>Release is available at <a href="http://dist.codehaus.org/jruby/">http://dist.codehaus.org/jruby/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/03/07/jruby-098-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/03/07/jruby-098-released/</feedburner:origLink></item>
		<item>
		<title>Martin Fowler, live in Melbourne</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/6xiNuVe9ztA/</link>
		<comments>http://www.rawblock.com/2007/02/26/martin-fowler-live-in-melbourne/#comments</comments>
		<pubDate>Mon, 26 Feb 2007 04:22:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/02/26/martin-fowler-live-in-melbourne/</guid>
		<description><![CDATA[Last Friday I attended a packed breakfast seminar to hear Martin Fowler speak. The event was put on by Enterprise Java Australia. After filling the original venue, it was moved to Melbourne Town Hall. All up there must have been around 300 people who dragged themselves out of bed early to eat bad food, drink [...]]]></description>
			<content:encoded><![CDATA[<p>Last Friday I attended a packed breakfast seminar to hear Martin Fowler speak. The event was put on by <a href="http://www.enterprisejava.org.au">Enterprise Java Australia</a>. After filling the original venue, it was moved to Melbourne Town Hall. All up there must have been around 300 people who dragged themselves out of bed early to eat bad food, drink bad coffee, and sit in uncomfortable chairs for 2 hours to hear Martin speak.</p>
<p><em>Disclaimer &#8211; the following is all based on my early morning, caffeine-deprived memory of the talk. Any resemblance to actual events or persons alive or dead is purely co-incidental</em></p>
<p>The event was titled <em>&#8220;Software Design in the 21st Century&#8221;</em>. Martin started by explaining that this was an intentionally vague title that would let him talk on whatever he felt like on the day.</p>
<h2>Java&#8217;s Progress for the last 10 years</h2>
<p>The talk opened with Martin talking about how far Java has brought us over the last 10 years (in spite of any short comings, which were discussed next&#8230;). Both in terms of the language and platform, and in terms of the greater community.</p>
<ul>
<li>Don&#8217;t have to worry about memory management and related bugs anymore</li>
<li>Dynamic open source community, especially when compared to .NET land</li>
<li>Test driven development has been embraced</li>
<li>Solid platform to develop on &#8211; as in the actual Java VM</li>
</ul>
<h2>Java&#8217;s Weaknesses</h2>
<p>Martin then did a round up of the audience to get the perception of pain points in Java, (and added a few of his own).</p>
<ul>
<li>J2EE in general, EJB in particular</li>
<li>J2ME. Tired of <em>&quot;Starting Java&#8230;&quot;</em> on mobile phones for little added functionality</li>
<li>Unnecessary XML overload &#8211; configuration files, data transfer</li>
<li>Date/Calendar API</li>
<li>Lack of any currency support considering how many financial applications are written in Java</li>
<li>Lack of advanced features like closures</li>
<li>Applets</li>
<li>J++ fiasco and resulting souring of Sun/Microsoft relations hurting Java in the browser.</li>
<li>Swing</li>
<li>Multi-threading. Or rather the fact that <em>&quot;Only 5 people in the world actually understand concurrency&quot;</em> and <em>&quot;A license should be required before developers are allowed to create new threads&quot;</em>
</ul>
<h2>Java&#8217;s near future</h2>
<p>Martin said he didn&#8217;t claim to be a futurist, and preferred just to talk about recent and current trends and only look at the near term. This was the bulk of the talk, and was the most interesting section.</p>
<ul>
<li>Java as a language will decrease in importance, while the Java VM as a platform will increase as it becomes more common for other languages to run on it (eg JRuby). Applications will only write the core code in Java, and use more productive languages for the implementation layers where most development time is spent.</li>
<li>Concurrency will become more of an issue on the desktop as multi-core systems become more common. This will be less of an issue for backend server development as developers are already used to developing logically segmented, shared-nothing systems to increase thoughput anyway. Languages like Erlang running on the VM may help with this</li>
<li>Java frameworks with the Rails philosophy of narrowly defined scope and high productivity will emerge as developers tire of the complexity and overhead of general purpose, complex frameworks such as Spring and J2EE</li>
</ul>
<p>All up an interesting talk. Nothing ground breaking, but most of it fitted with my thinking on Java&#8217;s direction &#8211; especially the discussion of Rails type frameworks, which is exactly what I was getting at in my last post on <a href="http://rawblock.blogspot.com/2007/02/jruby-can-save-swing.html">JRuby Can Save Swing</a>.</p>
<p>I expected Martin to be American for some reason, he&#8217;s actually English.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/02/26/martin-fowler-live-in-melbourne/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/02/26/martin-fowler-live-in-melbourne/</feedburner:origLink></item>
		<item>
		<title>JRuby can save Swing</title>
		<link>http://feedproxy.google.com/~r/RawBlock/~3/aJsKtVKLmeY/</link>
		<comments>http://www.rawblock.com/2007/02/15/jruby-can-save-swing/#comments</comments>
		<pubDate>Thu, 15 Feb 2007 06:34:00 +0000</pubDate>
		<dc:creator>madlep</dc:creator>
				<category><![CDATA[jruby]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://www.rawblock.com/2007/02/15/jruby-can-save-swing/</guid>
		<description><![CDATA[Swing is hard. Needlessly so. With the advent of scripting support on the JVM, why not wrap a light and elegant Ruby layer around Swing? Why keep coding Swing at it&#8217;s lowest API level using a heavy-weight language like Java?
I&#8217;ve always maintained Swing is a nice framework. It&#8217;s just that it&#8217;s too low level and [...]]]></description>
			<content:encoded><![CDATA[<p>Swing is hard. Needlessly so. With the advent of scripting support on the JVM, why not wrap a light and elegant Ruby layer around Swing? Why keep coding Swing at it&#8217;s lowest API level using a heavy-weight language like Java?</p>
<p>I&#8217;ve always maintained Swing is a nice framework. It&#8217;s just that it&#8217;s too low level and Java is a lousy language for programming it in. It&#8217;s already possible to code Swing in Ruby by using <a href="http://jruby.codehaus.org/">JRuby</a>. You get some of the Ruby niceness (such as easier method calls, some dynamic typing, and blocks), but you still end up fighting against listeners, layout managers, look-and-feels, event-threads etc before long. Suns trademark API over-engineering casts a long shadow, even into Ruby land.</p>
<p>The Swing API itself is very flexible and powerful, but at a low level. It&#8217;s powerful in the same way that a coil of wire and a bunch of tools is a flexible and powerful way to configure the electricals in your house. It&#8217;s just that sometimes you only want to plug a few things in and flick a switch to watch a DVD.</p>
<p>So what specifically are the problems?</p>
<h2>Swing&#8217;s issues</h2>
<p>Joshua Marinacci&#8217;s blog post <a href="http://weblogs.java.net/blog/joshy/archive/2003/11/swing_has_faile.html">Swing has failed. What can we do?</a> from 2003 covers this issue nicely. Joshua points out these flaws which I&#8217;d agree with 100%. Nothing much has changed in the years since, except maybe that Swing looks somewhat better now and resembles native apps much more closely.</p>
<blockquote>
<ul>
<li><em>&quot;Swing apps are slow to build.&quot;</em></li>
<li><em>&quot;Swing layout managers suck.&quot;</em></li>
<li><em>&quot;Swing apps are hard to maintain.&quot;</em></li>
<li><em>&quot;Swing is too powerful.&quot;</em></li>
<li><em>&quot;No native features.&quot;</em></li>
<li><em>&quot;Swing apps have a bad history.&quot;</em></li>
</ul>
</blockquote>
<h2>What needs to be done?</h2>
<p>Joshua&#8217;s ideas on what needs to be done to fix Swing are interesting.<br/><br />
<em>(there are more points he makes, but I&#8217;m just including the relevant ones)</em></p>
<blockquote>
<ul>
<li><strong><em>&quot;A structured way of building Swing apps.</strong> Something like Struts where each concern (aspect?) has it&#8217;s own special place to be stored and manipulated. How do you organize your layout, workflow, validation, intz&#8217;ed text, and hooks to the BL? Should you subclass to make frames or use factory code? We need a set of best practices and then a framework to implement them.&quot;</em></li>
<li><strong><em>&quot;A standard cross-tool representation of a GUI that is not Java code.</strong> Something that can be moved in and out of different IDEs and build tools. Probably an XML representation or maybe serialized Swing objects.&quot;</em></li>
<li><strong><em>&quot;An intermediate API.</strong> Maybe we need a simpler API on top of Swing? A new set of wrapper components which hide a lot of the complexity. Hell, half of the work could be done by just conditionally hiding 3/4 of the API from the Javadocs.&quot;</em></li>
</ul>
</blockquote>
<p>I particularly like the idea of a structured way of building Swing apps. At the moment it&#8217;s a free-for-all. Some developers have come up with nice individual patterns for maintaining order, others implement spaghetti, most start out well, but degrade into entropy. This even applies individual screens in some apps! &#8211; I&#8217;ve seen 6000 line long, single-class monstrosities for a single window! One of Rails main strengths is it&#8217;s &#8220;Convention over Configuration&#8221; approach for separating out and structuring an application. There is no reason why this can&#8217;t apply to a Rich Client. </p>
<h2>My Ideal Swing/Ruby framework features</h2>
<p>So&#8230; what would this look like?</p>
<ul>
<li><strong>Structured application layout.</strong> Works for Rails. Nuff said.</li>
<li><strong>Proper decoupling of model from view.</strong> Probably using Martin Fowler&#8217;s <a href="http://www.martinfowler.com/eaaDev/PresentationModel.html">Presentation Model</a> pattern, or similar.</li>
<li><strong>Automatic binding of model to view without glue code.</strong> (this makes the last point much easier to implement.) Ruby is <a href="http://rawblock.blogspot.com/2007/02/transparent-property-change-listeners.html">perfect</a> for this. You should be able to write something like <code>name_field.bind_to song, :title</code> and be done with it. Ruby should do it&#8217;s thing and set up listeners automatically &#8211; Even if the model class wasn&#8217;t designed with listeners when it was coded.</li>
<li><strong>View logic code separated from layout markup.</strong> View components and interaction (enable this button with this tooltip etc) should be coded in Ruby. Layout should be stored in a YAML file or similar (please no more XML&#8230;). Layout via coding is far too hard for most people to use effectively. Minimize the pain and let the framework take care of the grunt work. We definitely DO NOT want anymore GridBag boilerplate code&#8230;</li>
<li><strong>Application lifecycle support.</strong> Related to having a structured application layout. Provide session support, long lived models etc, and handle startup/shutdown.</li>
<li><strong>Minimize the amount of code.</strong> You already get this for free by using Ruby, but removing the fluff from Swing is a must. Too much code to achieve too little. It should be possible to scaffold something basic like Rails does, then tweak it if it needs to do more. <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a> is part of this, but that just seems like basic common sense for any kind of development in any language.</li>
<li><strong>Minimize complexity.</strong> Related to minimizing code. Making it easy to use a proper pattern like Presentation Model and removing a lot of the spaghetti listener code by using bindings will help a lot.</li>
<li><strong>Testable.</strong> It&#8217;s really hard to write automated tests for GUIs. Libraries like <a href="http://jfcunit.sourceforge.net/">JFC Unit</a> make it easier, but it&#8217;s still pretty heavy going. I don&#8217;t know the answer to this one. GUIs always need at least some manual intervention to check the visual layout (a computer can&#8217;t tell if it doesn&#8217;t &#8220;flow&#8221; right). Maybe the framework could help by making it easy to substitue mock objects for testing the presentation model code.</li>
<li><strong>Make the <em>Right</em> way of doing things the path of least resistance.</strong>. This one is important, and I think it is one of Swing&#8217;s big weaknesses. This is related to having a good structure, but it goes from there all the way down to how easy the APIs are to use. Rails makes it easy to create good designs and stick to them. Swing makes it hard &#8211; as evidenced by the plague of badly thought out <a href="http://www.martinfowler.com/eaaDev/AutonomousView.html">Autonomous Views</a> espoused by Sun&#8217;s Swing tutorials</li>
</ul>
<p>Even a few of these points would make Swing much more productive and fun. I&#8217;ve made a few posts recently that are leading up to this. Over the next few posts I&#8217;ll start to experiment with a few more of the pieces to see how it all hangs together. Who knows, maybe I&#8217;ll actually get something usable at the end <img src='http://www.rawblock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rawblock.com/2007/02/15/jruby-can-save-swing/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://www.rawblock.com/2007/02/15/jruby-can-save-swing/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.903 seconds -->
