<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Fredrik Appelberg's blog]]></title>
  <link href="http://mulli.nu/atom.xml" rel="self"/>
  <link href="http://mulli.nu/"/>
  <updated>2013-04-24T19:33:19+02:00</updated>
  <id>http://mulli.nu/</id>
  <author>
    <name><![CDATA[Fredrik Appelberg]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Bird flu]]></title>
    <link href="http://mulli.nu/2013/04/24/bird-flu.html"/>
    <updated>2013-04-24T19:30:00+02:00</updated>
    <id>http://mulli.nu/2013/04/24/bird-flu</id>
    <content type="html"><![CDATA[<p><img src="http://mulli.nu/media/comic/bird-flu.png"></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Back to reality]]></title>
    <link href="http://mulli.nu/2013/04/23/back-to-reality.html"/>
    <updated>2013-04-23T08:28:00+02:00</updated>
    <id>http://mulli.nu/2013/04/23/back-to-reality</id>
    <content type="html"><![CDATA[<p><img class="right" src="http://mulli.nu/media/images/kabukicho_gate.jpg" width="400" title="The Kabukicho gate" ></p>

<p>We just got back from a two-week trip to Japan, which was simply
<em>amazing</em>. I&#8217;ve seen more temples and <a href="http://en.wikipedia.org/wiki/Torii">Torii gates</a> than I care
to remember; I&#8217;ve seen the spring festival of Takayama and the Peace
Museum of Hiroshima. We went on a pilgrimage to <a href="https://www.google.com/search?site=&amp;tbm=isch&amp;source=hp&amp;biw=1242&amp;bih=802&amp;q=akihabara&amp;oq=akihabara&amp;gs_l=img.3.0.0l10.962.2026.0.3818.9.5.0.4.4.0.50.228.5.5.0...0.0...1ac.1.9.img.I11Iugoe744">Akihabara</a>, shopped
at <a href="https://www.google.com/search?site=&amp;tbm=isch&amp;source=hp&amp;biw=1242&amp;bih=802&amp;q=super+potato+akihabara&amp;oq=super+potato+akihabara&amp;gs_l=img.3..0l2j0i24l4.2268.11140.0.11293.22.11.0.11.11.0.73.467.11.11.0...0.0...1ac.1.9.img.x6JaUxNRlMo">Super Potato</a>, and had drinks at <a href="http://8bitcafe.net">8-bit Cafe</a>.</p>

<p>As most of my Japan knowledge comes from exclusively from playing the
<a href="http://en.wikipedia.org/wiki/Yakuza_(series)">Yakuza</a> games, one of my personal highlights was visiting the
real-life &#8220;Kamurocho&#8221; and seeing the iconic Kabukicho gate.</p>

<p>Side note: Tokyo is about just about the only city on earth where I&#8217;d
feel comfortable walking around the red light district at night
snapping pictures with my big touristy camera.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[This is why we fight]]></title>
    <link href="http://mulli.nu/2013/04/02/this-is-why-we-fight.html"/>
    <updated>2013-04-02T16:42:00+02:00</updated>
    <id>http://mulli.nu/2013/04/02/this-is-why-we-fight</id>
    <content type="html"><![CDATA[<p><a href="http://boardgamegeek.com/thread/940888/a-life-altering-game-deserves-this-kind-of-session">This is frankly the best damn session report I&#8217;ve read in my entire life</a>. At
36 pages long, it is an superbly well-written essay about the
psychology of gaming, friendship, and the sheer ridiculousness of a
<a href="http://boardgamegeek.com/boardgame/7614/a-world-at-war">certain monster wargame</a>.</p>

<blockquote><p>“Troy,” I said, “the reason I want so much to play this game is because nobody wants me to play this game. There is virtually no person you could present this to without getting a stunned, pitying look in return, and that ticks me off. It ticks me off because what so freaks people out is the time involved in this endeavor, time. Everything in adult life is designed to steal it away from us, and my God, look how we go along with the scheme so willingly.</p>

<p>&#8220;‘I have no time for such things anymore,’ we say, and then we spend our afternoons making our lawns pretty and shopping for junky Ikea furniture and ferrying kids to soccer games and gawking at cable TV, and above all, working at jobs we never really wanted. ‘Sure,’ we say, ‘when I was young and didn’t have all these responsibilities, I could spend hours doing this kind of thing. But that was then, and this is now.’</p>

<p>“Well, Troy,” I went on, “I want to be the guy who suddenly, at age 42, does spend hours doing this kind of thing, if only to feel what it’s like to take back a little piece of the soul I’ve sold to the company I slave for, to the obligatory evenings with people I’m not sure I even like, to daily errands, the lines at the DMV, to tax forms, to tedious family visits. This game is a slap in the face to all thinking creatures who live in such dire fear of the sands sifting through the hourglass. Playing a monster war game on this scale is ridiculous, a waste of energy, a waste of time, and so I want to do it. Let spite rule the day, Troy. Let’s learn and play A World at War!”</p></blockquote>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[In Despair, Liberation]]></title>
    <link href="http://mulli.nu/2013/03/20/in-despair.html"/>
    <updated>2013-03-20T19:37:00+01:00</updated>
    <id>http://mulli.nu/2013/03/20/in-despair</id>
    <content type="html"><![CDATA[<p><img src="http://mulli.nu/media/comic/in-despair-liberation.png"></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Raspberry, meet elnode]]></title>
    <link href="http://mulli.nu/2013/02/28/raspberry-meet-elnode.html"/>
    <updated>2013-02-28T19:08:00+01:00</updated>
    <id>http://mulli.nu/2013/02/28/raspberry-meet-elnode</id>
    <content type="html"><![CDATA[<p>So, I was curious about <a href="http://www.raspberrypi.org">elnode</a>. And I wanted to play more with
my <a href="http://www.raspberrypi.org">Raspberry Pi</a>. It only seemed logical
<a href="http://pi.appelberg.me:8000">to combine the two.</a></p>

<p>You know, because I can.</p>

<p><em>(I promised <a href="https://twitter.com/nicferrier">@nicferrier</a> a writeup on this project, so here
goes.)</em></p>

<h2>Installing Emacs 24</h2>

<p>The Emacs that comes with the Raspian distribution is version
23.4. Unfortunately, <a href="http://www.raspberrypi.org">elnode</a> requires Emacs 24, so I had to
compile my own. I dreaded doing this, but it actually turned out
pretty straightforward.</p>

<p>You need to <code>apt-get install</code> some build dependencies like
<code>libncurses-dev</code> (and probably <code>build-essentials</code> if you don&#8217;t
already have them), then you&#8217;re ready to go:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> &gt; wget http://ftp.gnu.org/pub/gnu/emacs/emacs-24.2.tar.gz
</span><span class='line'> &gt; tar xvfz emacs-24.2.tar.gz
</span><span class='line'> &gt; cd emacs-24.2
</span><span class='line'> &gt; ./configure
</span><span class='line'> &gt; make 
</span><span class='line'> &gt; sudo make install</span></code></pre></td></tr></table></div></figure>


<p>This would be a good opportunity to make a sandwich, or
<a href="http://www.penny-arcade.com/comic/2008/02/06">learn some sanskrit</a>, as building everything will take
quite a while.</p>

<h2>Running Emacs</h2>

<p>By default the elnode webserver runs on Emacs startup, so the idea is
to fire up emacs and just leave it. One way of doing that would be to
ssh into the Pi and run emacs inside a <a href="http://tmux.sourceforge.net">tmux</a> session (I tend to use
tmux for all remote access anyway). This makes the emacs process
persistent, and when I next log in I can just resume the session.</p>

<p>However, with this approach I&#8217;d still need to login in and start
manually every time the server restarts, so the setup is kind of
fragile. Especially since I have builders running round the house
cutting the main power every now and then.</p>

<p>So instead I use a simple init script to run emacs in daemon mode
(using the aptly named <code>--daemon</code> switch). This way I can still
connect to the running emacs process using <code>emacsclient</code>, but I don&#8217;t
have to bother with starting it manually anymore.</p>

<p>The only caveat is that since I want <code>start-stop-daemon</code> to fork off a
new process to run emacs as the <code>pi</code> user (running a web-connected
emacs as <code>root</code> seems like a really bad idea), I can&#8217;t rely on it to
generate a correct PID file for me. Instead, we&#8217;ll have to do that
from inside emacs (see next section).</p>

<figure class='code'><figcaption><span>/etc/init.d/elnode</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="c">#!/bin/sh</span>
</span><span class='line'>
</span><span class='line'><span class="nb">set</span> -e
</span><span class='line'>
</span><span class='line'><span class="c"># Must be a valid filename</span>
</span><span class='line'><span class="nv">NAME</span><span class="o">=</span>elnode
</span><span class='line'><span class="nv">PIDFILE</span><span class="o">=</span>/home/pi/elnode/elnode.pid
</span><span class='line'><span class="nv">UID</span><span class="o">=</span>1000
</span><span class='line'><span class="c">#This is the command to be run, give the full pathname</span>
</span><span class='line'><span class="nv">DAEMON</span><span class="o">=</span>/usr/local/bin/emacs
</span><span class='line'><span class="nv">DAEMON_OPTS</span><span class="o">=</span><span class="s2">&quot;--daemon --load /home/pi/.emacs.d/init.el --load /home/pi/elnode/web.el&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="nb">export </span><span class="nv">PATH</span><span class="o">=</span><span class="s2">&quot;${PATH:+$PATH:}/usr/sbin:/sbin&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="k">case</span> <span class="s2">&quot;$1&quot;</span> in
</span><span class='line'>    start<span class="o">)</span>
</span><span class='line'>        <span class="nb">echo</span> -n <span class="s2">&quot;Starting daemon: &quot;</span><span class="nv">$NAME</span>
</span><span class='line'>        start-stop-daemon --start --quiet --pidfile <span class="nv">$PIDFILE</span> --chuid <span class="nv">$UID</span> --exec <span class="nv">$DAEMON</span> -- <span class="nv">$DAEMON_OPTS</span>
</span><span class='line'>        <span class="nb">echo</span> <span class="s2">&quot;.&quot;</span>
</span><span class='line'>      ;;
</span><span class='line'>    stop<span class="o">)</span>
</span><span class='line'>        <span class="nb">echo</span> -n <span class="s2">&quot;Stopping daemon: &quot;</span><span class="nv">$NAME</span>
</span><span class='line'>        start-stop-daemon --stop --quiet --oknodo --pidfile <span class="nv">$PIDFILE</span>
</span><span class='line'>        <span class="nb">echo</span> <span class="s2">&quot;.&quot;</span>
</span><span class='line'>      ;;
</span><span class='line'>    restart<span class="o">)</span>
</span><span class='line'>        <span class="nb">echo</span> -n <span class="s2">&quot;Restarting daemon: &quot;</span><span class="nv">$NAME</span>
</span><span class='line'>        start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile <span class="nv">$PIDFILE</span>
</span><span class='line'>        start-stop-daemon --start --quiet --pidfile <span class="nv">$PIDFILE</span> --chuid <span class="nv">$UID</span> --exec <span class="nv">$DAEMON</span> -- <span class="nv">$DAEMON_OPTS</span>
</span><span class='line'>      <span class="nb">echo</span> <span class="s2">&quot;.&quot;</span>
</span><span class='line'>      ;;
</span><span class='line'>
</span><span class='line'>    *<span class="o">)</span>
</span><span class='line'>      <span class="nb">echo</span> <span class="s2">&quot;Usage: &quot;</span><span class="nv">$1</span><span class="s2">&quot; {start|stop|restart}&quot;</span>
</span><span class='line'>      <span class="nb">exit </span>1
</span><span class='line'><span class="k">esac</span>
</span><span class='line'>
</span><span class='line'><span class="nb">exit </span>0
</span></code></pre></td></tr></table></div></figure>


<p>When I start the deamon I get some weird error messages from elnode,
but as far as I can tell it actually runs fine.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>pi@raspberrypi ~ $ sudo /etc/init.d/elnode start                                                                                                                  
</span><span class='line'>Restarting daemon: elnode("/usr/local/bin/emacs" "--load" "/home/pi/.emacs.d/init.el" "--load" "/home/pi/elnode/web.el")
</span><span class='line'>Starting Emacs daemon.
</span><span class='line'>deleting server process
</span><span class='line'>elnode-error: elnode--sentinel 'deleted.' for process  *elnode-webserver-proc* with buffer *elnode-webserver*
</span><span class='line'>found the server process - NOT deleting
</span><span class='line'>elnode-error: Elnode server stopped
</span><span class='line'>.</span></code></pre></td></tr></table></div></figure>


<h2>Running elnode</h2>

<p>Elnode is available from <a href="http://marmalade-repo.org/">Marmalade</a>, which makes it very easy
to install from inside emacs. I also grapped the <a href="https://github.com/philjackson/xmlgen">xmlgen</a> library to
help with HTML generation.</p>

<p>This is my little Hello World-script. There&#8217;s nothing remarkable about
it, really. The first section generates a PID file to be used by the
init script to check if the process is running. I stop the default
server, as it binds to &#8220;localhost&#8221;, and I want to bind to the actual
server name (<code>raspberrypi.local</code> in my case) in order to serve remote
requests. You can see it in action <a href="http://pi.appelberg.me:8000">here.</a></p>

<p>Did I say there was nothing remarkable about this script? <em>Yeah, apart
from the fact that it&#8217;s running a webserver inside a 25 year old text
editor on a computer that&#8217;s about as large as a deck of cards.</em></p>

<figure class='code'><figcaption><span>/home/pi/elnode/web.el</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
</pre></td><td class='code'><pre><code class='cl'><span class='line'><span class="c1">;;; -*- lexical-binding: t -*-</span>
</span><span class='line'>
</span><span class='line'><span class="c1">;; write the pid file</span>
</span><span class='line'><span class="p">(</span><span class="nv">with-temp-file</span> <span class="s">&quot;/home/pi/elnode/elnode.pid&quot;</span> <span class="p">(</span><span class="nv">insert</span> <span class="p">(</span><span class="nb">format</span> <span class="s">&quot;%d&quot;</span> <span class="p">(</span><span class="nv">emacs-pid</span><span class="p">))))</span>
</span><span class='line'>
</span><span class='line'><span class="p">(</span><span class="nb">require</span> <span class="ss">&#39;cl</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="c1">;; stop the default server</span>
</span><span class='line'><span class="p">(</span><span class="nv">elnode-stop</span> <span class="mi">8000</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="p">(</span><span class="nb">defvar</span> <span class="nv">request-count</span> <span class="mi">0</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="p">(</span><span class="nb">defun</span> <span class="nv">hello-handler</span> <span class="p">(</span><span class="nv">httpconn</span><span class="p">)</span>
</span><span class='line'>  <span class="s">&quot;Hello, world&quot;</span>
</span><span class='line'>  <span class="p">(</span><span class="nv">elnode-http-start</span> <span class="nv">httpconn</span> <span class="mi">200</span> <span class="o">&#39;</span><span class="p">(</span><span class="s">&quot;Content-Type&quot;</span> <span class="o">.</span> <span class="s">&quot;text/html&quot;</span><span class="p">))</span>
</span><span class='line'>  <span class="p">(</span><span class="nv">elnode-http-return</span> <span class="nv">httpconn</span>
</span><span class='line'>            <span class="p">(</span><span class="nv">xmlgen</span>
</span><span class='line'>             <span class="o">`</span><span class="p">(</span><span class="nv">html</span>
</span><span class='line'>           <span class="p">(</span><span class="nv">head</span>
</span><span class='line'>            <span class="p">(</span><span class="nv">title</span> <span class="s">&quot;Hello, elnode!&quot;</span><span class="p">)</span>
</span><span class='line'>            <span class="p">(</span><span class="nv">style</span> <span class="s">&quot;body { margin:100px auto auto auto; width: 400px; }&quot;</span><span class="p">))</span>
</span><span class='line'>           <span class="p">(</span><span class="nv">body</span>
</span><span class='line'>            <span class="p">(</span><span class="nv">p</span> <span class="s">&quot;Hello, I am a small &quot;</span>
</span><span class='line'>               <span class="p">(</span><span class="nv">a</span> <span class="ss">:href</span> <span class="s">&quot;https://github.com/nicferrier/elnode&quot;</span> <span class="s">&quot;webserver&quot;</span><span class="p">)</span>
</span><span class='line'>               <span class="s">&quot; running inside Emacs 24 on a &quot;</span>
</span><span class='line'>               <span class="p">(</span><span class="nv">a</span> <span class="ss">:href</span> <span class="s">&quot;http://www.raspberrypi.org&quot;</span> <span class="s">&quot;Raspberry Pi&quot;</span><span class="p">)</span>
</span><span class='line'>               <span class="s">&quot;.&quot;</span><span class="p">)</span>
</span><span class='line'>            <span class="p">(</span><span class="nv">p</span> <span class="s">&quot;The local time is &quot;</span>
</span><span class='line'>               <span class="o">,</span><span class="p">(</span><span class="nv">format-time-string</span> <span class="s">&quot;%H:%M&quot;</span><span class="p">)</span>
</span><span class='line'>               <span class="s">&quot; and I have served a total of &quot;</span>
</span><span class='line'>               <span class="o">,</span><span class="p">(</span><span class="nb">incf</span> <span class="nv">request-count</span><span class="p">)</span>
</span><span class='line'>               <span class="s">&quot; requests.&quot;</span><span class="p">))))))</span>
</span><span class='line'>
</span><span class='line'><span class="p">(</span><span class="nb">defun</span> <span class="nv">root-handler</span> <span class="p">(</span><span class="nv">httpconn</span><span class="p">)</span>
</span><span class='line'>  <span class="p">(</span><span class="nv">elnode-hostpath-dispatcher</span> <span class="nv">httpconn</span> <span class="o">&#39;</span><span class="p">((</span><span class="s">&quot;.*/favicon.ico&quot;</span> <span class="o">.</span> <span class="nv">elnode-send-404</span><span class="p">)</span>
</span><span class='line'>                   <span class="p">(</span><span class="s">&quot;.*&quot;</span> <span class="o">.</span> <span class="nv">hello-handler</span><span class="p">))))</span>
</span><span class='line'>
</span><span class='line'><span class="p">(</span><span class="nv">elnode-start</span> <span class="ss">&#39;root-handler</span> <span class="ss">:port</span> <span class="mi">8000</span> <span class="ss">:host</span> <span class="s">&quot;raspberrypi.local&quot;</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Weapons of Choice]]></title>
    <link href="http://mulli.nu/2013/02/26/weapons-of-choice.html"/>
    <updated>2013-02-26T15:26:00+01:00</updated>
    <id>http://mulli.nu/2013/02/26/weapons-of-choice</id>
    <content type="html"><![CDATA[<p>I do Java for a living. Apart from a two-year hiatus back in 2003-05
I&#8217;ve been a Java guy ever since I left university in 1997 (<em>Man,
sixteen years now! I didn&#8217;t realize.</em>).</p>

<p>Java is&#8230; well, it&#8217;s Java. For all it warts, it&#8217;s actually a pretty
decent environment to get things done in. Yeah, it&#8217;s verbose as
hell. Yeah, most projects involve heaps of boilerplate XML. And yeah,
Maven is still the best we&#8217;ve got. But still, when you know your way
around it&#8217;s not bad. The 3rd party library support is outstanding, and
most of it is Open Source. Performance is generally good. And the
cross-platform compatibility is at this point something we just take
for granted.</p>

<p>There have been other languages. I was heavily into Common Lisp for a
while. I would prefer it over java were it not for the lack of
standard libraries. <a href="http://clojure.org">Clojure</a> seemed like a logical
progression, but for some reason I couldn&#8217;t get into it. I love the
premise: &#8220;Functional programming with full access to the Java
ecosystem,&#8221; but for some reason I never stuck around.</p>

<p>I was on the <a href="http://www.scala-lang.org/">Scala</a> wagon, I know enough <a href="http://ruby-lang.org">Ruby</a> to be
dangerous, and I&#8217;ve flirted with <a href="http://golang.org">Go</a>, <a href="http://www.haskell.org">Haskell</a>, <a href="http://python.org">Python</a>, and
<a href="http://coffeescript.org">CoffeeScript</a>. All excellent languages in their own right. None of
them really stuck. I&#8217;ve read the books, the blogs, the twitters. I
<em>know</em> these are the languages the cool kids use nowadays. Maybe it
was me, maybe I wasn&#8217;t hipster enough.</p>

<p><span class='pullquote-right' data-pullquote='It is a Lisp, but it&#8217;s awkward
and eccentric even by Lisp standards.'>
But there is one language that has grown on me. That hasn&#8217;t gone away
or been replaced. It&#8217;s a ugly little thing, full of warts and cruft
that has accumulated over many years. It is a Lisp, but it&#8217;s awkward
and eccentric even by Lisp standards. It lacks basic necessities like
namespaces and, for the longest time, lexical scoping. The standard
library is confused and naming conventions are all over the
place. Many Common Lisp staples (like <code>loop</code>, <code>map</code>, and
<code>reduce</code>) are missing. There is a Common Lisp compatibility
package, but using it was controversial and for a long time actively
discouraged.
</span></p>

<p>I am, of course, talking about <a href="http://en.wikipedia.org/wiki/Emacs_Lisp">emacs lisp</a>. I took stock of
<a href="https://github.com/fred-o">my github projects</a> and realized that apart from the Java
stuff, almost all of my recent activities are elisp. This was not
something I had planned, it&#8217;s just that Emacs is such an awesome elisp
IDE. I&#8217;m more productive in elisp than in any other environment. When
I make code changes I&#8217;m not just connecting to a REPL, I&#8217;m actually
changing <em>the very environment I&#8217;m currently coding in.</em> This is
incredibly powerful.</p>

<p>So, Java and elisp. Not very cool, I know. But do not underestimate
the power of knowing your tools and getting shit done.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Raspberry Pi]]></title>
    <link href="http://mulli.nu/2013/02/10/raspberry-pi.html"/>
    <updated>2013-02-10T15:38:00+01:00</updated>
    <id>http://mulli.nu/2013/02/10/raspberry-pi</id>
    <content type="html"><![CDATA[<p>The main focus at the <a href="http://jfokus.se">JFokus</a> conference last week seemed to
be the <a href="http://www.raspberrypi.org">Raspberry Pi</a>. Sure, Oracle was pushing Java 8, JEE 7 and
whatnot, but everybody was talking about the Little PC That
Could. There were raffles where you could win them, and according to
rumors they were given away to the audience at the embedded systems
keynote.</p>

<p>I happened to attend a technical session, mostly because there was
nothing better on. <a href="https://twitter.com/hansolo_">Gerrit Grunwald</a> showed off a Pi-based
system he had set up to display the temperature in his home, and I was
sold immediatly. As I left the room I flipped open my laptop, found <a href="https://www.microkit.se/">a
reseller</a> and ordered myself a starter kit. A few hours later I
got a notice saying it had shipped and by early afternoon the next day
it had been delivered, a full two days before I got home myself.</p>

<p>These are my impressions after playing with it over the weekend:</p>

<ul>
<li>It really is small. Really, really small. Of course, I seem to have
a thing for <a href="http://mulli.nu/2010/05/11/the-anti-ipad.html">small computers</a>.</li>
<li>Video output is strictly HDMI. It hooked up to the TV and booted
nicely, but when I tried connecting it to my old 17&#8221; monitor using
a HDMI-DVI converter I couldn&#8217;t get any signal at all. It doesn&#8217;t
really matter all that much, as getting a SSH server up and running
was trivial, and I kind of prefer accessing it through the network
anyway.</li>
<li>I had the notion that <a href="http://golang.org">Go</a> would be a good language to do some
systems programming in, but getting the infrastructure in place was
not trivial. Essentially you have to
<a href="http://www.greenhughes.com/content/how-get-go-going-raspberry-pi">apply a small patch and rebuild the debian packages</a>
before installing, and remember to put <code>export GOARM=5</code> in your
<code>.bashrc</code>.</li>
<li>The CPU isn&#8217;t great. Building Go from scratch took me well over 30
minutes. I realize I may have been spoiled by my MacBook.</li>
</ul>


<p>And now I have a trivial webserver running:</p>

<figure class='code'><figcaption><span>Disclaimer: I don&#8217;t really know Go</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
</pre></td><td class='code'><pre><code class='go'><span class='line'><span class="kn">package</span> <span class="nx">main</span>
</span><span class='line'>
</span><span class='line'><span class="kn">import</span> <span class="p">(</span>
</span><span class='line'>  <span class="s">&quot;fmt&quot;</span>
</span><span class='line'>  <span class="s">&quot;net/http&quot;</span>
</span><span class='line'>  <span class="s">&quot;html&quot;</span>
</span><span class='line'>  <span class="s">&quot;log&quot;</span>
</span><span class='line'>  <span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">port</span> <span class="p">=</span> <span class="mi">8001</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">s</span> <span class="p">=</span> <span class="o">&amp;</span><span class="nx">http</span><span class="p">.</span><span class="nx">Server</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">Addr</span><span class="p">:</span> <span class="nx">fmt</span><span class="p">.</span><span class="nx">Sprintf</span><span class="p">(</span><span class="s">&quot;:%d&quot;</span><span class="p">,</span> <span class="nx">port</span><span class="p">),</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="kd">func</span> <span class="nx">main</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">http</span><span class="p">.</span><span class="nx">HandleFunc</span><span class="p">(</span><span class="s">&quot;/&quot;</span><span class="p">,</span> <span class="kd">func</span><span class="p">(</span><span class="nx">w</span> <span class="nx">http</span><span class="p">.</span><span class="nx">ResponseWriter</span><span class="p">,</span> <span class="nx">r</span> <span class="o">*</span><span class="nx">http</span><span class="p">.</span><span class="nx">Request</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>      <span class="nx">fmt</span><span class="p">.</span><span class="nx">Fprintf</span><span class="p">(</span><span class="nx">w</span><span class="p">,</span> <span class="s">&quot;Hullo, %q&quot;</span><span class="p">,</span> <span class="nx">html</span><span class="p">.</span><span class="nx">EscapeString</span><span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">URL</span><span class="p">.</span><span class="nx">Path</span><span class="p">))</span>
</span><span class='line'>  <span class="p">})</span>
</span><span class='line'>  <span class="nx">log</span><span class="p">.</span><span class="nx">Printf</span><span class="p">(</span><span class="s">&quot;starting web server on port %d&quot;</span><span class="p">,</span> <span class="nx">port</span><span class="p">)</span>
</span><span class='line'>  <span class="nx">log</span><span class="p">.</span><span class="nx">Fatal</span><span class="p">(</span><span class="nx">s</span><span class="p">.</span><span class="nx">ListenAndServe</span><span class="p">())</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Asadmin shell completion]]></title>
    <link href="http://mulli.nu/2012/08/02/asadmin-shell-completion.html"/>
    <updated>2012-08-02T00:00:00+02:00</updated>
    <id>http://mulli.nu/2012/08/02/asadmin-shell-completion</id>
    <content type="html"><![CDATA[<p>I&#8217;ve been juggling <a href="http://glassfish.java.net/">glassfish</a> servers a lot lately, and found the
<a href="http://weblogs.java.net/blog/felipegaucho/archive/2010/03/04/glassfish-v3-resources-administration-cli-tool-asadmin">asadmin</a> CLI admin tool pretty nice. There was one thing lacking
though: ZSH tab completion. So, being a hacker, I thought to myself:
&#8220;How hard can it be?&#8221;</p>

<p>Pretty hard, as it turns out. The ZSH completion system is
ridiculously complex and poorly documented. There is a
<a href="http://zsh.sourceforge.net/Guide/zshguide.pdf">pretty good ebook</a>, but it is from 2003 and I&#8217;m sure a lot of
things have changed since then. Other than that, then only tutorial on
writing your own completion functions was an
<a href="http://www.linux-mag.com/id/1106/">old Linux Mag article</a>.</p>

<p>After a lot of trial and error, borrowing code from various
<a href="https://github.com/robbyrussell/oh-my-zsh">oh-my-zsh</a> plugins, and nearly giving up in frustration, I&#8217;ve now
produced a plugin of my own. It&#8217;s pretty large (1147 lines), but has
completions for all the 265 subcommands that I know of. I quickly
realized that maintaining the argument completions for all these
subcommands would be quite impractical, so I did what any hacker would
do: I wrote <a href="https://gist.github.com/3235533">quick-and-dirty program</a> that goes through all
the glassfish jar files on the classpath, looking for classes that
implement the asadmin commands. It then looks at annotations and uses
a bit of introspection to determine what arguments are available for
each command, and what completions (if any) should be used to complete
these. The end result is a ZSH script fragment which I then insert
manually into my completion script. Overall, this has worked out
pretty well. And it sure beats doing it by hand.</p>

<p>Anyway, if you work with <code>asadmin</code> and would like some hot completion
action going, check out <a href="https://github.com/fred-o/oh-my-zsh/tree/glassfish-plugin">my oh-my-zsh branch</a> on github.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Finally, an actual emacs-eclim release]]></title>
    <link href="http://mulli.nu/2012/07/10/finally-an-actual-emacs-eclim-release.html"/>
    <updated>2012-07-10T00:00:00+02:00</updated>
    <id>http://mulli.nu/2012/07/10/finally-an-actual-emacs-eclim-release</id>
    <content type="html"><![CDATA[<p>After hacking on and off on <a href="https://github.com/senny/emacs-eclim/">emacs-eclim</a> for the better part of three
years, it&#8217;s finally time to make an actual, honest to God,
release! With a version number and everything!</p>

<p>Even better, I made <em>two</em> releases, both at the same time. Thing is,
the <a href="http://eclim.org">eclim</a> guys switched the format of the response messages to JSON
with eclim 1.7.3. That was a rather good change, but it meant we had
to do quite a bit of work on our end to get everything working
properly. And that&#8217;s why it finally made sense to start talking about
<a href="https://github.com/senny/emacs-eclim/">emacs-eclim</a> releases. If you are stuck on an older version of <a href="http://eclim.org">eclim</a>,
you need <a href="https://github.com/senny/emacs-eclim/">emacs-eclim</a> version 0.1; but for <a href="http://eclim.org">eclim</a> 1.7.3 or later you
must run <a href="https://github.com/senny/emacs-eclim/">emacs-eclim</a> 0.2, or HEAD.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Let's write an emacs mode for Inform 7!]]></title>
    <link href="http://mulli.nu/2012/03/05/let-s-write-an-emacs-mode-for-inform-.html"/>
    <updated>2012-03-05T00:00:00+01:00</updated>
    <id>http://mulli.nu/2012/03/05/let-s-write-an-emacs-mode-for-inform-</id>
    <content type="html"><![CDATA[<p>So, my love affair with <a href="http://inform7.com">Inform</a> <a href="http://localhost:4000/2011/02/11/fun-with-inform7.html">continues</a>. Whatever love I
housed for the in-built editor however, has withered and died. The
keybindings all felt wrong, I kept accidentally narrowing the scope of
the code, and had to use the mouse way too much for it to be a
pleasant writing experience. So I thought, Hey, why not write an emacs
mode for Inform? I&#8217;ve been meaning to learn about major modes and
syntax highlighting anyway, and this is as good an excuse as
any. After a bit of research, it turned out that creating a new major
mode was pretty straightforward.</p>

<p>First, since we want headings in the source code to stand out, we&#8217;ll
define a new font face, based on
<code>font-lock-preprocessor-face</code>. It could be inherited from any face,
really, but let&#8217;s pick one that&#8217;s likely to have been included in most
colour themes.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='cl'><span class='line'><span class="p">(</span><span class="nv">defface</span> <span class="nv">inform7-heading-face</span>
</span><span class='line'>  <span class="o">&#39;</span><span class="p">((</span><span class="no">t</span> <span class="p">(</span><span class="ss">:inherit</span> <span class="nv">font-lock-preprocessor-face</span> <span class="ss">:weight</span> <span class="nv">bold</span> <span class="ss">:height</span> <span class="mf">1.2</span><span class="p">)))</span>
</span><span class='line'>  <span class="s">&quot;Face for Inform 7 headings&quot;</span>
</span><span class='line'>  <span class="ss">:group</span> <span class="ss">&#39;font-lock-highlighting-faces</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>Then some keybindings for our mode. There&#8217;s not much for us to do
here, but let&#8217;s make RET automatically jump to the correct indentation
level; that&#8217;s always nice:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='cl'><span class='line'><span class="p">(</span><span class="nb">defvar</span> <span class="nv">inform7-mode-map</span>
</span><span class='line'>  <span class="p">(</span><span class="k">let</span> <span class="p">((</span><span class="nb">map</span> <span class="p">(</span><span class="nv">make-sparse-keymap</span><span class="p">)))</span>
</span><span class='line'>    <span class="p">(</span><span class="nv">define-key</span> <span class="nb">map</span> <span class="p">(</span><span class="nv">kbd</span> <span class="s">&quot;RET&quot;</span><span class="p">)</span> <span class="ss">&#39;newline-and-indent</span><span class="p">)</span>
</span><span class='line'>    <span class="p">(</span><span class="nv">define-key</span> <span class="nb">map</span> <span class="s">&quot;\C-j&quot;</span> <span class="ss">&#39;newline-and-indent</span><span class="p">)</span>
</span><span class='line'>    <span class="nb">map</span><span class="p">)</span>
</span><span class='line'>  <span class="s">&quot;Keymap for inform7 major mode&quot;</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>The easiest way to add syntax highlighting for our mode is to use
regexp-based matchers. Inform 7 hasn&#8217;t got that much of a formal
syntax, but it would be nice to highlight keywords like <em>if</em>, <em>then</em>
and <em>otherwise</em> and for section headings in the text. We should also
find some way of supporting indexed text (i.e. anthing inside a string
surrounded by []).</p>

<p>The last one is a bit tricky, as the same delimiters are also used for
comments (see below), and it&#8217;s not actually possible to distinguishing
between them using only regexps. The solution here, prepending a &#8216;.&#8217;
to the matcher, is a workaround that&#8217;s good enough for most cases
though.</p>

<p>One thing to watch out for is that that the names of the faces must be
symbols. For the built-in faces there are variables defined for each
of these, but we must be careful to quote the name of the face we
defined above.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='cl'><span class='line'><span class="p">(</span><span class="nv">defconst</span> <span class="nv">inform7-font-lock-keywords</span>
</span><span class='line'>  <span class="o">`</span><span class="p">((</span> <span class="o">,</span><span class="p">(</span><span class="nv">regexp-opt</span> <span class="o">&#39;</span><span class="p">(</span><span class="s">&quot;Include&quot;</span> <span class="s">&quot;Use&quot;</span> <span class="s">&quot;let&quot;</span> <span class="s">&quot;say&quot;</span> <span class="s">&quot;if&quot;</span> <span class="s">&quot;otherwise&quot;</span><span class="p">)</span> <span class="ss">&#39;words</span><span class="p">)</span> <span class="o">.</span> <span class="nv">font-lock-keyword-face</span><span class="p">)</span>
</span><span class='line'>    <span class="p">(</span><span class="s">&quot;^\\(\\(?:Book\\|Chapter\\|Part\\|Section\\|Volume\\) - .*\\)&quot;</span> <span class="o">.</span> <span class="ss">&#39;inform7-heading-face</span><span class="p">)</span>
</span><span class='line'>    <span class="p">(</span><span class="s">&quot;.\\(\\[.*?\\]\\).&quot;</span> <span class="mi">0</span> <span class="nv">font-lock-variable-name-face</span> <span class="no">t</span><span class="p">)</span>
</span><span class='line'>    <span class="p">)</span>
</span><span class='line'>  <span class="s">&quot;Highlighting expressions for inform7-mode&quot;</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>We now have everything we need to define our new mode. Current wisdom
holds that it&#8217;s a good idea to extend an existing mode using
<code>define-derived-mode</code>, and have someone else do all the heavy
lifting. In our case, we want to extend <a href="https://github.com/brianc/jade-mode">sws-mode</a>, which handles
significant whitespace and provides functions for intelligent
indentation of lines and blocks of code. It is part of
<a href="https://github.com/brianc/jade-mode">jade-mode</a>.</p>

<p>Defining our major mode is deceptively simple; we just pass in a mode
name, the name of the mode we&#8217;re deriving from, a printable name that
will be displayed in the status line, and a body of code that will be
executed when the mode is initialized. <code>define-derived-mode</code> will take
care of the rest and set up a keymap, syntax table, mode hooks and
ensure that the parent mode and the hooks are called on init. In our
case, we&#8217;ve already created the keymap manually, so
<code>define-derived-mode</code> will use that one instead.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='cl'><span class='line'><span class="p">(</span><span class="nv">define-derived-mode</span> <span class="nv">inform7-mode</span> <span class="nv">sws-mode</span> <span class="s">&quot;Inform7&quot;</span>
</span><span class='line'>  <span class="s">&quot;Major mode for editing inform 7 story files.&quot;</span>
</span><span class='line'>  <span class="p">(</span><span class="nv">visual-line-mode</span><span class="p">)</span>
</span><span class='line'>  <span class="p">(</span><span class="nb">set</span> <span class="p">(</span><span class="nv">make-local-variable</span> <span class="ss">&#39;font-lock-defaults</span><span class="p">)</span> <span class="o">&#39;</span><span class="p">(</span><span class="nv">inform7-font-lock-keywords</span> <span class="no">nil</span> <span class="no">t</span><span class="p">)))</span>
</span></code></pre></td></tr></table></div></figure>


<p>Two things remain, though. First, the line indent function does always
increases the indentation of new/empty lines by one step. For inform
code, we only want that if the preceding line ends with a &#8216;:&#8217;,
otherwise we&#8217;d like the new line to have the same indentation level as
the previous one.</p>

<p>It turns out, that can be accomplished by adding some advice around
<code>sws-do-indent-line</code>, which is the function in sws-mode that actually
carries out the indentation:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='cl'><span class='line'><span class="p">(</span><span class="nv">defadvice</span> <span class="nv">sws-do-indent-line</span> <span class="p">(</span><span class="nv">around</span> <span class="nv">inform7-indent-blank</span> <span class="p">()</span> <span class="nv">activate</span><span class="p">)</span>
</span><span class='line'>  <span class="s">&quot;Ensure proper indentation of blank lines according to Inform7 conventions.&quot;</span>
</span><span class='line'>  <span class="p">(</span><span class="k">if</span> <span class="p">(</span><span class="nb">and</span> <span class="p">(</span><span class="nb">eq</span> <span class="nv">major-mode</span> <span class="ss">&#39;inform7-mode</span><span class="p">)</span> <span class="p">(</span><span class="nv">sws-empty-line-p</span><span class="p">))</span>
</span><span class='line'>    <span class="p">(</span><span class="k">if</span> <span class="p">(</span><span class="nv">save-excursion</span>
</span><span class='line'>          <span class="p">(</span><span class="nv">previous-line</span><span class="p">)</span>
</span><span class='line'>          <span class="p">(</span><span class="nv">looking-at</span> <span class="s">&quot;^.*:[ \t]*$&quot;</span><span class="p">))</span>
</span><span class='line'>        <span class="p">(</span><span class="nv">indent-to</span> <span class="p">(</span><span class="nv">sws-max-indent</span><span class="p">))</span>
</span><span class='line'>      <span class="p">(</span><span class="nv">indent-to</span> <span class="p">(</span><span class="nv">sws-previous-indentation</span><span class="p">)))</span>
</span><span class='line'>    <span class="nv">ad-do-it</span><span class="p">))</span>
</span></code></pre></td></tr></table></div></figure>


<p>The other thing we need to fix is highlighting of comments in the
text. We don&#8217;t want to do this with regexps, as it&#8217;s tricky to get
this working reliably for multi-line comments. Instead, we&#8217;ll take
advantage of the built-in facilities for syntactic
highlighting. Incidentally, you may have noticed that we didn&#8217;t have
to do anything to get highlighting of strings in the code; the
syntactic parser gives us that functionality for free.</p>

<p>These two lines modifies the syntax table, telling the parser to treat
[ and ] as comment delimiters.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='cl'><span class='line'><span class="p">(</span><span class="nv">modify-syntax-entry</span> <span class="nv">?\[</span> <span class="s">&quot;&lt;]&quot;</span> <span class="nv">inform7-mode-syntax-table</span><span class="p">)</span>
</span><span class='line'><span class="p">(</span><span class="nv">modify-syntax-entry</span> <span class="nv">?\]</span> <span class="s">&quot;&gt;[&quot;</span> <span class="nv">inform7-mode-syntax-table</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>So there we are, <a href="https://github.com/fred-o/inform7-mode/blob/master/inform7-mode.el">41 lines of code</a> all in all, not bad for a start.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[JFokus 2012]]></title>
    <link href="http://mulli.nu/2012/02/20/jfokus-.html"/>
    <updated>2012-02-20T00:00:00+01:00</updated>
    <id>http://mulli.nu/2012/02/20/jfokus-</id>
    <content type="html"><![CDATA[<p>Last week was <a href="http://jfokus.se">JFokus</a>, and a great time
<a href="https://twitter.com/#!/search/%23jfokus">was had by all</a>. This was the third time for me, and I&#8217;m
really glad they moved the location to Stockholm Waterfront. Last time
I went, we were crammed into a cinema complex with far too little
floorspace, no wifi and very limited toilet facilities. This year
though, the location was great and the surprisingly good coffee kept
flowing all throughout the three days.</p>

<p>There seemed to be a good deal of interest in <a href="http://www.scala-lang.org/">Scala</a> at the event,
but I&#8217;m not sure this actually reflects some kind of actual change in
the Java ecosphere. Mostly, it were small, hip, consultancies doing
the promotion, and I have a gnawing suspicion that they don&#8217;t have
much Scala work lined up per se, but are instead using Scala to get
the attention of potential recruits. Time will tell.</p>

<p>I&#8217;m a pretty introverted guy, and don&#8217;t really feel that comfortable
around a lot of people. Most of the time during the big breaks I found
myself wishing for a laptop so that I could get hacking instead of
having to wander round aimlessly pretending to feel at home in the
crowd. Fate, however, seated me beside <a href="http://www.chrisrichardson.net/aboutus.html">Chris Richardson</a> (of
<a href="http://cloudfoundry.org">Cloud Foundry</a> fame) during lunch the first day, and we had
a pretty good discussion, even though my english was still getting up
to speed. For some reason I also managed to corner
<a href="http://gregluck.com/blog/">Greg Luck</a> during the tuesday bar and talk to him about
<a href="http://ehcache.org">Ehcache</a>. Both were very nice guys, and I&#8217;d like to thank them both
for helping me come out of my shell a bit.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Ballad of Emacs-Eclim]]></title>
    <link href="http://mulli.nu/2012/02/02/the-ballad-of-emacs-eclim.html"/>
    <updated>2012-02-02T00:00:00+01:00</updated>
    <id>http://mulli.nu/2012/02/02/the-ballad-of-emacs-eclim</id>
    <content type="html"><![CDATA[<p>I&#8217;ve been using <a href="http://github.com/senny/emacs-eclim">emacs-eclim</a> for java development fulltime for well
over two years now, and I&#8217;ve been a co-maintainer for a couple of
months, but I&#8217;ve never really written anything about it. I guess part
of it is because I&#8217;m way too lazy to do a big write-up explaining all
the moving parts and how it relates to <a href="http://eclim.org/">eclim</a> and <a href="http://eclipse.org">eclipse</a>. You
know, a <em>proper blog post</em>.</p>

<p>Like most java programmers, I was a long-time <a href="http://eclipse.org">eclipse</a> victim. If
you&#8217;re not from the java world yourself, it might be hard to grasp the
love/hate relationship that all java programmers have with this
IDE. Or hate/hate relationship, as it may be. Sure, some people turn
to <a href="http://netbeans.org/">NetBeans</a> or <a href="http://www.jetbrains.com/idea/">IntelliJ</a>, but you can&#8217;t get away from the fact that
eclipse has in essence steamrolled all over the java IDE
space. Eclipse is <em>everywhere</em>.</p>

<p>Incidentally, &#8216;steamrolled&#8217; is an appropriate word here, as it
suggests huge mass and inertia bordering on inevitability, both of
which are also properties of eclipse itself. It takes forever to start
up, and if you actually manage to kick off a complex build operation,
it&#8217;s impossible to interrupt it.</p>

<p><a href="http://www.gnu.org/software/emacs/">Emacs</a> was my escape. But the story is kind of complicated. You see,
there was this bunch of enterprising <a href="http://www.vim.org/">vim</a> hackers that realized that
even though their editor was the greatest thing since sliced bread, it
wasn&#8217;t really that good at handling large java codebases, something
which eclipse is atually pretty competent at. So they wrote a plugin
for eclipse that turned it into a kind of server, and a vim extension
that acted as a client, and then they could edit the code in vim,
while leveraging the strengths of eclipse, such as command completion,
compilation, and refactoring. And they called it <a href="http://eclim.org/">eclim</a>.</p>

<p><img src="http://mulli.nu/images/article/obscure-setup.jpg" title="My setup is obscure" ></p>

<p>Then another <a href="http://github.com/senny">enterprising fellow</a> ported the client libraries
to <a href="http://www.gnu.org/software/emacs/">emacs</a>, and the result was <a href="http://github.com/senny/emacs-eclim">emacs-eclim</a>. It was a bit rough at
first, but it is improving steadily. In the past year, we&#8217;ve gotten
<a href="http://cx4a.org/software/auto-complete/">auto-complete-mode</a> support, inline error highlighting, improved
handling of import statements and numerous bug fixes. Right now I&#8217;m
working on making calls to the <code>eclimd</code> backend asynchronous, to make
editing more responsive. It kind of works, but right now it&#8217;s ugly.</p>

<p>I actually have no idea how many users we have.  There are
<a href="https://github.com/senny/emacs-eclim/watchers">116 people watching</a> the project on Github right now, and
bug reports are being filed every now and then, so I&#8217;d like to think
that at least <em>someone</em> finds it worthwhile.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Nine Months of Working Remote]]></title>
    <link href="http://mulli.nu/2012/01/26/nine-months-of-working-remote.html"/>
    <updated>2012-01-26T00:00:00+01:00</updated>
    <id>http://mulli.nu/2012/01/26/nine-months-of-working-remote</id>
    <content type="html"><![CDATA[<p>After a routine software update yesterday, my work laptop suddenly
refused to boot. That was a bit scary, and left me stressed out. You
see, I&#8217;m working remote, and the rest of our IT department is located
about 1000 km away. Which pretty much meant <em>&#8220;You&#8217;re on your own,
kid. If you can&#8217;t solve this yourself, then you won&#8217;t have a
workstation for a few days.&#8221;</em></p>

<p>This is the first time, however, that I actually had to reflect on my
working conditions as a remote worker. I have a home office set up,
complete with a stand-up desk, a <a href="http://www.fatboy.com/shop/product/the-original-lime-green">Fatboy bean bag</a>, and
multi-function printer. I do the lion part of my work on my laptop,
hooked up to the compay VPN. Inter-team communication is done using
<a href="http://campfirenow.com">Campfire</a> and daily telephone meetings. In many ways, this is
just like working at the office, except a) I can blast whatever I want
on the stereo, and b) I don&#8217;t get dragged into meetings as often as I
used to.</p>

<p>Working alone does mean that I&#8217;m not just a developer anymore; I&#8217;m
also responsible for first-line support for my own equipment. If the
wifi goes down, no-one will fix it except me. If the laptop bombs out,
I&#8217;ll either have to solve it myself, or find some way of setting up a
temporary workspace on one of the ancient machines I have lying about
until the company can send me a replacement.</p>

<p>Apart from that, I have no complaints about working alone. When I tell
people about my situation, they usually go <em>&#8220;Aaah, but you&#8217;ve got to
have such self dicipline to be working from home.&#8221;</em> The assumption
being, that as soon as you don&#8217;t have someone looking over your
shoulder, you will immediately revert to spending your working time
goofing off. I don&#8217;t get that. When I&#8217;m working, I&#8217;m working. Same as
if I were at the office. And there&#8217;s nothing special about me. In
fact, I&#8217;m a pretty lazy guy.</p>

<p>I got the laptop working again, after an agonizing hour of recovery
mode reboots, random fiddling with the BIOS and finally reinstalling
the X server and proprietary NVIDIA drivers.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Generating java code with maven, QDox and StringTemplate]]></title>
    <link href="http://mulli.nu/2012/01/16/generating-java.html"/>
    <updated>2012-01-16T00:00:00+01:00</updated>
    <id>http://mulli.nu/2012/01/16/generating-java</id>
    <content type="html"><![CDATA[<h2>Introduction: why would you ever want to generate Java code?</h2>

<p>In my current project at work we have quite a few value objects with
giant constructor methods; these behemoths take 20 to 30 arguments
each and it&#8217;s crucial that you get all of them in the right order,
which is a pain in those cases when you&#8217;re only really interested in
setting one or two of them. Just as an example, let&#8217;s just say that
these classes looks something like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">ValueObj</span> <span class="o">{</span>
</span><span class='line'>   <span class="kd">private</span> <span class="kt">int</span> <span class="n">value1</span><span class="o">;</span>
</span><span class='line'>   <span class="kd">private</span> <span class="kt">int</span> <span class="n">value2</span><span class="o">;</span>
</span><span class='line'>   <span class="kd">private</span> <span class="kt">int</span> <span class="n">value3</span><span class="o">;</span>
</span><span class='line'>   <span class="o">...</span>
</span><span class='line'>   <span class="kd">private</span> <span class="n">Object</span> <span class="n">obj1</span><span class="o">;</span>
</span><span class='line'>   <span class="kd">private</span> <span class="n">Object</span> <span class="n">obj1</span><span class="o">;</span>
</span><span class='line'>   <span class="o">...</span>
</span><span class='line'>   <span class="kd">public</span> <span class="nf">ValueObj</span><span class="o">(</span><span class="kt">int</span> <span class="n">value1</span><span class="o">,</span> <span class="kt">int</span> <span class="n">value2</span><span class="o">,</span> <span class="kt">int</span> <span class="n">value2</span><span class="o">,</span> <span class="o">...</span> <span class="n">Object</span>
</span><span class='line'>       <span class="n">obj1</span><span class="o">,</span> <span class="n">Object</span> <span class="n">obj2</span><span class="o">,</span> <span class="o">...)</span> <span class="o">{</span>
</span><span class='line'>      <span class="k">this</span><span class="o">.</span><span class="na">value1</span> <span class="o">=</span> <span class="n">value1</span><span class="o">;</span>
</span><span class='line'>      <span class="k">this</span><span class="o">.</span><span class="na">value2</span> <span class="o">=</span> <span class="n">value2</span><span class="o">;</span>
</span><span class='line'>      <span class="k">this</span><span class="o">.</span><span class="na">value2</span> <span class="o">=</span> <span class="n">value3</span><span class="o">;</span>
</span><span class='line'>      <span class="o">...</span>
</span><span class='line'>      <span class="k">this</span><span class="o">.</span><span class="na">obj1</span> <span class="o">=</span> <span class="n">obj1</span><span class="o">;</span>
</span><span class='line'>      <span class="k">this</span><span class="o">.</span><span class="na">obj2</span> <span class="o">=</span> <span class="n">obj2</span><span class="o">;</span>
</span><span class='line'>      <span class="o">...</span>
</span><span class='line'>   <span class="o">}</span>
</span><span class='line'>
</span><span class='line'>   <span class="kd">public</span> <span class="kt">int</span> <span class="nf">getValue1</span><span class="o">()</span> <span class="o">{</span>
</span><span class='line'>      <span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="na">value1</span><span class="o">;</span>
</span><span class='line'>   <span class="o">}</span>
</span><span class='line'>   <span class="o">...</span> <span class="o">(</span><span class="n">other</span> <span class="n">getter</span> <span class="n">methods</span> <span class="n">follow</span><span class="o">)</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>About a year ago or so we started using the
<a href="http://c2.org">Builder pattern</a>, creating a separate <em>Builder class</em> for
each value object class. The builder has one setter method for each
parameter, and one <code>create()</code> method that instantiates the new object.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">ValueObjBuilder</span> <span class="o">{</span>
</span><span class='line'>   <span class="kd">private</span> <span class="kt">int</span> <span class="n">value1</span><span class="o">;</span>
</span><span class='line'>   <span class="kd">private</span> <span class="kt">int</span> <span class="n">value2</span><span class="o">;</span>
</span><span class='line'>   <span class="kd">private</span> <span class="kt">int</span> <span class="n">value3</span><span class="o">;</span>
</span><span class='line'>   <span class="o">...</span>
</span><span class='line'>   <span class="kd">private</span> <span class="n">Object</span> <span class="n">obj1</span><span class="o">;</span>
</span><span class='line'>   <span class="kd">private</span> <span class="n">Object</span> <span class="n">obj1</span><span class="o">;</span>
</span><span class='line'>   <span class="o">...</span>
</span><span class='line'>
</span><span class='line'>   <span class="kd">public</span> <span class="n">ValueObjBuilder</span> <span class="nf">value1</span><span class="o">(</span><span class="kt">int</span> <span class="n">value1</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>       <span class="k">this</span><span class="o">.</span><span class="na">value1</span> <span class="o">=</span> <span class="n">value1</span><span class="o">;</span>
</span><span class='line'>       <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
</span><span class='line'>   <span class="o">}</span>
</span><span class='line'>   <span class="kd">public</span> <span class="n">ValueObjBuilder</span> <span class="nf">value2</span><span class="o">(</span><span class="kt">int</span> <span class="n">value2</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>       <span class="k">this</span><span class="o">.</span><span class="na">value2</span> <span class="o">=</span> <span class="n">value2</span><span class="o">;</span>
</span><span class='line'>       <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
</span><span class='line'>   <span class="o">}</span>
</span><span class='line'>   <span class="o">...</span>
</span><span class='line'>
</span><span class='line'>   <span class="kd">public</span> <span class="n">ValueObj</span> <span class="nf">create</span><span class="o">()</span> <span class="o">{</span>
</span><span class='line'>       <span class="k">return</span> <span class="k">new</span> <span class="nf">ValueObj</span><span class="o">(</span><span class="n">value1</span><span class="o">,</span> <span class="n">value2</span><span class="o">,</span> <span class="o">...);</span>
</span><span class='line'>   <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Since the setter methods return a reference to the builder itself it
is possible to chain invocations:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="n">ValueObj</span> <span class="n">obj</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ValueObjBuilder</span><span class="o">().</span><span class="na">value1</span><span class="o">(</span><span class="mi">23</span><span class="o">).</span><span class="na">value2</span><span class="o">(</span><span class="mi">47</span><span class="o">).</span><span class="na">create</span><span class="o">();</span>
</span></code></pre></td></tr></table></div></figure>


<p>However convenient these builder classes are to use, I very quickly
tired of maintaining them. Every time you add or remove a property to
a value object, you also need to make the corresponding change to the
builder. Keeping two classes in sync doesn&#8217;t seem like too much work,
but it is unnecessary, and it occurred to me that I could probably
write something to generate the builders automatically.</p>

<h2>Writing a Maven plugin</h2>

<p>We use <a href="http://maven.apache.org/">Maven</a> for our builds. Ok, ok, I know. Maven is horrible,
maven downloads the whole universe, maven is braindead. Yes, I know
all these things. But here&#8217;s the ting: <em>Maven is like democracy: It&#8217;s
not perfect, but it&#8217;s the best we have</em>.</p>

<p>One of the nice things about maven is that it has a well-defined
standard build lifecycle. The build process is divided into steps, and
during one of the steps, <code>generate-sources</code>, a maven plugin has the
opportunity to generate source that will then be compiled during the
<code>compile</code> step.</p>

<p>When invoked, we&#8217;d like the plugin to:</p>

<ol>
<li><p>Loop over our java classes, looking for constructors marked with
our custom <code>@builder</code> javadoc comment.</p></li>
<li><p>For each matching constructor, generate a new source file under
<code>target/generated-sources/builderbuilder/</code> containing the Builder
class.</p></li>
</ol>


<p>The plugin is invoked <em>before</em> the compilation step, meaning that all
the generated code will be included in the final output.</p>

<p>As an example, this code (in <code>src/main/java/example/ValueObj.java</code>):</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kn">package</span> <span class="n">example</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Cat</span> <span class="o">{</span>
</span><span class='line'>   <span class="kd">private</span> <span class="n">String</span> <span class="n">name</span><span class="o">;</span>
</span><span class='line'>   <span class="kd">private</span> <span class="kt">int</span> <span class="n">age</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'>   <span class="cm">/**</span>
</span><span class='line'><span class="cm">    * @builder</span>
</span><span class='line'><span class="cm">    */</span>
</span><span class='line'>   <span class="kd">public</span> <span class="nf">Cat</span><span class="o">(</span><span class="n">String</span> <span class="n">name</span><span class="o">,</span> <span class="kt">int</span> <span class="n">age</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>      <span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">;</span>
</span><span class='line'>      <span class="k">this</span><span class="o">.</span><span class="na">age</span> <span class="o">=</span> <span class="n">age</span><span class="o">;</span>
</span><span class='line'>   <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Will generate the following (in
<code>target/generated-sources/builderbuilder/example/CatBuilder.java)</code> when run through our plugin:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kn">package</span> <span class="n">example</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="nc">CatBuilder</span> <span class="o">{</span>
</span><span class='line'>   <span class="kd">private</span> <span class="n">String</span> <span class="n">name</span><span class="o">;</span>
</span><span class='line'>   <span class="kd">private</span> <span class="kt">int</span> <span class="n">age</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'>   <span class="kd">public</span> <span class="n">CatBuilder</span> <span class="nf">name</span><span class="o">(</span><span class="n">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>      <span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">;</span>
</span><span class='line'>      <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
</span><span class='line'>   <span class="o">}</span>
</span><span class='line'>
</span><span class='line'>   <span class="kd">public</span> <span class="n">CatBuilder</span> <span class="nf">age</span><span class="o">(</span><span class="kt">int</span> <span class="n">age</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>      <span class="k">this</span><span class="o">.</span><span class="na">age</span> <span class="o">=</span> <span class="n">age</span><span class="o">;</span>
</span><span class='line'>      <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
</span><span class='line'>   <span class="o">}</span>
</span><span class='line'>
</span><span class='line'>   <span class="kd">public</span> <span class="n">Cat</span> <span class="nf">create</span><span class="o">()</span> <span class="o">{</span>
</span><span class='line'>      <span class="k">return</span> <span class="k">new</span> <span class="nf">Cat</span><span class="o">(</span><span class="n">name</span><span class="o">,</span> <span class="n">age</span><span class="o">);</span>
</span><span class='line'>   <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>For those of you who like to read along, the code for the whole plugin
is <a href="http://github.com/fred-o/BuilderBuilder">on github</a>. The finished version has some extra bells and
whistles, like the ability to generate abstract builder classes and
explicitly the name of the <code>create()</code> method.</p>

<h2>Parsing Java code</h2>

<p>Okay, so let&#8217;s say we want to pick apart the java class files and for
each constructor found we want to generate a helper class as discussed
above. Now, normally we&#8217;d use the introspection facilities already
built into java, but now we have one problem: our code-generating code
will run during the <code>generate-sources</code> step, <em>before</em> any compilation
has actually taken places.</p>

<p>This is a problem. What we need is a java parser that can pull apart
the relevant bits of the source files and give us enough information
that so we can generate the new classes. Preferably the level of
detail should be on par with with that of the <code>java.util.reflect.*</code>
functions, and it should also be fast. I actually started writing
<a href="http://github.com/fred-o/timjan">something like that</a>, but that&#8217;s another story. Instead,
let&#8217;s check out <a href="http://qdox.codehaus.org">QDox</a>, an amazing little library used
internally by maven.</p>

<p>Using it is pretty simple. First, create a new <code>JavaDocBuilder</code> object
and tell it where the source code you want to parse lives:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="k">this</span><span class="o">.</span><span class="na">docBuilder</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JavaDocBuilder</span><span class="o">();</span>
</span><span class='line'><span class="k">for</span> <span class="o">(</span><span class="n">String</span> <span class="n">r</span> <span class="o">:</span> <span class="n">sources</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>    <span class="n">docBuilder</span><span class="o">.</span><span class="na">addSourceTree</span><span class="o">(</span><span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="n">r</span><span class="o">));</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Then loop over all known classes and generate the builder:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="k">for</span> <span class="o">(</span><span class="n">JavaClass</span> <span class="n">jc</span> <span class="o">:</span> <span class="n">docBuilder</span><span class="o">.</span><span class="na">getClasses</span><span class="o">())</span> <span class="o">{</span>
</span><span class='line'>    <span class="n">generateBuilderFor</span><span class="o">(</span><span class="n">jc</span><span class="o">);</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<h2>Generating the output</h2>

<p>This is the <code>generateBuilderFor()</code> method:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">public</span> <span class="kt">void</span> <span class="nf">generateBuilderFor</span><span class="o">(</span><span class="n">JavaClass</span> <span class="n">jc</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span> <span class="o">{</span>
</span><span class='line'>    <span class="k">for</span><span class="o">(</span><span class="n">JavaMethod</span> <span class="nl">m:</span> <span class="n">jc</span><span class="o">.</span><span class="na">getMethods</span><span class="o">())</span> <span class="o">{</span>
</span><span class='line'>        <span class="k">if</span> <span class="o">(</span><span class="n">m</span><span class="o">.</span><span class="na">isConstructor</span><span class="o">())</span> <span class="o">{</span>
</span><span class='line'>            <span class="n">DocletTag</span> <span class="n">dc</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="na">getTagByName</span><span class="o">(</span><span class="s">&quot;builder&quot;</span><span class="o">);</span>
</span><span class='line'>            <span class="k">if</span> <span class="o">(</span><span class="n">dc</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>                <span class="n">String</span> <span class="n">builderName</span> <span class="o">=</span> <span class="n">dc</span><span class="o">.</span><span class="na">getNamedParameter</span><span class="o">(</span><span class="s">&quot;name&quot;</span><span class="o">);</span>
</span><span class='line'>                <span class="k">if</span> <span class="o">(</span><span class="n">builderName</span> <span class="o">==</span> <span class="kc">null</span><span class="o">)</span>
</span><span class='line'>                    <span class="n">builderName</span> <span class="o">=</span> <span class="n">jc</span><span class="o">.</span><span class="na">getName</span><span class="o">()</span> <span class="o">+</span> <span class="s">&quot;Builder&quot;</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'>                <span class="n">String</span> <span class="n">packageName</span> <span class="o">=</span> <span class="n">dc</span><span class="o">.</span><span class="na">getNamedParameter</span><span class="o">(</span><span class="s">&quot;package&quot;</span><span class="o">);</span>
</span><span class='line'>                <span class="k">if</span> <span class="o">(</span><span class="n">packageName</span> <span class="o">==</span> <span class="kc">null</span><span class="o">)</span>
</span><span class='line'>                    <span class="n">packageName</span> <span class="o">=</span> <span class="n">jc</span><span class="o">.</span><span class="na">getPackageName</span><span class="o">();</span>
</span><span class='line'>
</span><span class='line'>                <span class="n">StringTemplate</span> <span class="n">st</span> <span class="o">=</span> <span class="n">templates</span><span class="o">.</span><span class="na">getInstanceOf</span><span class="o">(</span><span class="s">&quot;builder&quot;</span><span class="o">);</span>
</span><span class='line'>                <span class="n">st</span><span class="o">.</span><span class="na">setAttribute</span><span class="o">(</span><span class="s">&quot;packageName&quot;</span><span class="o">,</span> <span class="n">packageName</span><span class="o">);</span>
</span><span class='line'>                <span class="n">st</span><span class="o">.</span><span class="na">setAttribute</span><span class="o">(</span><span class="s">&quot;builderName&quot;</span><span class="o">,</span> <span class="n">builderName</span><span class="o">);</span>
</span><span class='line'>                <span class="n">st</span><span class="o">.</span><span class="na">setAttribute</span><span class="o">(</span><span class="s">&quot;resultClass&quot;</span><span class="o">,</span> <span class="n">jc</span><span class="o">.</span><span class="na">asType</span><span class="o">().</span><span class="na">toString</span><span class="o">());</span>
</span><span class='line'>
</span><span class='line'>                <span class="n">List</span><span class="o">&lt;</span><span class="n">Param</span><span class="o">&gt;</span> <span class="n">ps</span> <span class="o">=</span> <span class="k">new</span> <span class="n">LinkedList</span><span class="o">&lt;</span><span class="n">Param</span><span class="o">&gt;();</span>
</span><span class='line'>                <span class="k">for</span><span class="o">(</span><span class="n">JavaParameter</span> <span class="nl">p:</span> <span class="n">m</span><span class="o">.</span><span class="na">getParameters</span><span class="o">())</span> <span class="o">{</span>
</span><span class='line'>                       <span class="n">ps</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="k">new</span> <span class="n">Param</span><span class="o">(</span><span class="n">p</span><span class="o">.</span><span class="na">getType</span><span class="o">().</span><span class="na">toGenericString</span><span class="o">(),</span> <span class="n">p</span><span class="o">.</span><span class="na">getName</span><span class="o">()));</span>
</span><span class='line'>                <span class="o">}</span>
</span><span class='line'>                <span class="n">st</span><span class="o">.</span><span class="na">setAttribute</span><span class="o">(</span><span class="s">&quot;parameters&quot;</span><span class="o">,</span> <span class="n">ps</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'>                <span class="n">File</span> <span class="n">pd</span> <span class="o">=</span> <span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="n">outputDirectory</span><span class="o">,</span> <span class="n">packageName</span><span class="o">.</span><span class="na">replaceAll</span><span class="o">(</span><span class="s">&quot;\\.&quot;</span><span class="o">,</span> <span class="s">&quot;/&quot;</span><span class="o">));</span>
</span><span class='line'>                <span class="n">pd</span><span class="o">.</span><span class="na">mkdirs</span><span class="o">();</span>
</span><span class='line'>
</span><span class='line'>                <span class="n">FileWriter</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FileWriter</span><span class="o">(</span><span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="n">pd</span><span class="o">,</span> <span class="n">builderName</span> <span class="o">+</span> <span class="s">&quot;.java&quot;</span><span class="o">));</span>
</span><span class='line'>                <span class="k">try</span> <span class="o">{</span>
</span><span class='line'>                    <span class="n">out</span><span class="o">.</span><span class="na">append</span><span class="o">(</span><span class="n">st</span><span class="o">.</span><span class="na">toString</span><span class="o">());</span>
</span><span class='line'>                <span class="o">}</span> <span class="k">finally</span> <span class="o">{</span>
</span><span class='line'>                    <span class="n">out</span><span class="o">.</span><span class="na">flush</span><span class="o">();</span>
</span><span class='line'>                    <span class="n">out</span><span class="o">.</span><span class="na">close</span><span class="o">();</span>
</span><span class='line'>                <span class="o">}</span>
</span><span class='line'>            <span class="o">}</span>
</span><span class='line'>        <span class="o">}</span>
</span><span class='line'>    <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span><span class='line'>
</span><span class='line'><span class="kd">public</span> <span class="kd">static</span> <span class="kd">class</span> <span class="nc">Param</span> <span class="o">{</span>
</span><span class='line'>    <span class="kd">public</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">type</span><span class="o">;</span>
</span><span class='line'>    <span class="kd">public</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">name</span><span class="o">;</span>
</span><span class='line'>        <span class="kd">public</span> <span class="nf">Param</span><span class="o">(</span><span class="n">String</span> <span class="n">type</span><span class="o">,</span> <span class="n">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
</span><span class='line'>        <span class="k">this</span><span class="o">.</span><span class="na">type</span> <span class="o">=</span> <span class="n">type</span><span class="o">;</span>
</span><span class='line'>        <span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">;</span>
</span><span class='line'>    <span class="o">}</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>This is all pretty straightforward; we loop through the methods for
the class, looking for a constructor that has the <code>@builder</code> javadoc
tag.</p>

<p>Lines 6-12 checks if the tag has any values specified for <code>name</code>
and <code>package</code>, reverting to default values if not.</p>

<p>Lines 14-23 instantiates a new <code>StringTemplate</code> object and supplies it
with values for the <code>packageName</code>, <code>builderName</code> and <code>resultClass</code>
attributes (the latter being the class that we want the builder to
actually build). Lines 19-23 loops through the constructor arguments
and creates value object holding the name &amp; type of each.</p>

<p>Finally, a new file is created (lines 25-26) and written (lines
28-34).</p>

<h2>Templating</h2>

<p>There are an abundance of templating frameworks out there. I choose to
go with <a href="http://stringtemplate.org">StringTemplate</a> for this project, since it makes it easy
to use subtemplates in a functional way, and generally fits my way of
thinking. I could just as easily have used something like
<a href="http://freemarker.sourceforge.net/">FreeMarker</a> or <a href="http://velocity.apache.org/">Velocity</a>, though.</p>

<p>The templates are not that interesting, so I won&#8217;t go into it
here. You can check them out <a href="https://github.com/fred-o/BuilderBuilder/blob/master/src/main/resources/builderbuilder.stg">on github</a> if you are curious.</p>

<h2>Conclusion</h2>

<p>Automatic code generation in java projects is not only feasible, but
also quite convenient with maven. We&#8217;ve been using <a href="http://github.com/fred-o/BuilderBuilder">BuilderBuilder</a>
internally in production for a few months now, and it greatly cuts
down on code maintenance.</p>

<p>It would be nice, though, if there was a more general approach to code
generation. Just for <a href="http://github.com/fred-o/BuilderBuilder">BuilderBuilder</a>, I had to dive into <a href="http://maven.apache.org/">Maven</a>
internals (which are surprisingly poorly documented), learn
<a href="http://qdox.codehaus.org">QDox</a> (ditto) and write all the java code that solved this
particular problem. Imagine instead if there was some kind of
transformation language that operated on java sources, kind of like
what <a href="http://www.w3.org/Style/XSL/">XSLT</a> does for XML? Now, that would be cool.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Night Circus]]></title>
    <link href="http://mulli.nu/2011/09/16/the-night-circus.html"/>
    <updated>2011-09-16T00:00:00+02:00</updated>
    <id>http://mulli.nu/2011/09/16/the-night-circus</id>
    <content type="html"><![CDATA[<p>I&#8217;ve been playing <a href="http://www.nightcircus.co.uk/">The Night Circus</a> a lot lately. Well, &#8216;playing&#8217;
is a strong word; I&#8217;ve been mostly clicking on random cards and
enjoying the athmosphere of the game. I&#8217;m not really making any
informed choices that influence the story, and I have little control
over the game flow. This isn&#8217;t really the type of game I usually
bother with, but it does quite a few things right:</p>

<ul>
<li>You don&#8217;t have to create an account to play; just sign in with you
twitter or facebook account.</li>
<li>Every move is represented by a card that you play. You get to keep
six cards in your and you&#8217;re issued a new card randomly(?) every
four minutes. This, in conjunction with that there is very little
state to keep track of, means that it&#8217;s very easy to return every
now and then, play a few cards and then do something else. In
short, a perfect game to play while <a href="http://xkcd.com/303/">you&#8217;re code&#8217;s compiling</a>.</li>
<li>There&#8217;s a constant stream of small rewards. Almost every card
played gains you a memento of some sort, and most of the mementoes
can be used to unlock new paths in the game.</li>
<li>Also, the setting is very athmospheric in a kind of fantasy
victorian, <a href="http://en.wikipedia.org/wiki/Jonathan_Strange_%26_Mr_Norrell">Jonathan Strange &amp; Mr Norrell</a> kind of
way. The writing is well done, and you get the feeling that there&#8217;s
a lot to be discovered. I don&#8217;t know if there&#8217;s a conclusion or if
the game ever really &#8216;ends&#8217;. New story segments are added weekly
however, so there&#8217;s hope for some kind of coherent story.</li>
</ul>


<p>The game builds Erin Morgenstern&#8217;s upcoming
<a href="http://www.amazon.co.uk/The-Night-Circus-ebook/dp/B005AKFXZW/ref=sr_1_2?s=books&amp;ie=UTF8&amp;qid=1315234149&amp;sr=1-2">novel with the same name</a>, and as a promotion piece it works
pretty well. At the very least, it got me engaged and actually
considering getting the book at some point.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Warning: pictures of cats ahead!]]></title>
    <link href="http://mulli.nu/2011/08/17/warning-pictures-of-cats-ahead-.html"/>
    <updated>2011-08-17T00:00:00+02:00</updated>
    <id>http://mulli.nu/2011/08/17/warning-pictures-of-cats-ahead-</id>
    <content type="html"><![CDATA[<p>I used to draw a lot as a kid, but at some point I stopped doing
it. Maybe I didn&#8217;t have the time. Maybe I wasn&#8217;t good enough, or never
felt like my technique improved. And from time to time I felt really
bad about quitting.</p>

<p>Well, a couple of days ago I dusted off my <a href="http://www.wacom.com/en/Products/BambooTablets.aspx">Wacom Bamboo</a>
tablet, downloaded the latest version of <a href="http://www.artrage.com/artrage2.html">ArtRage</a>, and started
sketching again. For some reason, everything turned out cats:</p>

<p><a class="article_image" href="https://picasaweb.google.com/lh/photo/ElnGMFdjVle1qxLwkb6S5Q?feat=embedwebsite"><img src="https://lh3.googleusercontent.com/-b0whFcik-Oo/TkkFf8lOdBI/AAAAAAAAAEY/CKfS6YpsBQU/s400/kossan%252520i%252520gr%2525C3%2525A4set.JPG" height="400" width="339" /></a></p>

<p><a class="article_image" href="https://picasaweb.google.com/lh/photo/kvCNAfbQS9JxmHOyk5cAXw?feat=embedwebsite"><img src="https://lh6.googleusercontent.com/-xeKxwRE2la0/TkpFxa7K_kI/AAAAAAAAAEs/4-eA4o0YYu4/s400/kossan%252520vilar.JPG" height="300" width="400" /></a></p>

<p>The first two were made using photo references. This is our oldest cat
in various poses.</p>

<p><a class="article_image" href="https://picasaweb.google.com/lh/photo/291ZeH_nqcXWsyj_EZZbfw?feat=embedwebsite"><img class="right" src="https://lh6.googleusercontent.com/--K0FxN6qrOA/TkpFxS9qU7I/AAAAAAAAAEw/KncPLNdLQkw/s400/florence.JPG" height="384" width="400" /></a></p>

<p>This one was actually drawn from memory. This is our smallest cat, and
yes, her ears really are that large.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Amazing Arkham Horror Contents Calculator]]></title>
    <link href="http://mulli.nu/2011/08/07/arkham-horror-contents-calculator.html"/>
    <updated>2011-08-07T00:00:00+02:00</updated>
    <id>http://mulli.nu/2011/08/07/arkham-horror-contents-calculator</id>
    <content type="html"><![CDATA[

<p>It starts out innocently enough. You purchase the <a href="http://boardgamegeek.com/boardgame/15987/arkham-horror">Arkham Horror</a>
base set and play a few games with friends. You have loads of solid,
insanity-inducing fun, but after a while it gets kinda repetitive
playing with the same Investigators and Old Ones over and over
again. So you start looking at expansions, picking up say,
<a href="http://boardgamegeek.com/boardgameexpansion/40776/arkham-horror-innsmouth-horror-expansion">Innsmouth Horror</a> and Bam! you&#8217;re in Happytown again! Killing
monsters! Reading ancient tomes! Learning all things Man Was Not Meant
To Know.</p>

<p>Soon you have collected all the expansions, and now your problem is
that you&#8217;re running out of space. The base set alone contains over 700
moving parts. Each expansion adds more game boards, cards, tokens,
markers and rule books. You start asking yourself exactly what
ridiculous amount of game components you&#8217;ve accumulated on your quest
to boardgame nirvana.</p>

<p>At least, that&#8217;s what I asked myself. And so I whipped together a
web-based calculator using <a href="http://code.google.com/webtoolkit/">GWT</a> and some free time. Now you too
can use it to calculate the extent of <em>your</em> mania.</p>

<!-- more -->


<p><em>Note: The columns are sortable; try clicking on the column
headings. You can filter the selection by (un)checking the boxes for
different expansion sets and component types.</em></p>

<div id="ahccRoot">&nbsp;</div>


<script language="javascript" src="http://mulli.nu/media/ahcc/ahcc.nocache.js" type="text/javascript">&nbsp;</script>


<p>3222 components! Whew, that&#8217;s a <em>lot</em>!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[inform-htmlizer.el]]></title>
    <link href="http://mulli.nu/2011/05/14/inform-htmlizer-el.html"/>
    <updated>2011-05-14T00:00:00+02:00</updated>
    <id>http://mulli.nu/2011/05/14/inform-htmlizer-el</id>
    <content type="html"><![CDATA[<p>While writing the previous two posts I found the need to display
<a href="http://inform7.com">Inform7</a> source code in a blog-friendly way. Unfortunatly, the
<a href="http://pygments.org/">pygments</a> source highlighter doesn&#8217;t support it, and I couldn&#8217;t
find any plugins for it that would. The closest I came was this
<a href="http://blog.worldmaker.net/2009/feb/17/code-snippet-moment-inform-7-lexer-pygments/">blog post by Max Battcher</a>, but as he mentions, pygments is
probably a bad fit for this kind of code. Inform7 source is best
displayed with a non-fixed-width font and uses regular line wrapping,
but depends on significant whitespace for control flow. As far as I
could tell, pygments doesn&#8217;t really support that kind of output, and
anyway I couldn&#8217;t figure out how to use Python&#8217;s <code>setuptools</code> to hook
up my own plugins to begin with.</p>

<p>So I did what any self-respecting hacker would do: I rolled my own
solution using the tools I&#8217;m used to. In my case that means
<a href="http://en.wikipedia.org/wiki/Emacs_Lisp">elisp</a>, which is a good fit for med since Emacs is the tool
<a href="http://mulli.nu/2010/04/23/my-setup.html">I&#8217;m using</a> to write this blog. I&#8217;ve put the code on
<a href="https://github.com/fred-o/inform-htmlizer">GitHub</a> it case it proves useful for the very small subset of
Inform7 users who are also a) Emacs fanatics, and b) desperately in
need of a HTML syntax highlighter.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Working Title: Satisfaction]]></title>
    <link href="http://mulli.nu/2011/04/29/working-title-satisfaction.html"/>
    <updated>2011-04-29T00:00:00+02:00</updated>
    <id>http://mulli.nu/2011/04/29/working-title-satisfaction</id>
    <content type="html"><![CDATA[<p>I&#8217;m starting to settle into my new home office. There are boxes and
cables everywhere, but at least I have a desk to work from. Time to
get back to actual work again.</p>

<p>For the past month, I have made virtually zero progress on my
Interactive Fiction game. I could blame this on the stress of moving
across the country while simultaneously negotiating building plans for
our summer house, and then having relatives visiting the new house
over easter, but I won&#8217;t. Let&#8217;s just say I need a little ignition to
get going again, and I&#8217;m hoping blogging about it a bit will help.</p>

<p>When I first concieved the idea for the game I thought I&#8217;d be done in
a day, or a weekend at most. That was back in January, and I think I
might be halfway to an alpha version now. Obviously, it took a whole
lot longer than I expected, mostly because I was learning
<a href="http://inform7.com/">Inform 7</a> and designing the game world at the same time as
coding. One thing I did do right though, was actually writing a simple
design document before I started. It had a short synopsis describing
the game flow and central mechanics, and a section for each important
person in the game. Nailing down names, titles, and backgrounds of the
characters really helped things later on.</p>

<p>The games is divided into short chapters, with the viewpoint
alternating between two playable characters. I want the player to feel
like she&#8217;s participating in a story rather than trying to beat a game,
so there are no obvious puzzles to solve. In fact, right now most of
the game can be played just by moving between rooms, and waiting at
the correct places. I&#8217;m considering using the subtitle <em>A Short Story
About Inevitability</em>, but we&#8217;ll see.</p>

<p>Much of the plot revolves around discovering things about the player
characters, either by exploring or by having conversations with
NPCs. Even though the player is largely swept along for the ride, his
actions do have consequences for the ending of the game. There are
several different outcomes, even though they may not be obvious.</p>

<p>There are two things I&#8217;m doing to invite re-play of the game. First,
I&#8217;m trying to pace it so that the player will never be able to get the
whole picture in the first play-through. The challenge here is making
the player feel intrigued rather than annoyed, and there&#8217;s a cetain
risk this will backfire. Second, this will be a short game that can
probably be finished within the hour.</p>

<p>As I mentioned earlier, I want this to feel like a proper story. This
means that the player should be able to behave like she would in real
life, and expect a reasonable outcome. It also means that I have to
deal with certain IF staples in creative ways. For example, realism
dictates that there should be certain props (like a sideboard with a
tea kettle and some breakfast on a sideboard in the Dining Romm) in
the game. I want the player to be able to pick up and interact with
these objects, but not carry them around the house (which would spoil
the overall tone of the story). Thus, I created a mechanism for
handling unimportant items:</p>

<div class="i7-sample">
  <div class="i7-heading">Chapter - Non-essential props</div>
  <br/>
  <div>Things can be unimportant.</div>
  <br/>
  <div>A room has an object called the resting place. </div>
  <br/>
  <div>Carry out going when the player has an unimportant thing:</div>
  <div class="i7-indent-1">let the resting place be the resting place of the location;</div>
  <div class="i7-indent-1">let the inessentials be the list of unimportant things carried by the player;</div>
  <div class="i7-indent-1">repeat with the inessential running through the inessentials:</div>
  <div class="i7-indent-2">if the resting place is a supporter:</div>
  <div class="i7-indent-3">try silently putting the inessential on the resting place;</div>
  <div class="i7-indent-2">otherwise if the resting place is a container and the resting place is open:</div>
  <div class="i7-indent-3">try silently inserting the inessential into the resting place;</div>
  <div class="i7-indent-2">otherwise:</div>
  <div class="i7-indent-3">try silently dropping the inessential;</div>
  <div class="i7-indent-1">if the resting place is a supporter:</div>
  <div class="i7-indent-2">say <div class="i7-quote">&#8220;You put the <div class="i7-bracket">[the inessentials]</div> back on <div class="i7-bracket">[the resting place]</div>.&#8221;</div>;</div>
  <div class="i7-indent-1">otherwise if the resting place is a container:</div>
  <div class="i7-indent-2">say <div class="i7-quote">&#8220;You put the <div class="i7-bracket">[the inessentials]</div> back in <div class="i7-bracket">[the resting place]</div>.&#8221;</div>;</div>
  <div class="i7-indent-1">otherwise:</div>
  <div class="i7-indent-2">say <div class="i7-quote">&#8220;You leave the <div class="i7-bracket">[the inessentials]</div> in <div class="i7-bracket">[the printed name of the location in lower case]</div>.&#8221;</div></div>
</div>


<p>This rule ensures that an item that is declared <code>unimportant</code> the
player will drop it before leaving the room. To make it a bit more
realistic, you can name a container or supporter a <code>resting place</code>
(for want of a better name) for each room. Unimportant objects will
then be put back on the supporter or back into the container.</p>

<p>This is the (somewhat abridged) description of my Dining Room:</p>

<div class="i7-sample">
  <div class="i7-heading">Section - Dining Room</div>
  <br/>
  <div>The sideboard is a fixed in place supporter in Dining Room. <div class="i7-quote">&#8220;Along one of the walls is a grand old sideboard crafted out of solid oak. Conveniently placed on it is <div class="i7-bracket">[a list of things on the sideboard]</div>.&#8221;</div> The resting place of Dining Room is the sideboard.</div>
  <br/>
  <div>The silver kettle is on the sideboard. </div>
  <br/>
  <div>The kettle contains the tea. The description of the tea is <div class="i7-quote">&#8220;Smells like Earl Grey.&#8221;</div> The indefinite article of the tea is <div class="i7-quote">&#8220;some&#8221;</div>.</div>
  <br/>
  <div>Some breakfast is on the sideboard. <div class="i7-quote">&#8220;It seems Watkins has prepared some cucumber sandwiches for you. Just as good, you sincerely doubt you&#8217;d be able to eat a full breakfast right now.&#8221;</div> The breakfast is edible.</div>
  <br/>
  <div>The kettle and breakfast are unimportant.</div>

</div>


<p>And this is how it plays:</p>

<pre><code>Dining Room
Along one of the walls is a grand old sideboard crafted out of solid oak. 
Conveniently placed on it is a silver kettle, some breakfast, some china and a 
crystal decanter.

&gt;take kettle
Taken.

&gt;take breakfast
Taken.

&gt;i
You are carrying:
  some breakfast
  a silver kettle
    some tea
  a candle (providing light)
  some clothes (being worn)

&gt;w
You put the breakfast and silver kettle back on the sideboard.

[New room description snipped]
</code></pre>

<p>Allright, I should stop now. I just realized I spent an hour on this
post instead of actually working on the darn game. See ya next time!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Going Remote]]></title>
    <link href="http://mulli.nu/2011/04/06/going-remote.html"/>
    <updated>2011-04-06T00:00:00+02:00</updated>
    <id>http://mulli.nu/2011/04/06/going-remote</id>
    <content type="html"><![CDATA[<p>A week from now the movers will come and stuff all our belongings into
a big ol&#8217; truck. We will get in the car, wave goodbye to friends and
family and drive north for two days. There, in
<a href="http://sv.wikipedia.org/wiki/%C3%96jebyn">a small town you&#8217;ve probably never heard of</a>, lies our new
home.</p>

<p>Naturally, this is quite a scary proposition for a city boy. I
honestly don&#8217;t know if I&#8217;ll make it up there. But I was given a great
opportunity, and I had to at least try. Besides, life in the city was
getting a bit <em>too</em> convenient, if you know what I mean? It was time
for a change.</p>

<p>Fortunately, my employer was keen to keep me on, which means that
starting two weeks from now I&#8217;ll be working 100% remotely. This is a
big change, and I hope it will work out for everyone involved. Our
team has started using <a href="http://www.pivotaltracker.com">PivotalTracker</a> and <a href="http://campirenow.com">Campfire</a>, and
the overall impression is good so far. However, I will be working from
my home office, and I just hope the cabin fever doesn&#8217;t get
unbearable.</p>

<p>Another big change is that I&#8217;ll just be working 80%. Living in the
northern parts of Sweden is pretty cheap, and after doing the math we
decided that it wasn&#8217;t really necessary for me to work full time
anymore. Instead, I&#8217;ll try to spend the extra time on fun personal
projects, without having to worry about them earning me any money
(although it would be nice if they did).</p>

<p>I&#8217;ve been longing to give game development a shot for a long time now,
and this is kind of my big chance. For a guy with my background the
obvious choice seems to be mobile game development with Android, and I
already have some ideas to work on. I&#8217;m also really intrigued by what
can be done with <a href="http://lispgamesdev.blogspot.com/">Common Lisp</a>, which I believe could make
for a great interactive game environment. However, my first
goal is to finish my <a href="http://mulli.nu/2011/02/11/fun-with-inform7.html">Inform 7 game</a>, hopefully being able to
enter it into <a href="http://www.ifcomp.org/">IFComp 2011</a>. Watch this space.</p>

<p>You know, I have a good feeling about this.</p>
]]></content>
  </entry>
  
</feed>
