<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Plasmic Peach: Tag programming</title>
    <link>http://plasmicpeach.com/articles/tag/programming?tag=programming</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The Momo Web Blog</description>
    <item>
      <title>UK Geocoding with Google and Graticule</title>
      <description>&lt;p&gt;At long last, there&amp;#8217;s a good, free geocoding service for the UK.  Finding coordinates based on post code and/or address data has long been a free service in many countries.  But in the UK, the Royal Mail&amp;#8217;s control of post code data &amp;#8211; coupled with the ever-changing nature of that data &amp;#8211; has meant geocoding has been difficult or expensive.  Services like Postcode Anywhere and iShareMaps have provided equivalents to Google&amp;#8217;s geocoder, but for a fee.  That changed in early July 2007, when Google released geocoding for the UK.&lt;/p&gt;&lt;p&gt;If you&amp;#8217;re a Ruby programmer and you&amp;#8217;ve been doing geocoding, it&amp;#8217;s possible you&amp;#8217;ve been using a gem called Graticule.  This gem makes light work of plugging into various geocoding services and performing distance calculations.&lt;/p&gt;


	&lt;p&gt;Graticule includes a couple of classes for UK geocoding, one based on Postcode Anywhere and one based on Local Search Maps.  The first requires a Postcode Anywhere account, which is not free.  The second is free, but in my experience, not very reliable.&lt;/p&gt;


	&lt;p&gt;Neither matter anymore, though, since you can now just use the Google geocoder.  This post explains how to use Graticule to take advantage of Google&amp;#8217;s new UK geocoding service.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m assuming you have a Google Maps &lt;span class="caps"&gt;API&lt;/span&gt; key, and that you have the Graticule gem installed.  (If you don&amp;#8217;t have Graticule, it&amp;#8217;s just &amp;#8220;gem install graticule&amp;#8221;.)&lt;/p&gt;


	&lt;p&gt;In the simplest case, using the UK geocoding service is easy right out of the box.  Just pass the address data to the standard Graticule Google service, and you&amp;#8217;re there:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;require 'rubygems'
require 'graticule'

&amp;gt; g = Graticule.service(:google).new GMAP_API_KEY
#=&amp;gt; #&amp;lt;Graticule::Geocoder::Google:0xb73959f0 @key=&amp;quot;xxxxxxxxxx&amp;quot;,
@url=#&amp;lt;URI::HTTP:0xfdb9cabfe URL:http://maps.google.com/maps/geo&amp;gt;&amp;gt;

&amp;gt; g.locate &amp;quot;NW1 8BX&amp;quot;
#=&amp;gt; #&amp;lt;Graticule::Location:0xb7367064 @longitude=-0.145855,
@region=&amp;quot;England&amp;quot;, @precision=:zip, @latitude=51.542272,
@locality=&amp;quot;London&amp;quot;, @country=&amp;quot;GB&amp;quot;, @street=nil, @postal_code=&amp;quot;NW1 8BX&amp;quot;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;As you can see, the service correctly found the location in the UK.&lt;/p&gt;


	&lt;p&gt;But sometimes you don&amp;#8217;t have such complete data.  You might be using a partial post code, or a street address and no post code.  In those cases, the service might find a location in the wrong country&amp;#8212;the US, Canada, or Australia, for instance.&lt;/p&gt;


	&lt;p&gt;The easiest way to avoid that problem is to use the UK-specific geocoding service &lt;span class="caps"&gt;URL&lt;/span&gt;.  Graticule&amp;#8217;s Google geocoding class sets its &lt;span class="caps"&gt;URL&lt;/span&gt; to maps.google.com/maps/geo.  What we want is maps.google.co.uk/maps/geo.&lt;/p&gt;


	&lt;p&gt;When you call the method Graticule.service, it returns a geocoder class based on the symbol argument you pass in.  If you pass in :google, it returns the Graticule::Geocoder::Google class.  You could just as easily call Graticule::Geocoder::Google.new.  In either case, the way to get a UK-oriented geocoder is to make a new class that inherits from Graticule::Geocoder::Google, since the UK geocoding service is identical to the international one with the exception of the &lt;span class="caps"&gt;URL&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;In fact, the only method you need to write in the new class is the initialize method, which sets the &lt;span class="caps"&gt;URL&lt;/span&gt;.  Below is the code for the new class.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;graticule&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;Graticule&lt;/span&gt;
  &lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;Geocoder&lt;/span&gt;
    &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;GoogleUk&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;Graticule&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Geocoder&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Google&lt;/span&gt;
      &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;initialize&lt;/span&gt;&lt;span class="punct"&gt;(*&lt;/span&gt;&lt;span class="ident"&gt;args&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
        &lt;span class="keyword"&gt;super&lt;/span&gt;
        &lt;span class="attribute"&gt;@url&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;URI&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;parse&lt;/span&gt;&lt;span class="punct"&gt;(&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;http://maps.google.co.uk/maps/geo&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;)&lt;/span&gt;
      &lt;span class="keyword"&gt;end&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Put this code in the file &amp;#8220;google_uk.rb&amp;#8221;, in the directory graticule/geocoder somewhere in Ruby&amp;#8217;s include path.  For instance, if you&amp;#8217;re using Rails, you can put it in lib/graticule/geocoder.&lt;/p&gt;


	&lt;p&gt;Now you should be able to use the new UK-oriented geocoder as follows:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; g = Graticule.service(:google_uk).new GMAP_API_KEY
#=&amp;gt; #&amp;lt;Graticule::Geocoder::GoogleUk:0xb734bcb0 @key=&amp;quot;xxxxxxxxxx&amp;quot;,
@url=#&amp;lt;URI::HTTP:0xfdb9a4b3e URL:http://maps.google.co.uk/maps/geo&amp;gt;&amp;gt;

&amp;gt; g.locate &amp;quot;NW1 8BX&amp;quot;
#=&amp;gt; #&amp;lt;Graticule::Location:0xb7367064 @longitude=-0.145855,
@region=&amp;quot;England&amp;quot;, @precision=:zip, @latitude=51.542272,
@locality=&amp;quot;London&amp;quot;, @country=&amp;quot;GB&amp;quot;, @street=nil, @postal_code=&amp;quot;NW1 8BX&amp;quot;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;The UK geocoder works best if you pass it a string containing a complete postcode, or a street address (no apartment number or anything else) plus a partial post code.  Eg, &amp;#8220;AB1 3CD&amp;#8221;, or &amp;#8220;10 Whatever Street, &lt;span class="caps"&gt;AB1&lt;/span&gt;&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;A good way to learn more about the Graticule gem is to explore the &lt;a href="http://rdoc.momoweb.co.uk/graticule"&gt;RDoc documentation&lt;/a&gt; and visit the &lt;a href="http://graticule.com"&gt;Graticule web site&lt;/a&gt;.&lt;/p&gt;</description>
      <pubDate>Wed, 12 Sep 2007 16:15:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:8186bf85-754f-494c-871b-df50456a8f12</guid>
      <author>Momo</author>
      <link>http://plasmicpeach.com/articles/2007/09/12/uk-geocoding-with-google-and-graticule</link>
      <category>programming</category>
      <category>Ruby</category>
    </item>
    <item>
      <title>Ruby is better than PHP</title>
      <description>&lt;p&gt;Lots of web developers use &lt;span class="caps"&gt;PHP&lt;/span&gt;.  It&amp;#8217;s an open source programming language and one of the most popular for making web sites.  We don&amp;#8217;t use it, though.  We use Ruby.&lt;/p&gt;


	&lt;p&gt;This is not an arbitrary choice, like preferring purple to green.  We use Ruby because it&amp;#8217;s better.  That&amp;#8217;s what we tell our clients when they ask why we use Ruby.  The next question is usually, &amp;#8220;What makes it better?&amp;#8221;&lt;/p&gt;&lt;p&gt;It&amp;#8217;s pretty hard to answer that question directly, because the reasons are all highly technical.  Instead, we say something such as, &amp;#8220;Ruby is like well-crafted writing.&amp;#8221;  Or, &amp;#8220;It&amp;#8217;s just better designed.&amp;#8221;  Both of them are true.  But how do you know we&amp;#8217;re right, and not just expressing our opinion?  Mightn&amp;#8217;t other people think that &lt;span class="caps"&gt;PHP&lt;/span&gt; is a better language than Ruby?&lt;/p&gt;


	&lt;p&gt;Actually, probably not.  What you&amp;#8217;ll find is that people who&amp;#8217;ve learned Ruby and also &lt;span class="caps"&gt;PHP&lt;/span&gt; nearly all think Ruby is better.  People who know &lt;span class="caps"&gt;PHP&lt;/span&gt; but not Ruby, or &lt;span class="caps"&gt;PHP&lt;/span&gt; and a little Ruby, might tell you that the two languages are equivalent.&lt;/p&gt;


	&lt;p&gt;When talking about any two programming languages used for the same purpose &amp;#8211; call them X and Y &amp;#8211; you&amp;#8217;ll find one of two things. 1: everyone will agree that X and Y are equivalent; or, 2: some people will say X is better than Y, and some people will say X and Y are equivalent.&lt;/p&gt;


	&lt;p&gt;What you almost never find is some people saying &amp;#8220;X is better than Y&amp;#8221;, and some saying &amp;#8220;Y is better than X&amp;#8221;.  Why not?  The reason is that X &lt;em&gt;really is&lt;/em&gt; better than Y &amp;#8211; it&amp;#8217;s a fact &amp;#8211; but you have to know how to program in X pretty well before you realise it.&lt;/p&gt;


	&lt;p&gt;The people who say X and Y are equivalent are Y programmers who can&amp;#8217;t understand the more advanced features of X.  To them, X just looks like another version of Y, with a bunch of other random stuff tacked on.  They don&amp;#8217;t say &amp;#8220;Y is better than X&amp;#8221;, because they can at least see that X can do everything Y can do.  What they can&amp;#8217;t see is what X can do that their language can&amp;#8217;t.&lt;/p&gt;


	&lt;p&gt;So if you find experienced Ruby programmers saying &amp;#8220;Ruby is better than &lt;span class="caps"&gt;PHP&lt;/span&gt;&amp;#8221;, and &lt;span class="caps"&gt;PHP&lt;/span&gt; programmers saying &amp;#8220;Ruby and &lt;span class="caps"&gt;PHP&lt;/span&gt; are equivalent&amp;#8221;, believe the Ruby guys.&lt;/p&gt;</description>
      <pubDate>Sun, 09 Sep 2007 10:18:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c0bcb47b-0087-48a1-849b-ba9b0c846008</guid>
      <author>Momo</author>
      <link>http://plasmicpeach.com/articles/2007/09/09/ruby-is-better-than-php</link>
      <category>programming</category>
      <category>Ruby</category>
    </item>
    <item>
      <title>Drawing and Programming</title>
      <description>&lt;p&gt;Even though one fairly well-known &lt;a href="http://paulgraham.com/hp.html"&gt;programmer&lt;/a&gt; has already pointed out the similarities between programming and art, most people, I would say, still do not appreciate how similar they are.&lt;/p&gt;


	&lt;p&gt;One thing that struck me recently is how good programmers and good drawers approach their work &amp;#8211; and how they differ from the inexperienced.  In both fields, people who are skilled know where to begin.&lt;/p&gt;&lt;p&gt;Inexperienced drawers tend to approach the task pretty randomly.  Let&amp;#8217;s say they want to draw a picture of a cat.  They&amp;#8217;ll get a piece of paper, a pencil, and maybe even a cat to look at, and off they go drawing.  Maybe they&amp;#8217;ll start with an ear or an eye, or even the tail.  And they&amp;#8217;ll progress from that point, filling in a lot of detail as they go.  They&amp;#8217;ll probably erase a lot of mistakes.  Soon enough they look at their eraser-smudged picture and say, &amp;#8220;It&amp;#8217;s coming out all wrong.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;Their cat doesn&amp;#8217;t look like a cat.  Its ears are too big.  Its feet are way too small for its body.  Its tail is going off the page.  And there isn&amp;#8217;t any room left for the sofa that the cat&amp;#8217;s meant to be sitting on.&lt;/p&gt;


	&lt;p&gt;Experienced artists do it differently.  They start with the most basic shapes in rough, sketchy form, making sure they&amp;#8217;ve got the perspective and proportions right and that the object is positioned correctly on the page.  They&amp;#8217;ve studied art, so they know something about animal anatomy and perspective.  And they start filling in detail only when they&amp;#8217;re happy with the basic form.  When they&amp;#8217;re done, the picture is balanced, everything fits, and the eye is drawn to the right details.&lt;/p&gt;


	&lt;p&gt;I think there&amp;#8217;s a similar pattern at work in programming.  People new to programming often start in the wrong place &amp;#8211; with a trivial feature that seems cool, say.  And they fill in too much detail too early, before they&amp;#8217;ve even written the application&amp;#8217;s core engine.  Before they know it, they&amp;#8217;ve programmed themselves into a corner &amp;#8211; they realise that the architecture&amp;#8217;s wrong, or that the way they implemented those features depends on too much repetition of code.&lt;/p&gt;


	&lt;p&gt;Programmers with more experience tackle the core of the application first and keep a close eye on how they will reuse the components they write.  They make mistakes, but they sort out the critical ones before they&amp;#8217;ve written much, so making changes is relatively easy.  It&amp;#8217;s also easier to &lt;em&gt;see&lt;/em&gt; mistakes when there&amp;#8217;s not much code &amp;#8211; the core architecture of an application is much easier to understand when it&amp;#8217;s not very detailed yet.&lt;/p&gt;


	&lt;p&gt;One mistake that intermediate programmers can make is to assume that planning guarantees success.  It doesn&amp;#8217;t.  For one thing, plans are usually wrong, sometimes in minor ways, sometimes in major ways.  So it&amp;#8217;s still important to be able to change the actual code early, and for the early code to represent the core of the application, not trivial high-level features.&lt;/p&gt;


	&lt;p&gt;In both art and programming, there is an amount of theory that is extremely helpful for producing good work.  I think the importance of theory &amp;#8211; or &amp;#8220;science&amp;#8221; &amp;#8211; in art is greatly underappreciated.  But in both fields, practice is the vital ingredient that leads to an instinctive understanding of where to begin.&lt;/p&gt;</description>
      <pubDate>Sun, 17 Dec 2006 00:41:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:1642e294-f871-4d24-8b2f-25073f68a6fd</guid>
      <author>Momo</author>
      <link>http://plasmicpeach.com/articles/2006/12/17/drawing-and-programming</link>
      <category>programming</category>
    </item>
  </channel>
</rss>
