<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Occasionally sane</title>
	<atom:link href="http://gnuvince.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://gnuvince.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sun, 22 Jan 2012 03:27:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='gnuvince.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Occasionally sane</title>
		<link>http://gnuvince.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://gnuvince.wordpress.com/osd.xml" title="Occasionally sane" />
	<atom:link rel='hub' href='http://gnuvince.wordpress.com/?pushpress=hub'/>
		<item>
		<title>PyPy&#8217;s performances impress me</title>
		<link>http://gnuvince.wordpress.com/2011/10/19/pypys-performances-impress-me/</link>
		<comments>http://gnuvince.wordpress.com/2011/10/19/pypys-performances-impress-me/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 01:45:42 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=654</guid>
		<description><![CDATA[PyPy has been a project that I&#8217;ve heard about for a few years; a new implementation of the Python language. Because it was a young project and CPython worked for me, I never bothered to look at PyPy very closely. A couple weeks ago, I read a message that claimed that the performance of PyPy [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=654&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>PyPy has been a project that I&#8217;ve heard about for a few years; a new implementation of the Python language.  Because it was a young project and CPython worked for me, I never bothered to look at PyPy very closely.  A couple weeks ago, I read a message that claimed that the performance of PyPy for CPU-bounded tasks was impressive compared to CPython&#8217;s.</p>
<p>Last week in my algorithms class, we learned about greedy algorithm.  The first one we looked at was a program that made change.  You give it an amount and a set of coins and it returns the smallest number of coins for amount.  This is something we do every day without thinking about it.  For fun, I wrote an implementation of the algorithm in Python:</p>
<p><pre class="brush: python;">
from collections import defaultdict

def make_change1(amount, coins):
    total = 0
    solution = defaultdict(lambda: 0)
    current = 0

    while total != amount and current &lt; len(coins):
        if total + coins[current] &gt; amount:
            current += 1
        else:
            total += coins[current]
            solution[coins[current]] += 1

    return solution
</pre></p>
<p>Doing the change operation by successive subtraction is not terribly efficient, so I wrote another version that uses integer division instead:</p>
<p><pre class="brush: python;">
def make_change2(amount, coins):
    solution = {}
    for coin in coins:
        count = amount / coin
        solution[coin] = count
        amount -= coin*count
    return solution
</pre></p>
<p>And then I created a small script to test them with a lot of amounts, using Canadian coins:</p>
<p><pre class="brush: python;">
import sys

if sys.argv[1] == &quot;1&quot;:
    make_change = make_change1
    n = 100000
else:
    make_change = make_change2
    n = 10000000

for i in xrange(n):
    make_change(i, [200, 100, 25, 10, 5, 1])
</pre></p>
<p>Here are the times of running this script on my Linux laptop:</p>
<pre>
$ python2 --version
Python 2.7.2

$ time python2 make_change.py 1
real    0m16.236s
user    0m16.236s
sys     0m0.000s

$ time python2 make_change.py 2
real    0m28.638s
user    0m28.491s
sys     0m0.057s
</pre>
<p>And now with PyPy:</p>
<pre>
$ pypy --version
Python 2.7.1 (?, Sep 04 2011, 13:10:48)
[PyPy 1.6.0 with GCC 4.6.1]

$ time pypy make_change.py 1
real    0m2.185s
user    0m2.157s
sys     0m0.023s

$ time pypy make_change.py 2
real    0m8.799s
user    0m8.769s
sys     0m0.023s
</pre>
<p>Clearly this is just one silly, unscientific micro-benchmark, but I plan on trying to use PyPy more in the future to see if it generally performs better than CPython.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/654/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/654/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/654/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/654/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/654/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/654/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/654/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/654/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/654/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/654/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/654/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/654/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/654/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/654/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=654&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2011/10/19/pypys-performances-impress-me/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>
	</item>
		<item>
		<title>Text Untwist</title>
		<link>http://gnuvince.wordpress.com/2010/12/26/text-untwist/</link>
		<comments>http://gnuvince.wordpress.com/2010/12/26/text-untwist/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 02:44:54 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[programming java day9 text-twist]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=650</guid>
		<description><![CDATA[I recently saw a video of Day[9] playing a game called Text Twist. The objective of the game is to find as many words as possible with 6 or 7 given letters. You lose if you cannot find the word (or words) that use all the letters. Being a nerd and a hacker, I decided [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=650&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently saw a video of <a href="http://day9tv.blip.tv/">Day[9]</a> playing a game called Text Twist.  The objective of the game is to find as many words as possible with 6 or 7 given letters.  You lose if you cannot find the word (or words) that use all the letters.  Being a nerd and a hacker, I decided that I was going to make a little program to play in my stead.</p>
<p>That program is called <a href="https://github.com/gnuvince/TextUntwist">TextUntwist</a> and is available under the ISC License on GitHub.  Usage is very simple:</p>
<pre>
$ java net.gnuvince.textuntwist.TextUntwist &lt;dict&gt; &lt;letters&gt;
</pre>
<p>You&#8217;ll then have 3 seconds to switch to your game of TextTwist and the words will start being written in.  An English and French dictionary are available right now.; they differ from the dictionaries used by Text Twist on Yahoo, so they&#8217;ll not find every word.  You can add them to the dictionary yourself if you wish.  I&#8217;ve made a small video for your viewing pleasure.</p>
<span style="text-align:center; display: block;"><a href="http://gnuvince.wordpress.com/2010/12/26/text-untwist/"><img src="http://img.youtube.com/vi/EhRkmqTUqO8/2.jpg" alt="" /></a></span>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/650/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=650&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2010/12/26/text-untwist/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>
	</item>
		<item>
		<title>Cycling with closures</title>
		<link>http://gnuvince.wordpress.com/2010/11/28/cycling-with-closures/</link>
		<comments>http://gnuvince.wordpress.com/2010/11/28/cycling-with-closures/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 23:05:26 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[closures]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=647</guid>
		<description><![CDATA[There was a discussion on StackOverflow about useful alternative control structures.. One member mentioned that he would like to have an alternate control structure that would cycle through a list of possibilities. This structure is available already in some languages: Python has it in itertools.cycle and Haskell has the function cycle in its Prelude. But [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=647&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There was a discussion on StackOverflow about <a href="http://stackoverflow.com/questions/4293744/useful-alternative-control-structures">useful alternative control structures.</a>.  One member mentioned that he would like to have an <i>alternate</i> control structure that would cycle through a list of possibilities.</p>
<p>This structure is available already in some languages: Python has it in <tt>itertools.cycle</tt> and Haskell has the function <tt>cycle</tt> in its Prelude.</p>
<p>But if you don&#8217;t use Python or Haskell, but your language does have closures, you can implement it yourself.  Here&#8217;s how in JavaScript.</p>
<pre>
function cycle(choices) {
    var i = 0;
    return function () {
        var current = i;
        i = (i + 1) % choices.length;
        return choices[current];
    };
}
</pre>
<p>Simple, isn&#8217;t it?  Here&#8217;s a brief explanation of how it works.  Inside the body of <tt>cycle</tt>, there are two local variables, <tt>i</tt> and <tt>choices</tt>.  They are also available to the anonymous function that&#8217;s returned by the function, but the interesting thing is that although <tt>i</tt> and <tt>choices</tt> fall out of scope when <tt>cycle</tt> returns, the anonymous function still has a reference to them and can access and modify them as it needs to.  When the anonymous function is called, it returns the current element from <tt>choices</tt> and moves <tt>i</tt> to &#8220;point&#8221; to the next element.</p>
<p>Here are some sample usages:</p>
<pre>
var colors = cycle(["blue", "white", "red"]); // colors is a function

for (var i = 0; i &lt; 5; ++i) {
    console.log(colors());
}

// Output:
// bleu
// white
// red
// blue
// white

var salutations = cycles([
    function (s) { return &quot;Hello &quot; + s; },
    function (s) { return &quot;Good morning &quot; + s; },
    function (s) { return &quot;Hey &quot; + s; }
]);

for (var i = 0; i &lt; 3; ++i) {
    console.log(salutations()(&quot;world&quot;));
}

// Output:
// Hello world
// Good morning world
// Hey world
</pre>
<p>If you are not familiar with closures and your favorite language supports them, I recommend that you find a tutorial (many are available online using JavaScript) to learn and appreciate their power.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/647/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=647&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2010/11/28/cycling-with-closures/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>
	</item>
		<item>
		<title>Turing Machine in Scala</title>
		<link>http://gnuvince.wordpress.com/2010/09/29/turing-machine-in-scala/</link>
		<comments>http://gnuvince.wordpress.com/2010/09/29/turing-machine-in-scala/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 03:23:25 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cs]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[turing]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=643</guid>
		<description><![CDATA[I am currently enrolled in a theoretical computer science class. Last week, we started learning about Turing machines. The professor wrote and made available a small Turing machine simulator that we can use to write and run simple programs. Unfortunately for the students using Linux or MacOS X, the program is written in C# and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=643&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://upload.wikimedia.org/wikipedia/en/thumb/a/a2/Turing_machine_2b.svg/200px-Turing_machine_2b.svg.png"></p>
<p>I am currently enrolled in a theoretical computer science class.  Last week, we started learning about Turing machines.  The professor wrote and made available a small Turing machine simulator that we can use to write and run simple programs.  Unfortunately for the students using Linux or MacOS X, the program is written in C# and runs only on Windows.</p>
<p>I decided to write my own little Turing machine simulator in Scala.  The code is short (~40 lines of code) and I felt like sharing it.</p>
<p>First a small introduction to Turing machines (as I understand them):</p>
<ul>
<li>The <b>controller</b> stores the current <i>state</i> that the machine is in.  It can hold only one state at a time.</li>
<li>The <b>tape</b> is an infinite array onto which we can write characters.</li>
<li>The <b>head</b> points to a character on the tape.</li>
<li>The head can move one position backward or forward (left or right).</li>
<li>When the program is loaded, the initial input is copied at the beginning of the tape.  The rest of the tape consists of blanks.</li>
<li>The <b>transition function</b> takes the current state and current character under the head and sets a new state, writes a new character on the tape and moves left or right.</li>
<li>The programs runs until the state is <i>ACCEPTED</i> or <i>REJECTED</i>.</li>
</ul>
<p>I may have forgotten some details, but that&#8217;s the gist of it.  Now let&#8217;s see how we implement a Turing Machine.</p>
<pre>
import scala.collection.mutable.Map
</pre>
<p>Right off the bat, we&#8217;re going to make the Haskell people cry in agony and use a <i>mutable</i> Map in our program.  We&#8217;ll see later what it&#8217;s used for.</p>
<pre>
object Direction extends Enumeration {
  val left = Value(-1)
  val right = Value(1)
}
</pre>
<p>We define an enumeration type that represents the two directions where the head can go.  We used the values -1 and 1 to make the actual move a simple addition.</p>
<pre>
class Tape(input: String) {
  private val tape: Array[Char] = Array.fill(65536)('_')
  private var head: Int = 0
  for (i &lt;- 0 until input.length) {
    tape(i) = input(i)
  }

  def getValue() = tape(head)
  def setValue(c: Char) = tape(head) = c
  def move(d: Direction.Value) = head += d.id
}
</pre>
<p>This is the class that represents the tape.  It has a private member called <i>tape</i> which is an array of 65,536 characters initialized to the underscore character (which will be our blank character).  It also has a private member called <i>head</i> which emulates the Turing machine&#8217;s head.  It&#8217;s just an integer value that indicates which is the &#8220;active cell&#8221; on the tape.  The constructor of Tape takes a string that is copied onto the tape.</p>
<p>The methods getValue() and setValue() respectively read the current character and write a new value onto the tape.  move() changes the position of head. <code>d.id</code> gives us the -1 or 1 value that we defined earlier in <i>Direction</i>.</p>
<pre>
class TuringMachine(private var input: String, private var state: String) {
  private val tape = new Tape(input)
  private val transition: Map[(String, Char), (String, Char, Direction.Value)] = Map()

  def addRule(tuple: ((String, Char), (String, Char, Direction.Value))) {
    transition(tuple._1) = tuple._2
  }

  def execute() {
    while (state != "ACCEPTED" &amp;&amp; state != "REJECTED") {
      val value = tape.getValue
      val (newState, newValue, direction) = transition((state, value))
      println(newState, newValue, direction)
      state = newState
      tape.setValue(newValue)
      tape.move(direction)
    }
    println(state)
  }
}
</pre>
<p>This is the main class that brings everything together.  A TuringMachine&#8217;s constructor receives an input to be written on the tape and an initial state.  A TuringMachine has a Map (dictionnary) from <code>(String, Char)</code> &#8212; a 2-tuple representing the current state and character &#8212; to <code>(String, Char, Direction.Value)</code>, a 3-tuple that contains the new state, new character and direction for the head.</p>
<p>addRule() is a simple function that adds an entry to the transition map.</p>
<p>execute() loops until the state is either &#8220;ACCEPTED&#8221; or &#8220;REJECTED&#8221;.  Inside the loop, we take the value on the tape and the state, find the transition rule associated with that pair, and update the state, the tape and the head.  We print every intermediary step.  When the loop is done, we print the final state.</p>
<p>And that&#8217;s it.  That&#8217;s our Turing machine.  Now, let&#8217;s write a small program for it:</p>
<pre>
object TuringMachine {
  def usage() {
    println("Usage: scala TuringMachine  ")
    exit(1)
  }

  def main(args: Array[String]) {
    if (args.length != 2)
      usage()

    val tm = new TuringMachine(args(0), args(1))
    tm.addRule(("even", '0') -&gt; ("even",     '0', Direction.right))
    tm.addRule(("even", '1') -&gt; ("odd",      '1', Direction.right))
    tm.addRule(("even", '_') -&gt; ("ACCEPTED", '_', Direction.right))
    tm.addRule(("odd",  '0') -&gt; ("odd",      '0', Direction.right))
    tm.addRule(("odd",  '1') -&gt; ("even",     '1', Direction.right))
    tm.addRule(("odd",  '_') -&gt; ("REJECTED", '_', Direction.right))

    tm.execute()
  }
}
</pre>
<p>This is a program that, given an input of ones and zeros, accepts the program if the number of ones is even and rejects the program otherwise.  Here&#8217;s a sample execution with the string &#8220;110101&#8243; and given an initial state of &#8220;even&#8221; (since 0 ones is even):</p>
<pre>
$ scala -cp . TuringMachine 110101 even
(odd,1,right)
(even,1,right)
(even,0,right)
(odd,1,right)
(odd,0,right)
(even,1,right)
(ACCEPTED,_,right)
ACCEPTED
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/643/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/643/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/643/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/643/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/643/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/643/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/643/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/643/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/643/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/643/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/643/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/643/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/643/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/643/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=643&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2010/09/29/turing-machine-in-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/en/thumb/a/a2/Turing_machine_2b.svg/200px-Turing_machine_2b.svg.png" medium="image" />
	</item>
		<item>
		<title>Edge cases in computer programs</title>
		<link>http://gnuvince.wordpress.com/2010/08/23/edge-cases-in-computer-programs/</link>
		<comments>http://gnuvince.wordpress.com/2010/08/23/edge-cases-in-computer-programs/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 18:41:29 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[poker]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=640</guid>
		<description><![CDATA[Introduction We programmers like when problems can be solved with a single, general formula and we generally dislike when we need to manually handle small edge cases. I want to talk about such an edge case that occurred in a little poker program I am writing. Order please! My poker program is a hand simulator: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=640&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>We programmers like when problems can be solved with a single, general formula and we generally dislike when we need to manually handle small edge cases.  I want to talk about such an edge case that occurred in a little poker program I am writing.</p>
<h3>Order please!</h3>
<p>My poker program is a hand simulator: given two starting hands, it&#8217;ll compute their probabilities of winning at showdown (this is going to be pretty much the same thing as PokerStove).  One of the thing I need to do in my program is determine what kind of hand a player has.  There are 9 different types of hands in poker.  Here they are in decreasing strength order:</p>
<ul>
<li>Straight flush</li>
<li>Four of a kind</li>
<li>Full house</li>
<li>Flush</li>
<li>Straight</li>
<li>Three of a kind</li>
<li>Two pairs</li>
<li>One pair</li>
<li>High card</li>
</ul>
<p>(Note: a royal flush is a kind of straight flush.)</p>
<p>Before a hand is properly classified, the cards are sorted to make the classification functions easier to code.  The cards are first ordered by the number of cards of the same rank that appear in the hand and in decreasing order of strength.  Here are some examples:</p>
<ul>
<li>5-5-5-T-T: The three fives come first because there&#8217;s three of them, then the tens</li>
<li>9-9-3-3-6: We have two pairs, so we put the highest one first, the second pair next and the lonely card last</li>
<li>A-8-7-4-3: There are no two cards of the same rank here, so the cards are simply ordered by rank</li>
</ul>
<p>The hand is then tested for all types of hands from strongest to weakest and the classification stops as soon as a match has been found.  For example, to test for four of a kind we verify that <tt>card[0] = card[1] = card[2] = card[3]</tt> and later we can test for two pairs with <tt>card[0] = card[1] and card[2] = card[3]</tt> without having to test that <tt>card[2]</tt> and <tt>card[3]</tt> are different from <tt>card[0]</tt> and <tt>card[1]</tt>.</p>
<p>This ordering also makes it easy to determine the winner when two hands have the same type: we just go from the first card to the last, testing which one is the higher card.  If after the fifth card no card was higher, we have a tie.  This works for all types of hands.  <i>Almost.</i></p>
<h3>Why did they invent the wheel?</h3>
<p>In poker terms, a wheel is a 5-high straight; the ace is considered both high and low, so A-2-3-4-5 is actually a straight.  And this hand, which occurs less than 1% of the time, is the one that requires the most attention.</p>
<p>First, it makes testing for a straight harder.  The function for testing a straight is easy with our ordering: starting at the second card, we test that the current card is exactly one rank lower than the card before.  This work from A-K-Q-J-T down to 6-5-4-3-2.  With a wheel however, we have A-5-4-3-2 and 5 is not one rank lower than an ace and a straight isn&#8217;t found.  If no straight was found, we need to manually check if the hand is a wheel.</p>
<p>Second, if we used a simple card-by-card analysis to determine which of two straights (or straight flushes) is the higher one, the wheel would actually lose only to broadway (A-K-Q-J-T); it would (incorrectly) win against a straight such as 7-6-5-4-3, because the ace is higher than the 7, even though a 7-high straight beats a 5-high straight.  To fix this problem, we must add extra code to our comparison function when we are dealing with straights and straight flushes:</p>
<ul>
<li>If the two hands are wheel, we have a tie</li>
<li>If the first hand is a wheel, then the second hand is the winner</li>
<li>If the second hand is a wheel, then the first hand is the winner</li>
</ul>
<p>If none of these tests pass, we can use our card-by-card analysis. (Hands that aren&#8217;t straights or straight flushes just skip this part, of course.)</p>
<p>The net result of the wheel is that my functions to test for straights and for comparing hands are twice as long as they would be if wheels were not considered straights.  The little less-than-1% case causes the code of two functions to increase by 100%.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/640/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=640&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2010/08/23/edge-cases-in-computer-programs/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>
	</item>
		<item>
		<title>My quick review of Winning Low Limit Hold &#8216;em, by Lee Jones</title>
		<link>http://gnuvince.wordpress.com/2009/10/18/my-quick-review-of-winning-low-limit-hold-em-by-lee-jones/</link>
		<comments>http://gnuvince.wordpress.com/2009/10/18/my-quick-review-of-winning-low-limit-hold-em-by-lee-jones/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 23:22:26 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[poker]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=636</guid>
		<description><![CDATA[When I started getting interested in poker a few weeks ago, I looked for a novice book that would teach me how to correctly play a hand. I read book reviews on Amazon and on poker sites, and one beginner&#8217;s book consistently received high praises, Lee Jones&#8217; Winning Low Limit Hold &#8216;Em (WLLH). I placed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=636&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://ecx.images-amazon.com/images/I/41W7YKGWDZL._SS500_.jpg"></p>
<p>When I started getting interested in poker a few weeks ago, I looked for a novice book that would teach me how to correctly play a hand.  I read book reviews on Amazon and on poker sites, and one beginner&#8217;s book consistently received high praises, Lee Jones&#8217; <a href="http://www.amazon.com/Winning-Low-Limit-Holdem-Lee-Jones/dp/1886070237/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1255903159&amp;sr=8-1"><i>Winning Low Limit Hold &#8216;Em</i></a> (WLLH).  I placed an order on Amazon, received it a few days later and immediately started reading it with the firm intention of thoroughly studying its content before moving on to a no limit book.</p>
<p>I finished reading the book a few days ago and I&#8217;m already reading it a second time!  The style of Lee Jones is very easygoing, it almost feels as if he&#8217;s sitting with us, telling us how to play.  The subject matter is presented in a very straight forward manner, building upon the things that were introduced in previous chapters.  I liked the footnotes where he says that a piece of advice differs from the earlier editions of the book; I like a person who can form new opinions and not be afraid to admit it.</p>
<p>The book is split in four sections: the basics of hold &#8216;em, playing a hand of hold &#8216;em from pre-flop to showdown, a discussion of sit and go tournaments and miscellaneous subjects.  By far, the most important sections are the first two.</p>
<p>The first section introduces the different factors that must be considered when it&#8217;s time to act (cards, position, number of opponents, money to invest, etc.), calculating outs, pot odds and implied odds.  I wish the math for outs and odds was more detailed, but for the beginners and the people who aren&#8217;t math-savvy, this short overview works pretty well, and I know that there are books where the math is more rigorous.</p>
<p>The second section, which I will need to be read many times, discusses how to play every stage of a hand.  This section starts with a chapters on playing pre-flop in early, middle and late position as well as in the blinds.  There are detailed explanations on which action to take when you are the first in the pot, when there are some limpers in front of you, when there is a raise in front of you, etc.  Each chapter ends with a small chart that summarizes the content of the chapter.  Those pages should be bookmarked.  There are a few chapters on post-flop play that discuss what the player should do when he flops two pairs, a set, a straight, when the hand misses, when there&#8217;s a flush draw, etc.  The important subject of position follows and this section finishes with chapters on how to play the turn and the river.</p>
<p>I quickly skimmed over the sit and go section, since that&#8217;s no limit hold &#8216;em and I really want to solidify my limit game before moving on.  The last section contains chapters which did not fit elsewhere: there&#8217;s a chapter on card room etiquette, a chapter on discipline, on folding, on bankroll management, Barry Tanenbaum&#8217;s ten common errors list, etc.  This is a nice heap of good advice.</p>
<p>I should mention one problem I have with this book: my copy is falling apart!  I don&#8217;t know if it&#8217;s cheaper binding or that I was too rough, but as soon as I sat down with it, I started writing notes in the margins, underlining important passages, marking pages with sticky bookmarks and putting post-it notes over notions that I wanted to review in more detail later.  The result is that some page are already starting to come off.  I guess I&#8217;ll need to buy a second copy the next time I order from Amazon.</p>
<p>Despite the construction issue, WLLH is a terrific beginner&#8217;s book and I don&#8217;t think that I could have asked for anything better.  I&#8217;ll see you at the tables soon!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/636/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/636/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/636/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/636/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/636/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/636/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/636/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/636/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/636/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/636/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/636/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/636/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/636/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/636/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=636&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2009/10/18/my-quick-review-of-winning-low-limit-hold-em-by-lee-jones/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>

		<media:content url="http://ecx.images-amazon.com/images/I/41W7YKGWDZL._SS500_.jpg" medium="image" />
	</item>
		<item>
		<title>Weechat</title>
		<link>http://gnuvince.wordpress.com/2009/10/12/weechat/</link>
		<comments>http://gnuvince.wordpress.com/2009/10/12/weechat/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 18:25:40 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=634</guid>
		<description><![CDATA[I&#8217;ve been an irssi user for more than 7 years. Recently though, I started noticing people on IRC using weechat, another command-line-based client. I got a little curious this weekend and decided to give it a go and I must say that I am extremely impressed with it. I&#8217;ll be using it full time in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=634&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been an <a href="http://irssi.org">irssi</a> user for more than 7 years.  Recently though, I started noticing people on IRC using <a href="http://weechat.org">weechat</a>, another command-line-based client.  I got a little curious this weekend and decided to give it a go and I must say that I am <b>extremely</b> impressed with it.  I&#8217;ll be using it full time in the upcoming weeks to see how I like it. Here are some of the features I like after a couple days of usage:</p>
<ul>
<li>Scriptable in Python: Perl, Ruby, Lua and Tcl can also be used, but since Python is one of my favourite languages, that makes scripting for weechat all the more attractive to me</li>
<li>The nicknames of the people speaking are all neatly aligned and separated from their message at the same column, making it very easy to read.</li>
<li>Like in graphical clients, weechat maintains a list of the nicknames on each channel</li>
<li>Highly configurable: I haven&#8217;t found many default settings that were to my dislike that I couldn&#8217;t change easily.</li>
</ul>
<p>There are also things I disliked:</p>
<ul>
<li>Windows don&#8217;t maintain their position: if you scroll up in one window, switch to another one and come back, the original window will be at the bottom of its buffer again, not where you left it.  There&#8217;s a ticket opened for that problem, hopefully it is fixed soon.</li>
<li>When you type a long message in irssi, when you reach the right edge of the terminal, the text is move to the left by about a third of the width of the terminal.  weechat just keeps on going, always hugging the right edge of the terminal.  This is not a showstopper, but it&#8217;s a little annoying.  Weechat allows the input bar&#8217;s height to be configured, which tells me that a nice solution to this problem would be to increase the height as the input reaches the right edge of the window and resets to its original size afterwards.</li>
<li>Because the messages are between the aligned nicknames and the nickname list, long URLs are a pain in the neck to open.  Some scripts available on the weechat website deal with this problem, but none in a way that I really like.  Ideally, I&#8217;d want to be able to press a key combination, have a window of the URLs said in this particular channel that would allow me to use the up and down keys to select the one that I wish to open, press Return to open the link.  Upon pressing Return, the URL list window would be closed (or kept open, this could be configurable).  If I like weechat enough, I just might try to write it myself.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/634/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/634/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/634/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/634/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/634/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/634/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/634/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/634/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/634/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/634/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/634/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/634/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/634/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/634/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=634&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2009/10/12/weechat/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>
	</item>
		<item>
		<title>Has anyone ever got their Yahoo! accounts deleted for no apparent reason?</title>
		<link>http://gnuvince.wordpress.com/2009/10/01/has-anyone-ever-got-their-yahoo-accounts-deleted-for-no-apparent-reason/</link>
		<comments>http://gnuvince.wordpress.com/2009/10/01/has-anyone-ever-got-their-yahoo-accounts-deleted-for-no-apparent-reason/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 14:46:07 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=632</guid>
		<description><![CDATA[I ordered a couple of books on Amazon.ca yesterday and I was a little concerned when I didn&#8217;t get a confirmation email. I thought that it could just be a delay in delivery and figured I&#8217;d get it the next morning, so I went to bed. This morning, the confirmation email had still not arrived. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=632&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I ordered a couple of books on Amazon.ca yesterday and I was a little concerned when I didn&#8217;t get a confirmation email.  I thought that it could just be a delay in delivery and figured I&#8217;d get it the next morning, so I went to bed.</p>
<p>This morning, the confirmation email had still not arrived.  The first thing I did was to check if it wasn&#8217;t in my spam folder.  It wasn&#8217;t.  My next thought was that the Yahoo! Mail to Gmail redirection had somehow stopped working.  I have a Yahoo! account which I used for Amazon, but that I now use for all sorts of throwaway purposes and my main Gmail account; all mail from Yahoo! is redirected to Gmail.</p>
<p>I tried to connect to the Yahoo! Mail web interface, but it gave me a very weird message: this user ID does not exist.</p>
<p>I thought that it was very odd and that it must be a mistake on my part.  I tried several times, adding the @yahoo.ca suffix to make sure that I had the correct email, but no luck.  Finally, I decided to do a test: I clicked the &#8220;New User&#8221; link, I typed in my Yahoo! user ID and clicked the &#8220;Verify&#8221; button to make sure it was available.  It was.</p>
<p>My Yahoo! account was deleted sometimes during the week (I cannot say when exactly).  Has this ever happened to anyone?  Is there a cause for that? </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/632/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=632&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2009/10/01/has-anyone-ever-got-their-yahoo-accounts-deleted-for-no-apparent-reason/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>
	</item>
		<item>
		<title>This is why you need static typing</title>
		<link>http://gnuvince.wordpress.com/2009/09/29/this-is-why-you-need-static-typing/</link>
		<comments>http://gnuvince.wordpress.com/2009/09/29/this-is-why-you-need-static-typing/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 02:17:36 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=627</guid>
		<description><![CDATA[Because errors like this are just so embarrassing:<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=627&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Because errors like this are just so embarrassing:</p>
<p><a href="http://gnuvince.files.wordpress.com/2009/09/2009-09-29-221401_812x463_scrot.png"><img src="http://gnuvince.files.wordpress.com/2009/09/2009-09-29-221401_812x463_scrot.png?w=300&#038;h=171" alt="2009-09-29-221401_812x463_scrot" title="2009-09-29-221401_812x463_scrot" width="300" height="171" class="aligncenter size-medium wp-image-629" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/627/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/627/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/627/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/627/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/627/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/627/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/627/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/627/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/627/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/627/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/627/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/627/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/627/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/627/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=627&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2009/09/29/this-is-why-you-need-static-typing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>

		<media:content url="http://gnuvince.files.wordpress.com/2009/09/2009-09-29-221401_812x463_scrot.png?w=300" medium="image">
			<media:title type="html">2009-09-29-221401_812x463_scrot</media:title>
		</media:content>
	</item>
		<item>
		<title>K&amp;R and Programming Safety</title>
		<link>http://gnuvince.wordpress.com/2009/09/23/kr-and-programming-safety/</link>
		<comments>http://gnuvince.wordpress.com/2009/09/23/kr-and-programming-safety/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 00:54:46 +0000</pubDate>
		<dc:creator>gnuvince</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://gnuvince.wordpress.com/?p=623</guid>
		<description><![CDATA[The C Programming Language by Dennis Ritchie and Brian Kernighan &#8212; colloquially known as K&#38;R &#8212; is consistently ranked among the top computer programming books. It introduces the C language, its idioms and a part of its library in 190 pages. The last 50 pages contain a reference of the language. Programmers frequently praise K&#38;R [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=623&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1253748953&amp;sr=8-1"><i>The C Programming Language</i></a> by Dennis Ritchie and Brian Kernighan &#8212; colloquially known as K&amp;R &#8212; is consistently ranked among the top computer programming books.  It introduces the C language, its idioms and a part of its library in 190 pages.  The last 50 pages contain a reference of the language.  Programmers frequently praise K&amp;R for its succinctness and clarity and deplore that the newer programming books are much longer and don&#8217;t have clear explanations or real-world examples.</p>
<p>I own a copy of K&amp;R and I agree that it is great; authors of programming books should read it and work to bring the same pith and clarity to their own work.  Nevertheless, writing a book on a general purpose programming language in less than 200 pages is <b>not</b> something that authors should aim for.  K&amp;R achieves its thinness by avoiding some important topics, not the least of which is safety.</p>
<p>When learning a new skill, such as driving or cooking, it is important to be aware of the possible dangers and how to avoid them.  Road safety should not begin after you&#8217;ve wrecked your father&#8217;s car and it is not after you&#8217;ve cut your fingers that you need to learn how to properly handle a knife.  Programming is no different: safety needs to be taught from the start.</p>
<p>Regretfully, K&amp;R lacks detailed explanations on how to use the language safely.  I cannot recall instances when the authors discussed data validation, how to gracefully and idiomatically handle error conditions or how to avoid the dreaded buffer overflows or format string exploits that plague so many programs today.  It might have been okay in the late 70s to just tell the reader how to make a program work and let them deal with safety themselves, but in the 21st century, when so many aspects of our lives are governed by software, it is crucial that safety be constantly on the programmers&#8217; minds.  Authors should not leave out the details on how to use a tool safely just to skimp on page; doing so would be highly irresponsible.</p>
<p>I recently read <a href="http://www.artima.com/shop/programming_in_scala"><i>Programming in Scala</i></a> by Martin Odersky, Lex Spoon and Bill Venners and I want to point to their book as an example of clear and succinct writing while still providing the read with plenty of details and making sure that the best practises of the language are taught.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gnuvince.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gnuvince.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gnuvince.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gnuvince.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gnuvince.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gnuvince.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gnuvince.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gnuvince.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gnuvince.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gnuvince.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gnuvince.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gnuvince.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gnuvince.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gnuvince.wordpress.com/623/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gnuvince.wordpress.com&amp;blog=1436454&amp;post=623&amp;subd=gnuvince&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gnuvince.wordpress.com/2009/09/23/kr-and-programming-safety/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbf0c4a1a7eff07c11312673937c45f8?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gnuvince</media:title>
		</media:content>
	</item>
	</channel>
</rss>
