<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
        <title>Datamangling</title>
        <description>Datamangling - Gavin Heavyside</description>
        <link>http://datamangling.com</link>
        <link>http://datamangling.com</link>
        <lastBuildDate>2014-03-02T03:34:39-08:00</lastBuildDate>
        <pubDate>2014-03-02T03:34:39-08:00</pubDate>
        <ttl>1800</ttl>


        <item>
                <title>LIMIT 1 and performance in a Postgres query</title>
                <description>&lt;p&gt;I’ve just been debugging a slow-running report, and reduced the runtime from over 3 hours to under 5 minutes. The problem turned out to be the impact of &lt;code&gt;LIMIT 1&lt;/code&gt; on a simple SQL query on a Postgres DB.&lt;/p&gt;

&lt;p&gt;The report is fairly straightforward, and the queries it executes are also pretty simple, so it was a surprise to see how slowly it ran in production.&lt;/p&gt;

&lt;p&gt;The script is written in Ruby, running against one of our Rails applications. Instrumenting the script showed that one particular query, which only used one table, was often taking several seconds. It wasn’t obvious to me why it should be so slow. The table has several million rows, but sensible indexes are in place, and we don’t have any problems in production. I restored a backup of the DB to a isolated box, and started to experiment.&lt;/p&gt;

&lt;p&gt;I took the generated SQL of the query, and looked at the query plan and performance. &lt;code&gt;EXPLAIN ANALYZE&lt;/code&gt; is your friend here, as you get both the query plan and the actual runtime of the query:&lt;/p&gt;

&lt;pre class=&quot;sql&quot;&gt;&lt;code class=&quot;sql&quot;&gt;
EXPLAIN ANALYZE SELECT field1 FROM table WHERE field2 = value ORDER BY field3 DESC LIMIT 1;

QUERY PLAN
--------------------
  Limit  (cost=0.00..524.25 rows=1 width=34) (actual time=5572.027..5572.028 rows=1 loops=1)
  -&amp;gt;  Index Scan Backward using index_table_on_field3 on table  (cost=0.00..569861.98 rows=1087 width=34) (actual time=5572.018..5572.018 rows=1 loops=1)
Filter: (field2 = value)
  Total runtime: 5572.056 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A runtime of over five seconds. How many rows does are we working with?&lt;/p&gt;

&lt;pre class=&quot;sql&quot;&gt;&lt;code class=&quot;sql&quot;&gt;
SELECT COUNT(*) FROM table WHERE field2 = value;

  count
-------
  1020
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;5.5 seconds to pick a single row from just 1020 records? Something isn’t right. How long would it take to get ALL THE RECORDS? I dropped the &lt;code&gt;LIMIT 1&lt;/code&gt; from the query:&lt;/p&gt;

&lt;pre class=&quot;sql&quot;&gt;&lt;code class=&quot;sql&quot;&gt;
EXPLAIN ANALYZE SELECT field1 FROM table WHERE field2 = value ORDER BY field3 DESC;

QUERY PLAN
--------------------
Sort  (cost=1080.91..1083.63 rows=1087 width=34) (actual time=46.318..47.194 rows=1020 loops=1)
  Sort Key: field3
  Sort Method: quicksort  Memory: 104kB
  -&amp;gt;  Index Scan using index_table_on_field2 on table  (cost=0.00..1026.09 rows=1087 width=34) (actual time=0.245..44.305 rows=1020 loops=1)
Index Cond: (field2 = value)
  Total runtime: 48.199 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;WTF? 48ms to return all the records, but 5.5s for just one? Also note that the query planner is now using the index on field2 (i.e. 1020 rows) instead of the index on field3 (several million rows). I hit the internets, and found that adding a &lt;code&gt;LIMIT&lt;/code&gt; can often confuse the query planner. &lt;a href=&quot;http://dba.stackexchange.com/a/19744&quot;&gt;This post&lt;/a&gt; suggested adding conditions to the &lt;code&gt;ORDER BY&lt;/code&gt;. I added &lt;code&gt;field1&lt;/code&gt; to the ordering and the results were startling:&lt;/p&gt;

&lt;pre class=&quot;sql&quot;&gt;&lt;code class=&quot;sql&quot;&gt;
EXPLAIN ANALYZE SELECT field1 FROM table WHERE field2 = value ORDER BY field3 DESC, field1 LIMIT 1;

QUERY PLAN
--------------------
Limit  (cost=1031.53..1031.53 rows=1 width=34) (actual time=3.856..3.857 rows=1 loops=1)
-&amp;gt;  Sort  (cost=1031.53..1034.24 rows=1087 width=34) (actual time=3.853..3.853 rows=1 loops=1)
  Sort Key: field3, field1
  Sort Method: top-N heapsort  Memory: 25kB
  -&amp;gt;  Index Scan using index_table_on_field2 on table  (cost=0.00..1026.09 rows=1087 width=34) (actual time=0.028..2.667 rows=1020 loops=1)
Index Cond: (field2 = value)
  Total runtime: 3.890 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So we’ve gone from 5.5 seconds to just 3.9ms, by adding an irrelevant condition to the &lt;code&gt;ORDER&lt;/code&gt; clause. Adding &lt;code&gt;.order(:field1)&lt;/code&gt; to my Rails script got that added to the generated SQL, and the run time of the whole report reduced from over 3 hours to under 5 minutes.&lt;/p&gt;</description>
                <link>http://datamangling.com/2014/01/17/limit-1-and-performance-in-a-postgres-query</link>
                <guid>http://datamangling.com/2014/01/17/limit-1-and-performance-in-a-postgres-query</guid>
                <pubDate>2014-01-17T00:00:00-08:00</pubDate>
        </item>

        <item>
                <title>Location, Location, Location at ACCU 2013</title>
                <description>&lt;p&gt;Slides from my “Location, Location, Location” talk at &lt;a href=&quot;http://accu.org/index.php/conferences/accu_conference_2013&quot;&gt;ACCU2013&lt;/a&gt; in Bristol on 12 April 2013.&lt;/p&gt;

&lt;p&gt;The code can be found &lt;a href=&quot;https://github.com/gavinheavyside/geopostcoder&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div id=&#39;__ss_18682173&#39; style=&#39;width:427px&#39;&gt;
  &lt;strong style=&#39;display:block;margin:12px 0 4px&#39;&gt;
    &lt;a href=&#39;http://www.slideshare.net/gheavyside/location-location-location-18682173&#39; title=&#39;Location Location Location&#39;&gt;Location Location Location at ACCU 2013&lt;/a&gt;
  &lt;/strong&gt;
  &lt;iframe allowfullscreen=&#39;&#39; frameborder=&#39;0&#39; height=&#39;356&#39; marginheight=&#39;0&#39; marginwidth=&#39;0&#39; mozallowfullscreen=&#39;&#39; scrolling=&#39;no&#39; src=&#39;http://www.slideshare.net/slideshow/embed_code/18682173?rel=0&#39; style=&#39;border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px&#39; webkitallowfullscreen=&#39;&#39; width=&#39;427&#39;&gt; &lt;/iframe&gt;
  &lt;div style=&#39;padding:5px 0 12px&#39;&gt; View more &lt;a href=&#39;http://www.slideshare.net/&#39;&gt;presentations&lt;/a&gt; from &lt;a href=&#39;http://www.slideshare.net/gheavyside&#39; target=&#39;_blank&#39;&gt;Gavin Heavyside&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;</description>
                <link>http://datamangling.com/presentations/2013/04/16/location-location-location-at-accu2013</link>
                <guid>http://datamangling.com/presentations/2013/04/16/location-location-location-at-accu2013</guid>
                <pubDate>2013-04-16T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>DevOps and Infrastructure-As-Code at ACCU 2012</title>
                <description>&lt;p&gt;Slides from my “DevOps and Infrastructure-As-Code” talk atj &lt;a href=&quot;http://accu.org/index.php/conferences/accu_conference_2012&quot;&gt;ACCU2012&lt;/a&gt; in Oxford on 27th April&lt;/p&gt;

&lt;p&gt;I presented a 90-minute overview of infrastructure-as-code, chef, Vagrant, and zero-downtime deployment techniques.&lt;/p&gt;
&lt;div id=&#39;__ss_12742188&#39; style=&#39;width:425px&#39;&gt;
  &lt;strong style=&#39;display:block;margin:12px 0 4px&#39;&gt;
    &lt;a href=&#39;http://www.slideshare.net/gheavyside/devops-at-accu-2012&#39; title=&#39;DevOps at ACCU 2012&#39;&gt;DevOps at ACCU 2012&lt;/a&gt;
  &lt;/strong&gt;
  &lt;iframe allowfullscreen=&#39;&#39; frameborder=&#39;0&#39; height=&#39;355&#39; marginheight=&#39;0&#39; marginwidth=&#39;0&#39; mozallowfullscreen=&#39;&#39; scrolling=&#39;no&#39; src=&#39;http://www.slideshare.net/slideshow/embed_code/12742188?rel=0&#39; style=&#39;border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px&#39; webkitallowfullscreen=&#39;&#39; width=&#39;425&#39;&gt; &lt;/iframe&gt;
  &lt;div style=&#39;padding:5px 0 12px&#39;&gt; View more &lt;a href=&#39;http://www.slideshare.net/&#39;&gt;presentations&lt;/a&gt; from &lt;a href=&#39;http://www.slideshare.net/gheavyside&#39; target=&#39;_blank&#39;&gt;Gavin Heavyside&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;</description>
                <link>http://datamangling.com/presentations/2012/05/05/devops-and-infrastructure-as-code-at-accu2012</link>
                <guid>http://datamangling.com/presentations/2012/05/05/devops-and-infrastructure-as-code-at-accu2012</guid>
                <pubDate>2012-05-05T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>ACCU 2011 - Non-Relational Databases</title>
                <description>&lt;p&gt;These are the slides from my talk last Saturday at the &lt;a href=&quot;http://accu.org/index.php/conferences/accu_conference_2011&quot;&gt;ACCU2011 Conference&lt;/a&gt; in Oxford.&lt;/p&gt;

&lt;p&gt;I presented a 90-minute whirlwind tour of non-relational database families (trying my best to avoid saying ‘NoSQL’), and went into a little more detail for one in each of the column, graph, document and key-value families.&lt;/p&gt;

&lt;p&gt;These slides were chosen by Slideshare to be showcased on the front page of the Technology category&lt;/p&gt;
&lt;div id=&#39;__ss_7660456&#39; style=&#39;width:425px&#39;&gt;
  &lt;strong style=&#39;display:block;margin:12px 0 4px&#39;&gt;
    &lt;a href=&#39;http://www.slideshare.net/gheavyside/nonrelational-databases-at-accu2011&#39; title=&#39;Non-Relational Databases at ACCU2011&#39;&gt;Non-Relational Databases at ACCU2011&lt;/a&gt;
  &lt;/strong&gt;
  &lt;iframe allowfullscreen=&#39;&#39; frameborder=&#39;0&#39; height=&#39;355&#39; marginheight=&#39;0&#39; marginwidth=&#39;0&#39; mozallowfullscreen=&#39;&#39; scrolling=&#39;no&#39; src=&#39;http://www.slideshare.net/slideshow/embed_code/7660456?rel=0&#39; style=&#39;border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px&#39; webkitallowfullscreen=&#39;&#39; width=&#39;425&#39;&gt; &lt;/iframe&gt;
  &lt;div style=&#39;padding:5px 0 12px&#39;&gt; View more &lt;a href=&#39;http://www.slideshare.net/&#39;&gt;presentations&lt;/a&gt; from &lt;a href=&#39;http://www.slideshare.net/gheavyside&#39; target=&#39;_blank&#39;&gt;Gavin Heavyside&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;</description>
                <link>http://datamangling.com/presentations/2011/04/20/non-relational-databases-accu2011</link>
                <guid>http://datamangling.com/presentations/2011/04/20/non-relational-databases-accu2011</guid>
                <pubDate>2011-04-20T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Running a Jekyll blog on Heroku</title>
                <description>&lt;p&gt;This blog used to be hosted on the &lt;a href=&quot;http://github.com/mojombo/jekyll&quot;&gt;Jekyll&lt;/a&gt;-powered &lt;a href=&quot;http://pages.github.com&quot;&gt;Github Pages&lt;/a&gt;, and I was using the Custom Domains feature to have it appear under with the &lt;a href=&quot;http://datamangling.com&quot;&gt;DataMangling&lt;/a&gt; domain name. I’ve switched to&lt;br /&gt;hosting it with &lt;a href=&quot;http://heroku.com&quot;&gt;Heroku&lt;/a&gt; so that I can save myself $84 per year.&lt;/p&gt;

&lt;p&gt;Github only let you use Custom Domains if you’ve got a paid account. I had a micro (7$/month) plan, initially because I wanted to keep a couple of my repositories private, but I don’t need to do that anymore. I’m on a bit of an economy drive at the moment, so the monthly payment to Github has been a casualty of my belt-tightening.&lt;/p&gt;

&lt;p&gt;The only tangible consequence is I can no longer alias my own domain name to the blog. This is a bit annoying after I’d gone to the trouble of finding a dotcom domain that had the word data in it. The solution is to host the blog on &lt;a href=&quot;http://heroku.com&quot;&gt;Heroku&lt;/a&gt;, as the free tier of service is more than sufficient, and I can use my own domain name.&lt;/p&gt;

&lt;p&gt;The only question was how to get Heroku to serve the Jekyll blog properly?&lt;/p&gt;

&lt;p&gt;Enter &lt;a href=&quot;http://github.com/bry4n/rack-jekyll&quot;&gt;Rack-Jekyll&lt;/a&gt;. By depending on the rack-jekyll gem and adding a config.ru for Rack awareness the transition was smooth and painless. The only steps involved were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add &lt;code&gt;rack-jekyll&lt;/code&gt; to the .gemfile&lt;/li&gt;

&lt;li&gt;Add a config.ru as described in the &lt;a href=&quot;http://github.com/bry4n/rack-jekyll&quot;&gt;rack-jekyll page&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Make sure the &lt;code&gt;_site&lt;/code&gt; directory is checked into git&lt;/li&gt;

&lt;li&gt;Create a new heroku app and add my custom domain name&lt;/li&gt;

&lt;li&gt;Update DNS to point to Heroku&lt;/li&gt;

&lt;li&gt;Push to Heroku&lt;/li&gt;
&lt;/ul&gt;</description>
                <link>http://datamangling.com/2010/07/14/jekyll-on-heroku</link>
                <guid>http://datamangling.com/2010/07/14/jekyll-on-heroku</guid>
                <pubDate>2010-07-14T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Notes on Trying to Develop for Symbian</title>
                <description>&lt;p&gt;Aaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrgggggggggghhhhhhhhh.&lt;/p&gt;</description>
                <link>http://datamangling.com/2010/07/13/symbian-development</link>
                <guid>http://datamangling.com/2010/07/13/symbian-development</guid>
                <pubDate>2010-07-13T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Cascalog Lightning Talk at HUGUK</title>
                <description>&lt;p&gt;The 4th &lt;a href=&quot;http://huguk.org/&quot;&gt;Hadoop Users Group UK&lt;/a&gt; meetup took place last night at the &lt;a href=&quot;http://skillsmatter.com/go/find-us&quot;&gt;Skillsmatter Exchange&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Aaron Kimball of &lt;a href=&quot;www.cloudera.com&quot;&gt;Cloudera&lt;/a&gt; talked about &lt;a href=&quot;http://www.cloudera.com/developers/downloads/sqoop/&quot;&gt;Sqoop&lt;/a&gt;, and Tim Sell of &lt;a href=&quot;http://last.fm&quot;&gt;Last.fm&lt;/a&gt; talked about how they use Hive. Ben “Shevek” Mankin of Karmasphere gave a Lightning talk introducing &lt;a href=&quot;http://www.karmasphere.com/products/&quot;&gt;Karmasphere Studio&lt;/a&gt; which looks great, and then I gave a quick overview of &lt;a href=&quot;http://nathanmarz.com/blog/introducing-cascalog/&quot;&gt;Cascalog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I think the combination of two unfamiliar technologies (Clojure and Datalog) was probably a bit much for most people, but it was good to be able to talk about something new.&lt;/p&gt;
&lt;div id=&#39;__ss_4408253&#39; style=&#39;width:425px&#39;&gt;
  &lt;strong style=&#39;display:block;margin:12px 0 4px&#39;&gt;
    &lt;a href=&#39;http://www.slideshare.net/gheavyside/huguk-4-cascalog&#39; title=&#39;HUGUK #4 - Cascalog&#39;&gt;HUGUK #4 - Cascalog&lt;/a&gt;
  &lt;/strong&gt;
  &lt;iframe frameborder=&#39;0&#39; height=&#39;355&#39; marginheight=&#39;0&#39; marginwidth=&#39;0&#39; scrolling=&#39;no&#39; src=&#39;http://www.slideshare.net/slideshow/embed_code/4408253?rel=0&#39; width=&#39;425&#39;&gt; &lt;/iframe&gt;
  &lt;div style=&#39;padding:5px 0 12px&#39;&gt; View more &lt;a href=&#39;http://www.slideshare.net/&#39;&gt;presentations&lt;/a&gt; from &lt;a href=&#39;http://www.slideshare.net/gheavyside&#39;&gt;Gavin Heavyside&lt;/a&gt; &lt;/div&gt;
&lt;/div&gt;</description>
                <link>http://datamangling.com/2010/06/03/cascalog-at-huguk</link>
                <guid>http://datamangling.com/2010/06/03/cascalog-at-huguk</guid>
                <pubDate>2010-06-03T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>ACCU 2010 session - Introduction to Hadoop</title>
                <description>&lt;p&gt;At the &lt;a href=&quot;http://accu.org/index.php/conferences/accu_conference_2010&quot;&gt;ACCU2010 Conference&lt;/a&gt; in April I presented a short session introducing MapReduce and Apache Hadoop, into which I crammed HDFS, MapReduce, Hadoop Streaming, Pig and Hive. Slides are available on slideshare:&lt;/p&gt;
&lt;div id=&#39;__ss_3743127&#39; style=&#39;width:425px&#39;&gt;
  &lt;strong style=&#39;display:block;margin:12px 0 4px&#39;&gt;
    &lt;a href=&#39;http://www.slideshare.net/gheavyside/introduction-to-hadoop-accu2010&#39; title=&#39;Introduction to Hadoop - ACCU2010&#39;&gt;Introduction to Hadoop - ACCU2010&lt;/a&gt;
  &lt;/strong&gt;
  &lt;iframe allowfullscreen=&#39;&#39; frameborder=&#39;0&#39; height=&#39;355&#39; marginheight=&#39;0&#39; marginwidth=&#39;0&#39; mozallowfullscreen=&#39;&#39; scrolling=&#39;no&#39; src=&#39;http://www.slideshare.net/slideshow/embed_code/3743127?rel=0&#39; style=&#39;border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px&#39; webkitallowfullscreen=&#39;&#39; width=&#39;425&#39;&gt; &lt;/iframe&gt;
  &lt;div style=&#39;padding:5px 0 12px&#39;&gt; View more &lt;a href=&#39;http://www.slideshare.net/&#39;&gt;presentations&lt;/a&gt; from &lt;a href=&#39;http://www.slideshare.net/gheavyside&#39;&gt;Gavin Heavyside&lt;/a&gt; &lt;/div&gt;
&lt;/div&gt;</description>
                <link>http://datamangling.com/presentations/2010/05/28/intro-to-hadoop-accu2010</link>
                <guid>http://datamangling.com/presentations/2010/05/28/intro-to-hadoop-accu2010</guid>
                <pubDate>2010-05-28T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>GeoTools Quickstart example in Clojure</title>
                <description>&lt;p&gt;As part of my &lt;a href=&quot;http://clojure.org&quot;&gt;Clojure&lt;/a&gt; experiments I’m taking a look at &lt;a href=&quot;http://geotools.org&quot;&gt;GeoTools&lt;/a&gt; and the &lt;a href=&quot;http://tsusiatsoftware.net/jts/main.html&quot;&gt;Java Topologya Suite&lt;/a&gt; for working with geospatial data.&lt;/p&gt;

&lt;p&gt;Clojure has been described as “A better Java than Java”. I’m not a Java programmer, but having access to Java libraries in Clojure is very useful, and Clojure has made the interop remarkably painless so far.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;http://www.geotools.org/quickstart.html#quickstart&quot;&gt;quickstart example&lt;/a&gt; on the GeoTools documentation pages starts with a &lt;a href=&quot;http://www.geotools.org/quickstart.html#depending-on-geotools&quot;&gt;horrid Maven incantation&lt;/a&gt; which I converted to a &lt;a href=&quot;http://github.com/technomancy/leiningen&quot;&gt;leiningen&lt;/a&gt; project file. The &lt;a href=&quot;http://svn.osgeo.org/geotools/tags/2.6.4/demo/example/src/main/java/org/geotools/demo/Quickstart.java&quot;&gt;source itself&lt;/a&gt; once converted to Clojure looks like this:&lt;/p&gt;
&lt;script src=&#39;https://gist.github.com/415029.js&#39;&gt;&lt;![CDATA[ ]]&gt;&lt;/script&gt;
&lt;p&gt;And the leiningen project.clj:&lt;/p&gt;
&lt;script src=&#39;https://gist.github.com/415031.js&#39;&gt;&lt;![CDATA[ ]]&gt;&lt;/script&gt;
&lt;p&gt;Running either of the functions pops up a dialog box for you to choose a shapefile, which is then loaded and displayed.&lt;/p&gt;

&lt;p&gt;The clojure version is shorter than the Java version, can be tinkered with at the REPL, and doesn’t use any Maven.&lt;/p&gt;</description>
                <link>http://datamangling.com/2010/05/26/geotools-quickstart-in-clojure</link>
                <guid>http://datamangling.com/2010/05/26/geotools-quickstart-in-clojure</guid>
                <pubDate>2010-05-26T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>It's Good to be Lazy</title>
                <description>&lt;p&gt;On 14th May 2010 the inaugural meeting of the &lt;a href=&quot;http://softwarecraftsmanship.co.uk&quot;&gt;Software Craftsmanship UK user group&lt;/a&gt; was held at the offices of &lt;a href=&quot;http://edendevelopment.co.uk&quot;&gt;Eden Development&lt;/a&gt; in Winchester.&lt;/p&gt;

&lt;p&gt;The meeting kicked off with introductions, and then &lt;a href=&quot;http://twitter.com/ecomba&quot;&gt;Enrique&lt;/a&gt; called Doug Bradbury and Micah Martin of &lt;a href=&quot;http://8thlight.com&quot;&gt;8th Light&lt;/a&gt; on Skype, and they talked to us about the history of the Software Craftsmanship movement.&lt;/p&gt;

&lt;p&gt;After lightning talks, we moved on to a randori-style &lt;a href=&quot;http://codingdojo.org/cgi-bin/wiki.pl?RandoriKata&quot;&gt;coding dojo&lt;/a&gt; in which the task was to write an algorithm to determine how many &lt;a href=&quot;http://en.wikipedia.org/wiki/Lychrel_number&quot;&gt;Lychrel numbers&lt;/a&gt; there are in the starting range 1-10000.&lt;/p&gt;

&lt;p&gt;We used Ruby, which was known by the majority (but not all) of the attendees, and after a few false moves a recursive algorithm took shape and an answer was found. The program could have used a bit of refactoring, but it satisfied the task.&lt;/p&gt;

&lt;p&gt;I’m currently very enthusiastic about &lt;a href=&quot;http://clojure.org&quot;&gt;Clojure&lt;/a&gt;, partly because I’ve been meaning to learn a functional language for ages and this looks like a good one, and partly because it runs on the JVM and has some &lt;a href=&quot;http://github.com/nathanmarz/cascalog&quot;&gt;interesting&lt;/a&gt; &lt;a href=&quot;http://github.com/liebke/incanter&quot;&gt;libraries&lt;/a&gt; that I want to use with Hadoop for processing and analysing big data sets at &lt;a href=&quot;http://www.journeydynamics.com&quot;&gt;Journey Dynamics&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The next day I knocked up a &lt;a href=&quot;http://github.com/gavinheavyside/lychrels/blob/16e0d357a7b0a32115dfecafcd3b545af07766d2/src/lychrels/core.clj&quot;&gt;Clojure solution&lt;/a&gt; to the problem we’d seen in the dojo. It was concise, tested, and I was fairly pleased with it. I tweeted about it, and was about to forget about it until &lt;a href=&quot;http://twitter.com/t_crayford&quot;&gt;@t_crayford&lt;/a&gt; said that he could do better. Before long he’d posted an improved version of the main function:&lt;/p&gt;
&lt;script src=&#39;https://gist.github.com/402335.js&#39;&gt;&lt;![CDATA[ ]]&gt;&lt;/script&gt;
&lt;p&gt;At first I was baffled, but that was mostly down to trying to read it on my iPhone after a couple of glasses of wine. With a clear head and a big screen the next day it became obvious how he had replaced my naive recursive algorithm with a much more idiomatic lazy sequence version that has better performance.&lt;/p&gt;

&lt;p&gt;He defines a function that calculates the next number in the sequence, and creates a (infinite) lazy sequence of them using &lt;code&gt;iterate&lt;/code&gt;. It takes 50 numbers from this sequence using &lt;code&gt;rest&lt;/code&gt; and &lt;code&gt;take&lt;/code&gt; and checks to see if any of them are palindromic using &lt;code&gt;some&lt;/code&gt;. I was initially confused by the &lt;code&gt;-&amp;gt;&amp;gt;&lt;/code&gt; macro, but it is explained &lt;a href=&quot;http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/-%3E%3E&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It’s going to take me a while to think naturally in Clojure idioms, but I think it will be worth it. Paul Graham argues that &lt;a href=&quot;http://www.paulgraham.com/avg.html&quot;&gt;the truly serious hacker should consider learning Lisp&lt;/a&gt;, and I think he is absolutely right. The advantage of being able to think about solutions to problems in a different way from the dominant procedural and OO mindset can be really valuable, and I agree that even if you don’t subsequently use Lisp, having learned it will make you a better programmer.&lt;/p&gt;</description>
                <link>http://datamangling.com/2010/05/19/its-good-to-be-lazy</link>
                <guid>http://datamangling.com/2010/05/19/its-good-to-be-lazy</guid>
                <pubDate>2010-05-19T00:00:00-07:00</pubDate>
        </item>


</channel>
</rss>
