<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Yellow™ Lab Blog &#187; Dev</title>
	<atom:link href="http://yellowlab.com.au/blog/category/dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://yellowlab.com.au/blog</link>
	<description></description>
	<lastBuildDate>Tue, 15 Sep 2009 00:25:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Functional Programming in Ruby</title>
		<link>http://yellowlab.com.au/blog/2009/09/15/functional-programming-in-ruby/</link>
		<comments>http://yellowlab.com.au/blog/2009/09/15/functional-programming-in-ruby/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 00:25:50 +0000</pubDate>
		<dc:creator>jeremy.mawson</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[proc]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://yellowlab.com.au/blog/?p=134</guid>
		<description><![CDATA[After many years of software development in the imperative style under my belt, I have in recent years developed a keen interest in functional programming as an alternative paradigm. First via the confusion of Functional Java, then Scala and now some forays into Haskell. Having experienced first hand the improvement in legibility and comprehension the [...]]]></description>
			<content:encoded><![CDATA[<div><span style="background-color: #ffffff;">After many years of software development in the imperative style under my belt, I have in recent years developed a keen interest in functional programming as an alternative paradigm. First via the confusion of <a href="http://functionaljava.org/" target="_blank">Functional Java</a>, then <a href="http://www.scala-lang.org/" target="_blank">Scala</a> and now some forays into <a href="http://www.haskell.org/" target="_blank">Haskell</a>. Having experienced first hand the improvement in legibility and comprehension the functional style can bring, I naturally wondered how FP could be applied to our Ruby work on Yellow Lab.</span></div>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<div><span style="background-color: #ffffff;">Ruby&#8217;s strength is in its loose typing and imperative style. I like to think of it as the new and improved Perl. A rapid prototyping and scripting language for the modern developer and technical SME alike. Whilst it lacks the rigour of a purely functional language (as all imperative languages do) it does have functional capabilities.</span></div>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<div><span style="background-color: #ffffff;">The essence of the functional style is the application of functions instead of variable mutation. It follows that functional languages must support function expressions for there to be any prospect of applying the consistent behaviour over an enumeration. Ruby supports three types of function expressions:</span></div>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<h3><span style="background-color: #ffffff;">Blocks</span></h3>
<div><span style="background-color: #ffffff;">Anyone who has used <em>collect</em> or<em> inject</em> on a map knows what a block is. They are anonymous function expressions which are applied in a method when the <em>yield</em> keyword is encountered.</span></div>
<p><span style="background-color: #ffffff;"><br />
<code>fruits.each {|fruit| eat fruit } # delicious!</code></span></p>
<div><span style="background-color: #ffffff;">In this example the brackets denote the block, the pipes delimit the input parameter list and the remainder is the block body to be executed. Blocks cannot be assigned to a variable so their reuse is limited. One of the Yellow Lab developers has written <a href="http://www.skorks.com/2009/09/using-ruby-blocks-and-rolling-your-own-iterators/" target="_blank">more about Ruby blocks</a> on his blog.</span></div>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<h3><span style="background-color: #ffffff;">Procs</span></h3>
<div><span style="background-color: #ffffff;">Procs are references to blocks. The are constructed explicitly with <strong>Proc</strong>.<em>new</em> or implicitly when ampersand prefixed method parameters receive anonymous blocks. They are invoked with a call to <em>call</em>.</span></div>
<p><span style="background-color: #ffffff;"><br />
<code>def do_something_with_fruit(fruit, &amp;fruit_related_activity)<br />
</code> <code>fruit_related_activity.call(fruit)<br />
end</code></span></p>
<p><code> </code></p>
<p><code>do_something_with_fruit(banana) {|fruit| eat fruit} # =&gt; the banana is eaten!</code></p>
<div><span style="background-color: #ffffff;">On first sight they seem fit for purpose. But they have some strong limitations.</span></div>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<div><span style="background-color: #ffffff;">1. Flow control statements, such as return and break, will affect the flow in the invoking method, not just in the proc.</span></div>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<div><span style="background-color: #ffffff;">2. They can happily be invoked with an incorrect numbers of parameters. Some may think this is a benefit, but I believe it is an open invitation for bugs.</span></div>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<h3>Lambdas</h3>
<div><span style="background-color: #ffffff;">Lambdas are akin to Procs, but correct the two limitations listed above. That is, flow control statements take effect within the scope of the lambda only and the number of parameters must be correct. They are the best fit for reusable references to function expressions.</span></div>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<p><code>blend = lambda {|fruit| blender.blend(fruit)}<br />
freeze = lambda {|fruit| freezer &lt;&lt; fruit}</code></p>
<p><code> </code></p>
<p><code>basketOfFruit.each &amp;blend # => a smoothie<br />
basketOfFruit.each &amp;freeze # => now icecream<br />
canOfWorms.each &amp;freeze # => um ...</code></p>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<h3>Utility</h3>
<div><span style="background-color: #ffffff;">Our application uses the Rails framework and has many of the artefacts you&#8217;d expect to see in a Rails application: controllers, models, views, some rake and capistrano tasks. Much of it is elegant and simple imperative style code. Blocks are used frequently within Labs to simplify the application of behaviour across an enumerable &#8211; especially in rake and capistrano tasks that prepare our data for runtime. There seems little necessity in this kind of application for the inclusion of lambdas. (I expect this would be quite a different situation if we were building a framework instead).</div>
<div><span style="background-color: #ffffff;"><br />
</span></div>
<div><span style="background-color: #ffffff;">Ruby is far from a functional language. No one could possibly argue otherwise. The lack of typing and immutability ensure that it is too tempting to revert to a less rigid style. But, as this post has shown, there are some functional aspects of the language and it is certainly worth keeping these in the toolbox.</div>
]]></content:encoded>
			<wfw:commentRss>http://yellowlab.com.au/blog/2009/09/15/functional-programming-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What A Modern Rails Application Looks Like In Production</title>
		<link>http://yellowlab.com.au/blog/2009/08/19/what-a-modern-rails-application-looks-like-in-production/</link>
		<comments>http://yellowlab.com.au/blog/2009/08/19/what-a-modern-rails-application-looks-like-in-production/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 23:19:36 +0000</pubDate>
		<dc:creator>mark.mansour</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rails application]]></category>
		<category><![CDATA[rails in production]]></category>

		<guid isPermaLink="false">http://yellowlab.com.au/blog/?p=112</guid>
		<description><![CDATA[Yellow Lab is a Rails application. When we first started up we chose Ruby on Rails (Sensis generally uses Java) to see how using a dynamic platform would change our delivery patterns. Now that we&#8217;ve been running for a while, we wanted to share what our high level architecture looks like and the various components [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Yellow Lab" href="http://yellowlab.com.au/" target="_blank">Yellow Lab</a> is a Rails application. When we first started up we chose Ruby on Rails (Sensis generally uses Java) to see how using a dynamic platform would change our delivery patterns. Now that we&#8217;ve been running for a while, we wanted to share what our high level architecture looks like and the various components that make it up.  We hope it is interesting to see what a live, enterprise, Rails application looks like when deployed, and if you have some ideas to share with us, we are always happy to hear them.</p>
<p>We find that simple systems are easier to build and understand, which make them easier to change, so with that in mind we are always striving to make things as simple as they can be, without being simplistic.  Our setup is a fairly standard in modern web applications with a web server that receives client&#8217;s requests then passes those requests back to either the file-system (if static assets are requested) or to the application server which in turn pulls data from a database, a search engine or the file system.</p>
<p><img class="aligncenter size-full wp-image-115" title="Yellow Lab System Overview" src="http://yellowlab.com.au/blog/wp-content/uploads/2009/08/yellow-lab-system-1.png" alt="Yellow Lab System Overview" width="523" height="289" /></p>
<h2>The Bits And Pieces</h2>
<ul>
<li><strong>The Web Server (<a href="http://nginx.net/">Nginx</a>)</strong> &#8211;  (pronounced as &#8220;engine X&#8221;)  is a light weight, high performance web server/reverse proxy. We chose Nginx for it&#8217;s light footprint and easy configuration.  It has served us very well and hasn&#8217;t got in the way of anything we&#8217;ve needed to do. If you are looking for a web server and you&#8217;d like to try something beside Apache&#8217;s httpd then Nginx is a great alternative.</li>
<li><strong>The App Server (A Bunch Of <a href="http://mongrel.rubyforge.org/">Mongrels</a>)</strong> &#8211; <a href="http://mongrel.rubyforge.org/">Mongrel</a> is our application server.  If you are from a Java world you can think of it as Apache&#8217;s Tomcat for Ruby.  We use Mongrel to host our <a href="http://rubyonrails.org/">Rails application</a> and it does a fine job.  Mongrel was the default deployment option for Rails until the original author, Zed Shaw, decided he didn&#8217;t want to support it any more and a competing technology, <a href="http://www.modrails.com/">Phusion&#8217;s Passenger</a>, came along.  Passenger is the &#8220;<a href="http://rubyonrails.org/deploy">preferred deployment setup for Rails</a>&#8221; &#8211; it is under active development but doesn&#8217;t really offer us enough to switch from Mongrel.  We&#8217;ll probably swap over to it, but we&#8217;re in no rush.</li>
<li><strong>The Meat And Bones (Ruby On Rails)</strong> &#8211; We are using the <a href="http://rubyonrails.org/">Ruby on Rails framework</a> to build the business logic for the site.  So, has it changed our delivery patterns? Yes, it&#8217;s made us faster. Some of it is probably due to the fact that we are a lab/test bed group, but RoR has certainly been a major contributing factor to allow us to get features into &#8216;production&#8217; more quickly (there are some stories and learnings here, but we can explore that some other time).  <a href="http://www.ruby-lang.org/en/">Ruby</a> is a fantastic language to build web applications with and Rails leverages Ruby&#8217;s language features pretty well.</li>
<li><strong>The Database (PostgreSQL)</strong> &#8211; <a href="http://www.postgresql.org/">PostgreSql</a> is a mature, open source database with clear licensing.  If you haven&#8217;t looked at it, then you should.  We use PostgreSql to store business listing data and user generated content (we are sooo web 2.0).  Fairly straight forwards stuff.  We also use a PostgreSql GIS extension, <a href="http://postgis.refractions.net/">PostGIS</a>, to generate reference data for suburbs that we use during our search.</li>
<li><strong>How We Find Stuff (FAST ESP)</strong> &#8211; All Sensis properties use <a href="http://www.microsoft.com/enterprisesearch/en/us/fast-customer.aspx">FAST ESP</a> (bought by Microsoft last year) for their search requirements. Being a test bed for new functionality (of which search is a major component), we use it too.  In the open source world <a href="http://lucene.apache.org/solr/">Solr</a> (build on Lucene), <a href="http://www.sphinxsearch.com/">Sphinx</a> or <a href="http://xapian.org/">Xapian</a> may fill the same requirements. We make heavy use of FAST and many of it&#8217;s feature and there is much we can say about it as well as all the things we have learned about search from using it, but we&#8217;re trying to keep this short and sweet, so moving right along.</li>
</ul>
<p>That&#8217;s our logical design, but physically we have two servers.</p>
<h2>Why Two Machines?</h2>
<p>Notice that one of our machine is completely devoted to FAST (our search product). While we could use just a single server for delivering search results we need the grunt power of a second machine when we &#8220;ingest&#8221; our data (load it) into FAST.</p>
<p>If you have a comment or suggestion about our setup or simply want to <span style="text-decoration: line-through;">brag about</span> showcase your own, please leave a comment, we&#8217;d love to hear from you.</p>
]]></content:encoded>
			<wfw:commentRss>http://yellowlab.com.au/blog/2009/08/19/what-a-modern-rails-application-looks-like-in-production/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
