<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
 
 <title>Luke Randall</title>
 
 <link href="http://lukerandall.github.com/" />
 <updated>2012-02-11T23:02:29-08:00</updated>
 <id>http://lukerandall.github.com/</id>
 <author>
   <name>Luke Randall</name>
   <email>luke.randall@gmail.com</email>
 </author>

 
 <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/lukerandall" /><feedburner:info uri="lukerandall" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
   <title>Architecting a Rails App</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/v81Ju6zP9fw/architecting-a-rails-app.html" />
   <updated>2012-02-03T00:00:00-08:00</updated>
   <id>http://lukerandall.github.com/2012/02/03/architecting-a-rails-app</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2012/02/03/architecting-a-rails-app.html"&gt;Architecting a Rails App&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;3 February 2012 &amp;#8211; Cape Town&lt;/p&gt;
&lt;p&gt;I gave a talk yesterday at &lt;a href="http://rubyfuza.org"&gt;Rubyfuza&lt;/a&gt; about Architecting Rails Applications. Primarily I spoke about how the focus on &lt;span class="caps"&gt;MVC&lt;/span&gt; alone has provided an insufficient level of abstraction, causing our models to become a dumping ground for application logic. Using &lt;a href="http://en.wikipedia.org/wiki/Data,_context_and_interaction"&gt;&lt;span class="caps"&gt;DCI&lt;/span&gt;&lt;/a&gt; allows us to decompose and manage this complexity. By turning the algorithm into a first-class object in our code, we can better reason about it, more easily test it, and encapsulate it. Like any design pattern, it&amp;#8217;s not always applicable, and won&amp;#8217;t solve every problem, but it is a useful tool. My slides won&amp;#8217;t be as meaningful without the talk, but here they are:&lt;/p&gt;
&lt;script src="http://speakerdeck.com/embed/4f2a83126a1774001f016ebc.js"&gt;&lt;/script&gt;&lt;p&gt;I think an extra ten minutes would have been useful &amp;#8211; there were certain things I had to hurry through to fit into the time slot and still have a couple minutes to answer questions. Chatting to &lt;a href="http://nicksda.apotomo.de"&gt;Nick Sutterer&lt;/a&gt; afterwards, he mentioned that he would have liked to see a bit more time spent discussing contexts specifically. I agree &amp;#8211; for a concept that&amp;#8217;s so vital I didn&amp;#8217;t spend enough time examining it. That&amp;#8217;s something I will try rectify by exploring it in more detail here.&lt;/p&gt;
&lt;p&gt;After the conference was done for the day, &lt;a href="http://svenfuchs.com"&gt;Sven Fuchs&lt;/a&gt; and I chatted for a bit, and he raised (not for the first time) the issue of whether &lt;code&gt;#extend&lt;/code&gt; is too expensive to call during each request/response lifecycle. I was aware that it might be an issue with JRuby due to it clobbering the constants lookup cache (see &lt;a href="http://blog.headius.com/2011/08/invokedynamic-in-jruby-constant-lookup.html"&gt;this blog post by Charles Nutter&lt;/a&gt; for some details on why this is), and he said it was likely an issue with Rubinius as well. I don&amp;#8217;t know, and I think it&amp;#8217;s something worth investigating. I&amp;#8217;ve seen some microbenchmarks on the matter, but I don&amp;#8217;t know how much faith one can put in them. It seems to me they benchmark the cost of calling &lt;code&gt;#extend&lt;/code&gt; itself, without taking into account the long term cost (ie across multiple requests).&lt;/p&gt;
&lt;p&gt;Two things strike me whilst writing this &amp;#8211; firstly, it&amp;#8217;s possible (likely even) that for the average application the extra cost to lookup constants is not going to be what determines whether or not the system performs adequately, and secondly, there is nothing inherent in &lt;span class="caps"&gt;DCI&lt;/span&gt; that requires that we use &lt;code&gt;#extend&lt;/code&gt;. The fact that &lt;span class="caps"&gt;DCI&lt;/span&gt; is happily used in statically typed languages would suggest that this is the case. There are various alternatives that have already occured to me, none of which I&amp;#8217;ve thought through particularly well, and none of which I like, but nonetheless I think with further thought at least one idea would be found to be a workable solution. I&amp;#8217;m interested to see what ideas others have on the matter.&lt;/p&gt;
&lt;p&gt;One thing that came up in the questions at the end of the talk was that someone (as I recall Sven) asked about the usage of &lt;code&gt;#call&lt;/code&gt; for the context. I was glad it was raised, as it&amp;#8217;s something I forgot to mention during the talk. I owe the insight (as I indeed owe &lt;a href="http://mikepackdev.com/blog_posts/24-the-right-way-to-code-dci-in-ruby"&gt;the code in question&lt;/a&gt;) to Mike Pack. He suggests &lt;code&gt;#call&lt;/code&gt; in lieu of &lt;code&gt;#execute&lt;/code&gt;, &lt;code&gt;#run&lt;/code&gt; or the various other verbiage that others have suggested as it retains the same calling semantics were one to use a Proc instead of a class based approach to Contexts.&lt;/p&gt;
&lt;p&gt;When it comes to &lt;span class="caps"&gt;DCI&lt;/span&gt;, I owe the understanding I have &amp;#8211; but certainly not any misconceptions &amp;#8211; to a wide variety of sources, but some I found particularly helpful were: &lt;a href="http://mikepackdev.com/blog_posts/24-the-right-way-to-code-dci-in-ruby"&gt;Mike Pack&lt;/a&gt;, &lt;a href="http://andrzejonsoftware.blogspot.com/2011/02/dci-and-rails.html"&gt;Andrzej Krzywda&lt;/a&gt; and &lt;a href="http://saturnflyer.com/blog/jim/2011/10/04/oop-dci-and-ruby-what-your-system-is-vs-what-your-system-does/"&gt;Jim Gay&lt;/a&gt;; as well as the obvious duo of &lt;a href="http://www.artima.com/articles/dci_vision.html"&gt;Trygve Reenskaug and James Coplien&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/v81Ju6zP9fw" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2012/02/03/architecting-a-rails-app.html</feedburner:origLink></entry>
 
 <entry>
   <title>Rubyfuza Again</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/fkZcITlLoGY/rubyfuza-again.html" />
   <updated>2012-02-02T00:00:00-08:00</updated>
   <id>http://lukerandall.github.com/2012/02/02/rubyfuza-again</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2012/02/02/rubyfuza-again.html"&gt;Rubyfuza Again&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;2 February 2012 &amp;#8211; Cape Town&lt;/p&gt;
&lt;p&gt;Later today I&amp;#8217;ll be giving a talk at Rubyfuza. I&amp;#8217;ll be posting the slides when I&amp;#8217;m done.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/fkZcITlLoGY" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2012/02/02/rubyfuza-again.html</feedburner:origLink></entry>
 
 <entry>
   <title>Feedburner</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/-O2o9E5BFC8/feedburner.html" />
   <updated>2011-05-26T00:00:00-07:00</updated>
   <id>http://lukerandall.github.com/2011/05/26/feedburner</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2011/05/26/feedburner.html"&gt;Feedburner&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;26 May 2011 &amp;#8211; Cape Town&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve changed my Atom feed to use Feedburner, so for the 2 (hmm, that might be a generous total) of you following my blog, please point your feed reader at &lt;a href="http://feeds.feedburner.com/lukerandall"&gt;http://feeds.feedburner.com/lukerandall&lt;/a&gt; so that you can stay up to date. Thanks.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/-O2o9E5BFC8" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2011/05/26/feedburner.html</feedburner:origLink></entry>
 
 <entry>
   <title>Monoids</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/9J3kcYY8jYg/monoids.html" />
   <updated>2011-05-22T00:00:00-07:00</updated>
   <id>http://lukerandall.github.com/2011/05/22/monoids</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2011/05/22/monoids.html"&gt;Monoids&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;22 May 2011 &amp;#8211; Cape Town&lt;/p&gt;
&lt;p&gt;In an effort to break the usual Haskell newbie cycle of writing another blog post on monads, my inaugural Haskell themed blog post will be about &lt;strong&gt;monoids&lt;/strong&gt;, which I&amp;#8217;ve found to be surprisingly interesting.&lt;/p&gt;
&lt;h2&gt;What is a monoid?&lt;/h2&gt;
&lt;p&gt;Simply put, a monoid is an algebraic type with an associative binary operation &amp;#8211; ie an operation that has two operands &amp;#8211; called mappend, and an identity element &amp;#8211; an element that, when combined with another element using the aforementioned binary operation, leaves the element unchanged &amp;#8211; called mempty. Disregarding the unfortunate choice of names, some examples might help to illustrate the concept:&lt;/p&gt;
&lt;p&gt;The natural numbers form a monoid under addition, with the binary operation obviously being addition, and the identity element 0. Likewise, they form a monoid under multiplication, with the identity element being 1. In both cases, the truthfulness of this can be trivially tested. Addition and multiplication both take two operands. Further adding 0 to any number returns that number; multiplying any number by 1 returns that number.&lt;/p&gt;
&lt;h2&gt;What&amp;#8217;s the point?&lt;/h2&gt;
&lt;p&gt;With such simple examples, one might wonder what utility there is in creating a type class for monoids. In truth, I feel the power of monoids comes from the fact that they are 1. rather general, and 2. very simple. Since there is no limitation on the binary operation beyond that it be associative, many things can be represented as a monoid. Looking at the &lt;a href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Monoid.html"&gt;Data.Monoid documentation&lt;/a&gt; one finds a number of monoid instances.&lt;/p&gt;
&lt;h2&gt;Folding with monoids&lt;/h2&gt;
&lt;p&gt;To illustrate the utility of monoids, let&amp;#8217;s try using foldMap and a few monoid instances. For example, the Sum monoid can be used thusly:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="haskell"&gt;&lt;span class="nf"&gt;foldMap&lt;/span&gt; &lt;span class="kt"&gt;Sum&lt;/span&gt; &lt;span class="kt"&gt;[]&lt;/span&gt;
&lt;span class="nf"&gt;foldMap&lt;/span&gt; &lt;span class="kt"&gt;Sum&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;which return respectively Sum 0 and Sum 6. &amp;#8220;So what?&amp;#8221;, I hear you ask. Well, consider the situation where you want to compute the sum and the product of a list. No problem:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="haskell"&gt;&lt;span class="nf"&gt;foldMap&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;\&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Sum&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;which returns a tuple containing Sum 10 and Product 24. I suppose it would be more accurate to say it returns:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="haskell"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Sum&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;getSum&lt;/span&gt; &lt;span class="ow"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="kt"&gt;Product&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;getProduct&lt;/span&gt; &lt;span class="ow"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The getSum and getProduct wrappers are because there can only exist one monoid instance per data type, so Sum and Product are newtype wrappers around Num.&lt;/p&gt;
&lt;h2&gt;I&amp;#8217;m still not impressed&lt;/h2&gt;
&lt;p&gt;Gosh, you really lack imagination, don&amp;#8217;t you? Anything that obeys our monoid laws can be made a monoid. For example, consider two functions with type signature Monoid b =&amp;gt; a &amp;#8594; b. There exists a monoid for said functions, which means you can combine these two functions with mappend. What does this mean for you? As &lt;a href="http://www.reddit.com/r/programming/comments/7cf4r/monoids_in_my_programming_language/c06adnx"&gt;cgibbard wonderfully demonstrates&lt;/a&gt; &amp;#8211; and indeed this is what first helped me to recognise the universal utility of monoids &amp;#8211; using the Ordering data type, you can order a list using a variety of criteria simply and succinctly. To wit, Ordering forms a monoid under the following usage:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="haskell"&gt;&lt;span class="kt"&gt;LT&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="n"&gt;mappend&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt; &lt;span class="kr"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;LT&lt;/span&gt;
&lt;span class="kt"&gt;GT&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="n"&gt;mappend&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt; &lt;span class="kr"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;GT&lt;/span&gt;
&lt;span class="kt"&gt;EQ&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="n"&gt;mappend&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;

&lt;span class="nf"&gt;mempty&lt;/span&gt; &lt;span class="ow"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;EQ&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Suppose then that we have a list containing integers, and we wish to sort it first by the sum of the list, then by list length, then by ordinary numerical sorting of the elements, one can do the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="haskell"&gt;&lt;span class="nf"&gt;sortBy&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;comparing&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="n"&gt;mappend&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt; &lt;span class="n"&gt;comparing&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="p"&gt;`&lt;/span&gt;&lt;span class="n"&gt;mappend&lt;/span&gt;&lt;span class="p"&gt;`&lt;/span&gt; &lt;span class="n"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;returning [[1,1,1,1],[5,1],[1,2,3],[3,2,1],[1,1,1,1,1,1],[4,2,1]]. As you can see, the list was sorted by sum, then length, then by comparison (hence [1,2,3] coming before [3,2,1]). Now consider how much code it would have taken to do this without using monoids.&lt;/p&gt;
&lt;h2&gt;You&amp;#8217;d better be impressed&lt;/h2&gt;
&lt;p&gt;Although these examples barely skim the surface of all you can do with monoids, I hope demonstrated how much simpler your code could be by recognising and using monoids appropriately. Since first learning about them, it&amp;#8217;s surprised me how this simple pattern appears in code I write &lt;strong&gt;every single day&lt;/strong&gt;, and how often I could have written far simpler code if I had but recognised it for what it was &amp;#8211; a simple, lowly monoid.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/9J3kcYY8jYg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2011/05/22/monoids.html</feedburner:origLink></entry>
 
 <entry>
   <title>Haskell Again</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/HyEoZapiZEw/haskell-again.html" />
   <updated>2011-04-21T00:00:00-07:00</updated>
   <id>http://lukerandall.github.com/2011/04/21/haskell-again</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2011/04/21/haskell-again.html"&gt;Haskell Again&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;21 April 2011 &amp;#8211; Cape Town&lt;/p&gt;
&lt;p&gt;It struck me, as I started typing this page, that I don&amp;#8217;t move around nearly enough to warrant including a location in each blog post. Maybe once every few years when I move I can write &amp;#8220;the next 5 years of blogging coming to you from &lt;em&gt;city name&lt;/em&gt;&amp;#8221; or something to that effect. Anyhow&amp;#8230;  As usual, I realised I haven&amp;#8217;t blogged in ages. Like most blogs, mine seems to be a sort of metablog about blogging (or the absence thereof) rather than content. Perhaps this is the start of something more. Time will tell.&lt;/p&gt;
&lt;p&gt;As usual, I&amp;#8217;ve spent the last year suffering from technology-induced &lt;span class="caps"&gt;ADD&lt;/span&gt;. This includes starting 2 books on Scala, a book on Clojure, one on Common Lisp, another on JavaScript, etc. I&amp;#8217;d say the JavaScript one was most successful in that I actually read enough of it for it to have affected my understanding (and writing) of JavaScript. I&amp;#8217;ve since realised that, as much as there are 100 different subjects that fascinate me, I&amp;#8217;m never going to master any of them unless I&amp;#8217;m willing to accept that I need to focus on one or two at a time.&lt;/p&gt;
&lt;p&gt;With that in mind, I&amp;#8217;ve decided my primary focus &amp;#8211; outside of whatever I&amp;#8217;m doing at work, which will likely be a combination of Ruby and Objective-C &amp;#8211; will be Haskell. I&amp;#8217;m tired of having to resolve problems and rediscover things I&amp;#8217;ve learnt before, so I&amp;#8217;m going to try catalogue things as I learn them.&lt;/p&gt;
&lt;h2&gt;Starting today&lt;/h2&gt;
&lt;p&gt;I watched some presentations given by &lt;a href="http://vimeo.com/user4351020/videos/sort:date"&gt;Nick Partridge&lt;/a&gt; on Haskell, and learnt about or was reminded of a few things. Briefly:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Use &lt;a href="http://hackage.haskell.org/package/pointful"&gt;pointful&lt;/a&gt; to help you make sense of complex point-free expressions.&lt;/li&gt;
	&lt;li&gt;Use &lt;a href="http://hackage.haskell.org/package/pointfree"&gt;pointfree&lt;/a&gt; to turn pointful expressions into (complex, at times) pointfree expressions.&lt;/li&gt;
	&lt;li&gt;Use &lt;a href="http://community.haskell.org/~ndm/hlint/"&gt;hlint&lt;/a&gt; on your source code for suggestions on how to improve it.&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://www.haskell.org/hoogle/"&gt;Hoogle&lt;/a&gt; can be installed locally.&lt;/li&gt;
	&lt;li&gt;First look in hackage for libraries that do what you are trying to accomplish before writing your own code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Those were the salient points for me. Now I&amp;#8217;m off to try my hand at getting Yesod up and running.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/HyEoZapiZEw" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2011/04/21/haskell-again.html</feedburner:origLink></entry>
 
 <entry>
   <title>Some rambling thoughts on type inference</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/udJ1xq_DAQM/some-rambling-thoughts-on-type-inference.html" />
   <updated>2010-12-02T00:00:00-08:00</updated>
   <id>http://lukerandall.github.com/2010/12/02/some-rambling-thoughts-on-type-inference</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2010/12/02/some-rambling-thoughts-on-type-inference.html"&gt;Some rambling thoughts on type inference&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;02 Dec 2010 &amp;#8211; Cape Town&lt;/p&gt;
&lt;p&gt;O&amp;#8217;Reilly were having one of their site-wide ebook discounts, and as usual I scoured the very comprehensive list of books to see what I should buy. It&amp;#8217;s funny how something will suddenly become a necessity when you can get 60% off the purchase price. Needless to say I wound up buying &lt;a href="http://programmingscala.com/"&gt;Programming Scala&lt;/a&gt;, in spite of already owning a perfectly good &amp;#8211; and unread &amp;#8211; copy of &lt;a href="http://www.artima.com/shop/programming_in_scala"&gt;Programming in Scala&lt;/a&gt;. Admittedly, I did find the latter somewhat slow going, which has not helped in my efforts to try and learn the language.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve always (for the last 6 months at least!) considered my lack of knowledge of Scala to be an unfortunate shortcoming, and so I reasoned if I bought Just One More Book on it, I might read enough of it to learn a sufficent portion of the language to start enjoying it, allowing me to stick it out and learn further. It&amp;#8217;s frustrating to me how many programming books start out by detailing minutiae of a language instead of getting on with teaching us about it&amp;#8217;s style and strengths. I enjoy being given a complex, idiomatic piece of code in a language and having to figure out what it does, as well as identify the strange (or familiar) programming idioms. I find it fascinating to learn the different styles and patterns that become best practice in different languages.&lt;/p&gt;
&lt;p&gt;Anyway, as I started reading, I was wondering how Scala performs it&amp;#8217;s type inference. All the languages that perform type inference that I have a knowledge of use Hindley-Milner (or Damas-Milner to the pedantic), or some derivative of that. This is true of Haskell, ML, F#, etc.&lt;/p&gt;
&lt;p&gt;While searching for an answer, I came across &lt;a href="http://www.codecommit.com/blog/scala/universal-type-inference-is-a-bad-thing"&gt;an article&lt;/a&gt; which suggests that H-M type inference is a bad thing. It contrasts two equivalent pieces of code &amp;#8211; written in ML and Scala &amp;#8211; and posits that the Scala version is somehow superior to the ML version, precisely because it is more verbose. Okay, it&amp;#8217;s on the verbosity per se, but the type annotations necessitated by Scala performing only local type inference. Reading on, the author reasons that, due to the extensive use of type annotations in the Scala version, it is safer and more useful than the ML version. I must say, I find this argument to be rather absurd.&lt;/p&gt;
&lt;p&gt;In Haskell, I&amp;#8217;ve found type inference to be hugely useful. It gives the code you write a feel more akin to dynamically typed languages than the verbose, boilerplate filled code one normally associates with statically typed languages. Letting the compiler figure out the types lets you focus on solving the problem, not babysitting the compiler.&lt;/p&gt;
&lt;p&gt;However, I have found it very useful when writing a function to start by thinking about its type signature. It accomplishes a number of things:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;It forces you to formalise the problem in your head, and helps ensure your solution is actually solving the problem.&lt;/li&gt;
	&lt;li&gt;It gives you and others reading your code a succint explanation of what the code is doing.&lt;/li&gt;
	&lt;li&gt;It prevents errors of the sort the author complains about, where your function behaves differently to your expectations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;#8217;m not sure if this just reflects a difference in culture between Haskell and ML, but I&amp;#8217;ve found (from my admittedly limited experience with Haskell) that there is an emphasis on manually writing the type signature for all but the most basic functions, to ensure that your function isn&amp;#8217;t just internally consistent, but also consistent with your expectations of it. It provides numerous benefits, adds a single line of code above the function, and obviates the need for scattering ugly type annotations throughout your code.&lt;/p&gt;
&lt;p&gt;If, as the author says, there is a tendency in ML to only include the type signature when necessary, I can see why this might cause frustration. But, it seems to be a case of throwing out the baby with the bathwater when the problem can be solved quite simply, and not by &amp;#8220;protecting&amp;#8221; ourselves by using a dumbed down type inference algorithm.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/udJ1xq_DAQM" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2010/12/02/some-rambling-thoughts-on-type-inference.html</feedburner:origLink></entry>
 
 <entry>
   <title>Could it be</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/P2Dv5HsGtFQ/could-it-be.html" />
   <updated>2010-11-28T00:00:00-08:00</updated>
   <id>http://lukerandall.github.com/2010/11/28/could-it-be</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2010/11/28/could-it-be.html"&gt;Could it be&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;28 Nov 2010 &amp;#8211; Cape Town&lt;/p&gt;
&lt;p&gt;Lately I&amp;#8217;ve been trying to learn a lot of new (at least for me) technologies and languages, and I&amp;#8217;ve wanted a place to keep track of my thoughts and progress. So I&amp;#8217;ve decided it makes sense for my to dust off the cobwebs and see if I can try make blogging stick. Time will tell.&lt;/p&gt;
&lt;h2&gt;What&amp;#8217;s new?&lt;/h2&gt;
&lt;p&gt;I&amp;#8217;ve changed things up a bit. Mostly by swapping out my dull sans serif font stack for Skolar. TypeKit is great, and I&amp;#8217;m glad to finally have a site where I can use it.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve swapped out the most of the blue in the old style for red. It&amp;#8217;s a work in progress, but I think it&amp;#8217;s an improvement.&lt;/p&gt;
&lt;h2&gt;What I&amp;#8217;ll be writing about&lt;/h2&gt;
&lt;p&gt;Lately I&amp;#8217;ve finally taken it upon myself to improve my JavaScript. I&amp;#8217;ll be doing some pretty interesting things in the coming months.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m also taking the time to learn more about functional programming, and in particular Haskell, so I&amp;#8217;ll probably have some very rudimentary posts about Haskell from time to time.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/P2Dv5HsGtFQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2010/11/28/could-it-be.html</feedburner:origLink></entry>
 
 <entry>
   <title>Time travelling with Jekyll</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/JMDRa3GFfQs/time-travelling-with-jekyll.html" />
   <updated>2009-02-11T00:00:00-08:00</updated>
   <id>http://lukerandall.github.com/2009/02/11/time-travelling-with-jekyll</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2009/02/11/time-travelling-with-jekyll.html"&gt;Time travelling with Jekyll&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;11 Feb 2009 &amp;#8211; Johannesburg&lt;/p&gt;
&lt;p&gt;So I went ahead and changed the front page so that it showed my last couple of posts. I didn&amp;#8217;t like it though, so I changed it back. At the end of the day the whole thing is something of a hack since I just truncate the content of the post, which means that the &lt;span class="caps"&gt;HTML&lt;/span&gt; has a 99% chance of missing a closing p tag or something. Anyway, it works for now&amp;#8230;&lt;/p&gt;
&lt;p&gt;One thing that I haven&amp;#8217;t figured out with Jekyll is how to have multiple entries from the same day appear in the correct order. I suppose I haven&amp;#8217;t really tried to figure it out. I suppose the obvious thing to do would be to add in a timestamp. I dunno if Jekyll supports anything but the date. So in the meantime I&amp;#8217;ve just resorted to back dating and post dating entries if the order is important. Hence the title of this post&amp;#8230;&lt;/p&gt;
&lt;p&gt;I was looking back at my old, abandoned blog (with all of two entries) and it struck me how quickly things move. I was busy blogging about Git and how I planned to look into GitHub. That was back in the days when you needed an invite to get onto GitHub. And that was less than a year ago. In less than a year GitHub has completely revolutionised open source, and more specifically Ruby, development.&lt;/p&gt;
&lt;p&gt;Anyway, I hadn&amp;#8217;t intended for this to be long. I&amp;#8217;m hoping for once to get a decent night&amp;#8217;s rest.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/JMDRa3GFfQs" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2009/02/11/time-travelling-with-jekyll.html</feedburner:origLink></entry>
 
 <entry>
   <title>A few new additions</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/AOp2nwWE9cQ/a-few-new-additions.html" />
   <updated>2009-02-10T00:00:00-08:00</updated>
   <id>http://lukerandall.github.com/2009/02/10/a-few-new-additions</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2009/02/10/a-few-new-additions.html"&gt;A few new additions&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;10 Feb 2009 &amp;#8211; Johannesburg&lt;/p&gt;
&lt;p&gt;Well, more like one new addition. Since I don&amp;#8217;t blog all that often, and I don&amp;#8217;t have anything else I&amp;#8217;m linking to, I disliked the fact that my latest blog entry wasn&amp;#8217;t displayed on the home page. So, searching the net for a liquid cheat sheet (since I&amp;#8217;ve never used it before), I hacked away at my index page for a few minutes and now have a truncated version of my newest post displayed on the home page. I&amp;#8217;m thinking I&amp;#8217;ll probably do that for the last 3 &amp;#8211; 5 posts, and then display links to the older ones, but I&amp;#8217;ll get to that soon enough.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/AOp2nwWE9cQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2009/02/10/a-few-new-additions.html</feedburner:origLink></entry>
 
 <entry>
   <title>Someone reminded me to update my blog</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/XqX32wtfH6Q/someone-reminded-me-to-update-my-blog.html" />
   <updated>2009-02-09T00:00:00-08:00</updated>
   <id>http://lukerandall.github.com/2009/02/09/someone-reminded-me-to-update-my-blog</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2009/02/09/someone-reminded-me-to-update-my-blog.html"&gt;Someone reminded me to update my blog&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;09 Feb 2009 &amp;#8211; Johannesburg&lt;/p&gt;
&lt;p&gt;Today, someone tweeted me and reminded me that my blog is one of the most shamefully neglected corners of cyberspace. Since I&amp;#8217;ve never had anyone express interest in my blog before, I&amp;#8217;ve never really felt too bad. But the fact that someone actually took notice means that I need to repent and become a more devout blogger.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve been using Rails 2.3 for the past week or two. Well, 2.3 RC1 to be precise. It seems more than stable &amp;#8211; certainly I&amp;#8217;ve yet to run into any issues with it. And truly, the output of rake routes is a joy to behold now that all the formatted routes crap is gone. I don&amp;#8217;t know that we use enough routes in any of our projects for it to make a &lt;strong&gt;huge&lt;/strong&gt; difference memory-wise, but I&amp;#8217;ll test that when I upgrade one of our older projects from Rails 2.1 to 2.3. Mostly I haven&amp;#8217;t because I&amp;#8217;ve just been a bit lazy. Considering it&amp;#8217;s about 10 minutes worth of work (plus a few more to test), I really just need to buckle down and do it.&lt;/p&gt;
&lt;p&gt;In other news, since I&amp;#8217;ve been working more closely with other developers, I&amp;#8217;ve actually started remembering to switch out to branches before I add features. When you&amp;#8217;re pretty much the only person working on a particular code base, working on the master branch causes problems rarely enough that you tend to just do it. However, it&amp;#8217;s one of those things that I&amp;#8217;ve known I shouldn&amp;#8217;t be doing for a while, so I&amp;#8217;m glad I&amp;#8217;ve finally had something to push me to remember. Now finally I can stop abusing git stash.&lt;/p&gt;
&lt;p&gt;Anyway, I&amp;#8217;m really going to try and make time for a few blog posts a week, since I often have things I think I should blog about but neglect to. Let&amp;#8217;s see how that goes.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/XqX32wtfH6Q" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2009/02/09/someone-reminded-me-to-update-my-blog.html</feedburner:origLink></entry>
 
 <entry>
   <title>Things I think I'll like about Jekyll</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/VHoFYWq5CT0/things-i-think-ill-like-about-jekyll.html" />
   <updated>2008-12-22T00:00:00-08:00</updated>
   <id>http://lukerandall.github.com/2008/12/22/things-i-think-ill-like-about-jekyll</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2008/12/22/things-i-think-ill-like-about-jekyll.html"&gt;Things I think I&amp;#8217;ll like about Jekyll&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;22 Dec 2008 &amp;#8211; Johannesburg&lt;/p&gt;
&lt;p&gt;Well, it&amp;#8217;s been all of ten minutes. No wait, maybe fifteen. Anyway, with that much exposure to it, this is a real first impressions type post. But here&amp;#8217;s what seems cool thus far.&lt;/p&gt;
&lt;h2&gt;Uses Git (and integrates with GitHub)&lt;/h2&gt;
&lt;p&gt;I like the fact that I can edit blog posts from TextMate. I think a big reason for me never blogging is the fact that I have to think of going to my Wordpress site, logging into the admin section, and then composing a new entry. Now, this doesn&amp;#8217;t sound like much work (it really isn&amp;#8217;t), but I suppose I&amp;#8217;m lazy, and so being able to do things from TextMate (which &amp;#8211; on my machine &amp;#8211; is open 95% of the time) makes the workflow just that little bit cleaner. Plus, I can push the changes out to GitHub with just a couple of keystrokes.&lt;/p&gt;
&lt;p&gt;Admittedly, this is not solely a Jekyll feature, since much of it&amp;#8217;s utility depends on GitHub&amp;#8230; Still, I&amp;#8217;m viewing Jekyll from the angle of GitHub pages, so I think it&amp;#8217;s a fair point.&lt;/p&gt;
&lt;h2&gt;You can hack on it. Easily&lt;/h2&gt;
&lt;p&gt;The code for this blog is pretty much straight &lt;span class="caps"&gt;HTML&lt;/span&gt; or Textile, with maybe 2 loops (using Liquid) to display the list of blog posts. You can&amp;#8217;t get simpler than that.&lt;/p&gt;
&lt;h2&gt;And&amp;#8230;?&lt;/h2&gt;
&lt;p&gt;Okay, so that&amp;#8217;s only two points. But what more could you ask for in a blogging engine? Basically, the features &lt;span class="caps"&gt;TPW&lt;/span&gt; wanted it to have are really useful, and seem to be exactly what I need to start blogging more often. Time will tell I suppose.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/VHoFYWq5CT0" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2008/12/22/things-i-think-ill-like-about-jekyll.html</feedburner:origLink></entry>
 
 <entry>
   <title>My newest blog</title>
   <link href="http://feedproxy.google.com/~r/lukerandall/~3/S1Cc-x86W1U/my-newest-blog.html" />
   <updated>2008-12-22T00:00:00-08:00</updated>
   <id>http://lukerandall.github.com/2008/12/22/my-newest-blog</id>
   <content type="html">&lt;h1&gt;&lt;a href="/2008/12/22/my-newest-blog.html"&gt;My newest blog&lt;/a&gt;&lt;/h1&gt;
&lt;p class="meta"&gt;22 Dec 2008 &amp;#8211; Johannesburg&lt;/p&gt;
&lt;p&gt;Well, I&amp;#8217;m at it again &amp;#8211; creating a new blog. I think my blog:posts ratio is close enough to 1:1 that the actual variance is negligible. It&amp;#8217;s shocking really. My last blog contained exactly 1 post, as did the one before it, etc. Plus to offset the few blogs that have contained multiple posts, I&amp;#8217;ve created a few blogs that never even got their first post. For shame!&lt;/p&gt;
&lt;p&gt;Anyway, this is a shameless rip-off of &lt;a href="http://mojombo.github.com"&gt;Mojombo&amp;#8217;s blog&lt;/a&gt;, which he has happily invited us all to rip-off. I&amp;#8217;m initially just interested in seeing my own name in Shiny letters on my GitHub page. I have high hopes of &amp;#8211; in time &amp;#8211; making this my own little creation. We&amp;#8217;ll see I suppose.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/lukerandall/~4/S1Cc-x86W1U" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://lukerandall.github.com/2008/12/22/my-newest-blog.html</feedburner:origLink></entry>
 
 
</feed>

