Wednesday, February 25, 2009

Heres to you Mrs Watanabe

The last few days have been quite busy with starting a new job and the arrival of my first child, so I've been running a bit behind schedule writing wise.

One of the articles I've finally got round to reading was the FT "Hunting Mrs Watanabe" a lovely piece on Japan's housewife speculators. I'm intrigued as to whether there could be a "Mrs Smith" in the UK, and how far are we from a Sterling Carry Trade...

Hopefully I'll be able to write a bit more often again now that things are settling down.

Wednesday, February 11, 2009

Merv Focuses on quantitative easing

Merv, or Mervyn King to those who don't know him well is the main man at the Bank of England. His job is to make sure that inflation is kept under control, and a bit of financial stability as well.

Here is a lovely picture used by the FT in their article "Bank set to deploy quantitative easing":
[copyright bloomberg.com, 2008]

I like to think that it would have been titled "Merv Focuses on printing money" by The Sun (a tabloid/racy sports/babes/gossip newspaper).

Of course "printing money" is not quantitative easing, but then again we don't have any useful terminology for this complex concept so all the newspapers and TV programs keep using "printing money". For some reason it's better to give it a name that seems simple but is completely wrong, rather than explaining what quantitative easing is.

And a little side note [pun intended] is that the Bank of England does not print money.. they outsourced that ages ago ;-)

Friday, February 6, 2009

Enumerable character ranges

I was reading Eric Lippert's Blog entry A nasality talisman for the sultana analyst where he was writing some code to help in playing scrabble like games. And I saw a piece of code that I had written myself before and I thought, there must be a better way....

The code:
    foreach (char c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    {
        // do stuff
    }
what did I not like about the code? the literal ABCDEFGHIJKLMNOPQRSTUVWXYZ, it's too easy to type this in wrong - so I thought I could improve this using the Range function of Enumerable which allows you to write:
    foreach (int i in Enumerable.Range(1, 10))
    {
        // do stuff
    }
neat! but wait a second, the Range function only accepts int as the data type - hmm, so I came up with:
    foreach (int i in
        Enumerable.Range('a', 'z' - 'a' + 1).Select(charCode => (char)charCode))
    {
        // do stuff
    }
way to go! apart from the code being even longer than it was before, and not exactly the sort of code the drips of your finger-tips.

I then found Using LinqPad to Create a Time-Selector Drop-Down List, and the implementation of a "To" extension method:
public static IEnumerable To(this int first, int last) {
  return Enumerable.Range(first, last - first + 1);
}

(Note: on Richard Bushnell's blog I found www.extensionmethod.net a repository of .Net Extension Methods).

I took Richard's implementation and combined it with mine to create a "To" method for characters:
  public static IEnumerable<char> To(this char first, char last)
  {
   var result = Enumerable.Range(first, last - first + 1).Select(charCode => (char)charCode);

   return result;
  }

Which allows you to write:
    foreach (char c in 'A'.To('Z'))
    {
        // do stuff
    }
 // vs.
    foreach (char c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    {
        // do stuff
    }
And finally, I changed the "To" method to cope with ranges in reverse order:
 public static class EnumerableExtensions
 {
  private static void Swap(ref char a, ref char b)
  {
   var temp = a;
   a = b;
   b = temp;
   // swap code updated to reflect eric's comments
   // http://blogs.msdn.com/ericlippert/archive/2009/02/04/a-nasality-talisman-for-the-sultana-analyst.aspx#comments
  }

  public static IEnumerable<char> To(this char first, char last)
  {
   bool reverseRequired = (first > last);

   if (reverseRequired)
    Swap(ref first, ref last);

   var result = Enumerable.Range(first, last - first + 1).Select(charCode => (char)charCode);

   if (reverseRequired)
    result = result.Reverse();

   return result;
  }
 }
Which allows you to write:
    foreach (char c in 'a'.To('z'))
        Console.WriteLine(c);
    foreach (char c in 'A'.To('Z'))
        Console.WriteLine(c);
    foreach (char c in 'z'.To('a'))
        Console.WriteLine(c);
    foreach (char c in '0'.To('9'))
        Console.WriteLine(c);

Thursday, February 5, 2009

Mona Lisa Overdrive

I like this demonstration of the the elegance that can be created through an evolutionary approaches, very fitting in a Darwinian 200 year celebration.

Genetic Programming: Evolution of Mona Lisa

And of course the combination of evolution, AI and Mona Lisa segues nicely into Mona Lisa Overdrive

Tuesday, February 3, 2009

Terms of Service for Web Mapping providers

Interesting article on Terms of Service for Web Mapping providers and the dangers of clicking "I Agree" without actually reading the terms (apparently 50% don't read before agreeing)

Nice coverage of what people are signing up for when they use the various services and a bit of light shed on the Ordnance Survey "Show us a better way" fiasco.

Reminds of the Copyright article on uncyclopedia

though they do recommend reading the Wikipedia (a dangerous parody of Uncyclopedia):