<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jayway Team Blog &#187; Anders Janmyr</title>
	<atom:link href="http://blog.jayway.com/author/andersjanmyr/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Sun, 05 Sep 2010 20:32:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using Git with Subversion</title>
		<link>http://blog.jayway.com/2010/09/02/using-git-with-subversion/</link>
		<comments>http://blog.jayway.com/2010/09/02/using-git-with-subversion/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 07:45:26 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=6260</guid>
		<description><![CDATA[I had the unfortunate experience of having to use Subversion again after using Git for a long time. It is amazing how fast I can forget. After renaming a directory at the prompt, and the agony that goes with it, I decided to switch back to Git. $ mv requester sampler # svn agony after [...]]]></description>
			<content:encoded><![CDATA[<p>I had the unfortunate experience of having to use Subversion again after using Git for a long time. It is amazing how fast I can forget. After renaming a directory at the prompt, and the agony that goes with it, I decided to switch back to Git.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ mv requester sampler
<i><font color="#9A1900"># svn agony after renaming a directory</font></i>
$ svn st
<font color="#990000">?</font>       sampler
<font color="#990000">!</font>       requester
<font color="#990000">!</font>       requester<font color="#990000">.</font>rb
A       sampler<font color="#990000">.</font>rb

</tt></pre>
<p>The tool to use when using Git with Subversion is, of course, <code>git svn</code>.</p>
<p><code>git svn</code> works very well as long as you remember that <em>Subversion is not Git</em>. It does not handle merging well, and it will bite you if you don't respect that. So what does this actually mean? It means:</p>
<h2>Always keep the Git master in sync with Subversion</h2>
<p>To do this you have two commands you can use.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Rebases the commits from the upstream Subversion server with your local master.</font></i>
$ git svn rebase

</tt></pre>
<p>You should only <code>git svn rebase</code> in your Git master, and you should <strong>ALWAYS</strong> do it before you <code>git svn dcommit</code> anything to the subversion repository. <code>git svn rebase</code> keeps the upstream subversion in sync with your local master by pulling down the changes, kind of like <code>svn update</code>.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Commits the changes you have in your local master to the upstream Subversion server.</font></i>
$ git svn dcommit

</tt></pre>
<p>When you have changes ready to commit, you commit them to subversion with <code>git svn dcommit</code>. You should <strong>ALWAYS</strong> <code>git svn rebase</code> before you do the update, or it will fail.</p>
<p>That's it! As long as you follow these two simple rules, your life with <code>git svn</code> will be easy. If you forget to follow them, you will be bitten. When you get bitten, the cool thing about Git is that even if you screw up, it is always possible to sort it out.</p>
<p>It that was all there was to it, there would be no reason to use Git instead of Subversion. Git really shines when it comes to branching and merging. You may create as many local branches as you like with <code>git branch branch_name</code> or <code>git checkout -b branch_name</code>. You can hack around in these local branches as much as you want and merge them together. But, before you merge them into the master branch, <strong>you must rebase with master! Not merge, rebase!</strong> Rebase means replay the commits on top of the named branch. It creates new commits, the same content, but with a different SHA-1.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Example session</font></i>

<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn rebase
<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout -b dev
hack<font color="#990000">,</font> hack<font color="#990000">,</font> hack<font color="#990000">,</font> <font color="#990000">...</font>
<font color="#990000">(</font>dev<font color="#990000">)</font>$ git commit -am <font color="#FF0000">'Commit the changes'</font> 

<font color="#990000">(</font>dev<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout -b bugfix
hack<font color="#990000">,</font> hack<font color="#990000">,</font> hack<font color="#990000">,</font> <font color="#990000">...,</font> <b><font color="#0000FF">done</font></b>

<font color="#990000">(</font>bugfix<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn rebase
<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout bugfix
$ git rebase master
<font color="#990000">(</font>bugfix<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git merge --ff bugfix <i><font color="#9A1900"># --ff only fast-forwards, merges that don't need to merge. </font></i>
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit
<font color="#990000">(</font>master<font color="#990000">)</font>$ git branch -D bugfix <i><font color="#9A1900"># delete the branch it is not needed anymore</font></i>

<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout dev
hack<font color="#990000">,</font> hack<font color="#990000">,</font> hack<font color="#990000">,</font> <font color="#990000">...,</font> <b><font color="#0000FF">done</font></b>

<font color="#990000">(</font>dev<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn rebase
<font color="#990000">(</font>master<font color="#990000">)</font>$ git checkout dev
<font color="#990000">(</font>dev<font color="#990000">)</font>$ git rebase master
<font color="#990000">(</font>dev<font color="#990000">)</font>$ git checkout master
<font color="#990000">(</font>master<font color="#990000">)</font>$ git merge --ff dev <i><font color="#9A1900"># --ff only fast-forwards, merges that don't need to merge.</font></i>
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit

</tt></pre>
<p>Another thing to be aware of is that <code>git svn dcommit</code> creates an extra commit, so even if you haven't changed anything in the master you need to rebase the local branch with the master. This is only needed if you don't delete the branches after you are done with a commit.</p>
<p>In the example above, I ended with a <code>git svn dcommit</code> and I didn't remove the <code>dev</code> branch.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit <i><font color="#9A1900"># from above</font></i>
<font color="#990000">(</font>master<font color="#990000">)</font>$ git co dev
<font color="#990000">(</font>dev<font color="#990000">)</font>$ git rebase master <i><font color="#9A1900"># rebases the extra commit created by git svn dcommit</font></i>

</tt></pre>
<p>If you forget to rebase or something else happens that hinders a clean merge into the master. You can always back out of it with <code>git reset --hard</code>.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit
<font color="#990000">...</font> failed miserably<font color="#990000">,</font> because I failed to git svn rebase<font color="#990000">,</font> bollocks<font color="#990000">!</font>
<font color="#990000">(</font>aa<font color="#990000">..</font>88dd<font color="#990000">|</font>MERGING<font color="#990000">)</font>$ git reset --hard
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn rebase
<font color="#990000">(</font>master<font color="#990000">)</font>$ git svn dcommit <i><font color="#9A1900"># Nice and clean commit</font></i>

</tt></pre>
<p>To get started you need to clone a subversion repository.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ git svn clone http<font color="#990000">:</font>//svn<font color="#990000">.</font>example<font color="#990000">.</font>com/project/trunk
$ cd trunk
<font color="#990000">(</font>master<font color="#990000">)</font>$ git <font color="#990000">...</font>

</tt></pre>
<p>Now, is a good time to start using Git. Get yourself anything by Scott Chacon, such as the <a href="http://www.amazon.com/Pro-Git-Scott-Chacon/dp/1430218339?tag=thtasta-20">book</a> or the <a href="http://www.gitcasts.com/">screencasts</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/09/02/using-git-with-subversion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Ruby Toolbox</title>
		<link>http://blog.jayway.com/2010/08/26/the-ruby-toolbox/</link>
		<comments>http://blog.jayway.com/2010/08/26/the-ruby-toolbox/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 13:12:55 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=6166</guid>
		<description><![CDATA[One of the great things about Ruby is the community. When something is not working out as well as it could, someone figures out a way to improve it. It used to be difficult to select what gems, Ruby libraries, to use when solving a task that I was not familiar with. This is not [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great things about Ruby is the community. When something is not working out as well as it could, someone figures out a way to improve it.</p>
<p>It used to be difficult to select what gems, Ruby libraries, to use when solving a task that I was  not familiar with. This is not the case anymore.<br />
<a href="http://colszowka.heroku.com">Christoph Olszowka</a> decided that he wanted to solve this problem and created <a href="http://ruby-toolbox.com/">The Ruby Toolbox</a>.</p>
<blockquote><p><a href="http://ruby-toolbox.com/">The Ruby Toolbox</a>, <strong>Know your options!</strong></p>
<p>Ruby developers can choose from a variety of tools to get their job done.</p>
<p>The Ruby Toolbox gives you an overview of these tools, sorted in categories and rated by the amount of watchers and forks in the corresponding source code repository on GitHub so you can find out easily what options you have and which are the most common ones in the Ruby community.</p>
</blockquote>
<p>This is surprisingly powerful. In my latest project I used the following libraries (among others).</p>
<h2><a href="http://ruby-toolbox.com/categories/web_app_frameworks.html#rails_rails">Rails</a></h2>
<p>Rails need no introduction, it is one of the best frameworks for creating dynamic web applications. With best, I mean most productive and fun to work with!</p>
<h2><a href="http://ruby-toolbox.com/categories/template_languages.html#nex3_haml">Haml</a></h2>
<p>Haml (HTML Abstraction Markup Language) is a layer on top of XHTML or XML that's designed to express the structure of XHTML or XML documents in a non-repetitive, elegant, easy way!</p>
<h2><a href="http://www.ruby-toolbox.com/categories/http_clients.html#pauldix_typhoeus">Typhoeus</a></h2>
<p>Typhoeus is a http client library, a thick wrapper around curl, just like curl it works like a charm.</p>
<h2><a href="http://www.ruby-toolbox.com/categories/deployment_automation.html#jamis_capistrano">Capistrano</a></h2>
<p>Ahh, Capistrano, deployment scripting done right! The simplicity of the structure is worth showing since it should be copied by other lesser tools.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900"># Create the basic structure</font></i>
$ cap deploy<font color="#990000">:</font>setup
mkdir -p /var/rails/rsvc
/var/rails/rsvc/releases
/var/rails/rsvc/shared
<font color="#990000">...</font>

<i><font color="#9A1900"># Deploy from the repo into a timestamped release directory and symlink current</font></i>
$ cap deploy
svn checkout -q  -r<font color="#993399">5454</font> https<font color="#990000">:</font>//svn<font color="#990000">.</font>neo4j<font color="#990000">.</font>org/qa/matrix-framework/rsvc/trunk/rsvc /var/rails/rsvc/releases<font color="#990000">/</font><font color="#993399">20100826122450</font>
echo <font color="#993399">5454</font> <font color="#990000">&gt;</font> /var/rails/rsvc/releases<font color="#990000">/</font><font color="#993399">20100826122450</font>/REVISION
<font color="#990000">....</font>
rm -f /var/rails/rsvc/current <font color="#990000">&amp;&amp;</font> ln -s /var/rails/rsvc/releases<font color="#990000">/</font><font color="#993399">20100826122450</font> /var/rails/rsvc/current

</tt></pre>
<p>It's so simple and powerful, that it makes me cry.</p>
<h2><a href="http://www.ruby-toolbox.com/categories/server_monitoring.html#mojombo_god">God</a></h2>
<p>God, a wonderfully named, server monitoring tool written in Ruby. God aims to be the simplest, most powerful monitoring application available.</p>
<h2><a href="http://www.ruby-toolbox.com/categories/testing_frameworks.html#dchelimsky_rspec">RSpec</a></h2>
<p>RSpec, only code can do it justice.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>describe Request <b><font color="#0000FF">do</font></b>

  before <b><font color="#0000FF">do</font></b>
    <font color="#009900">@sample</font> <font color="#990000">=</font> Sample<font color="#990000">.</font>create<font color="#990000">(:</font>name <font color="#990000">=&gt;</font> <font color="#FF0000">'my_sample'</font><font color="#990000">,</font> <font color="#990000">:</font>method <font color="#990000">=&gt;</font> <font color="#FF0000">"post"</font><font color="#990000">)</font>
  <b><font color="#0000FF">end</font></b>

  context <font color="#FF0000">'#old'</font> <b><font color="#0000FF">do</font></b>
    it <font color="#FF0000">"should not return any"</font> <b><font color="#0000FF">do</font></b>
      Request<font color="#990000">.</font>old<font color="#990000">.</font>should be_empty
    <b><font color="#0000FF">end</font></b>
    <font color="#990000">...</font>
  <b><font color="#0000FF">end</font></b>

  context <font color="#FF0000">'#delete_old_non_failing'</font> <b><font color="#0000FF">do</font></b>

    it <font color="#FF0000">"should delete old non failing requests"</font> <b><font color="#0000FF">do</font></b>
      create_old_request <font color="#990000">:</font>response_status_code <font color="#990000">=&gt;</font> <font color="#993399">0</font>
      create_old_request <font color="#990000">:</font>response_status_code <font color="#990000">=&gt;</font> <font color="#993399">200</font>
      expect <font color="#FF0000">{</font>
        Request<font color="#990000">.</font>delete_old_non_failed
      <font color="#FF0000">}</font><font color="#990000">.</font>to change <font color="#FF0000">{</font> Request<font color="#990000">.</font>count <font color="#FF0000">}</font><font color="#990000">.</font>by<font color="#990000">(-</font><font color="#993399">2</font><font color="#990000">)</font>
    <b><font color="#0000FF">end</font></b>
    <font color="#990000">...</font>
  <b><font color="#0000FF">end</font></b>

  <font color="#990000">...</font>
<b><font color="#0000FF">end</font></b>

</tt></pre>
<p>Does your language have a Toolbox? Perhaps it is time to create one, or to switch to another language?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/08/26/the-ruby-toolbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Good Practices for Rich Web Applications</title>
		<link>http://blog.jayway.com/2010/08/16/good-practices-for-rich-web-applications/</link>
		<comments>http://blog.jayway.com/2010/08/16/good-practices-for-rich-web-applications/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 05:54:53 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=6046</guid>
		<description><![CDATA[Use jQuery jQuery is the best thing that has happened to Javascript since it got first class functions in version 1.2. The library is elegant, powerful and has exactly the right level of abstraction for working with the DOM. There is nothing more to say. Learn it and use it. Good resources are: the jQuery [...]]]></description>
			<content:encoded><![CDATA[<h2>Use jQuery</h2>
<p>jQuery is the best thing that has happened to Javascript since it got first class functions in version 1.2. The library is elegant, powerful and has exactly the right level of abstraction for working with the DOM. There is nothing more to say. Learn it and use it. Good resources are: <a href="http://api.jquery.com/l">the jQuery API</a>, <a href="http://dl.dropbox.com/u/7283184/jquery-api-1.4.2.html">my view of the jQuery API</a></p>
<h2>Learn Javascript</h2>
<p>Javascript is the <a href="http://oredev.org/2010/sessions/javascript-the-language-of-the-web">programming language of the web</a>. Learn it! Javascript is different from most other programming languages. It is dynamic, it has prototypical inheritance, and works more like Scheme than any of the languages that you are probably used to. If you want to learn Javascript you should get the following books, <a href="http://www.amazon.com/gp/product/0262560992?tag=thtasta-20">The Little Schemer</a>, <a href="http://www.amazon.com/gp/product/026256100X?tag=thtasta-20">The Seasoned Schemer</a>, <a href="http://www.amazon.com/gp/product/0596517742?tag=thtasta-20">Javascript, the Good Parts</a>, and possibly <a href="http://www.amazon.com/Performance-JavaScript-Faster-Application-Interfaces/dp/059680279X?tag=thtasta-20">High Performance Javascript</a></p>
<h2>Learn CSS</h2>
<p>Many programmers think that CSS is the language of designers and not programmers. This is not the case at all. If you are lucky enough to have a designer on your team (most people don't), CSS is the language with which you communicate. It is the interface between designers and programmers and as a programmer you should know it better than the designers. By knowing CSS well you will reduce the misunderstandings between you and your designer.</p>
<p>Unfortunately, many designers don't care about how code looks, as long as the design looks good on the surface. It will be up to you to make sure that the CSS doesn't get out out of hand. It will also be up to you to keep the HTML clean, and a good way to do this is to use semantic HTML, combined with CSS. You have no idea what the designers can come up with.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- </font></i>
<i><font color="#9A1900">  Old School rounded corners, invented by a GOOD designer. </font></i>
<i><font color="#9A1900">  All this code was actually needed to achieve the purpose.</font></i>
<i><font color="#9A1900">  --&gt;</font></i>
<b><font color="#0000FF">&lt;style&gt;</font></b>
<font color="#993399">.t</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">dot.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">repeat-x</font></i>; <font color="#0000FF">width:</font> <i><font color="#009900">20em</font></i><font color="#FF0000">}</font>
<font color="#993399">.b</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">dot.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">100%</font></i> <i><font color="#009900">repeat-x</font></i><font color="#FF0000">}</font>
<font color="#993399">.l</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">dot.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">repeat-y</font></i><font color="#FF0000">}</font>
<font color="#993399">.r</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">dot.gif</font></i>) <i><font color="#009900">100%</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">repeat-y</font></i><font color="#FF0000">}</font>
<font color="#993399">.bl</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">bl.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">100%</font></i> <i><font color="#009900">no-repeat</font></i><font color="#FF0000">}</font>
<font color="#993399">.br</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">br.gif</font></i>) <i><font color="#009900">100%</font></i> <i><font color="#009900">100%</font></i> <i><font color="#009900">no-repeat</font></i><font color="#FF0000">}</font>
<font color="#993399">.tl</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">tl.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">no-repeat</font></i><font color="#FF0000">}</font>
<font color="#993399">.tr</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">tr.gif</font></i>) <i><font color="#009900">100%</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">no-repeat</font></i>; <font color="#0000FF">padding:</font><i><font color="#009900">10px</font></i><font color="#FF0000">}</font>
<b><font color="#0000FF">&lt;/style&gt;</font></b>
<b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"t"</font><b><font color="#0000FF">&gt;</font></b>
  <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"b"</font><b><font color="#0000FF">&gt;</font></b>
    <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"l"</font><b><font color="#0000FF">&gt;</font></b>
      <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"r"</font><b><font color="#0000FF">&gt;</font></b>
        <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"bl"</font><b><font color="#0000FF">&gt;</font></b>
          <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"br"</font><b><font color="#0000FF">&gt;</font></b>
            <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"tl"</font><b><font color="#0000FF">&gt;</font></b>
              <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"tr"</font><b><font color="#0000FF">&gt;</font></b>
                Lorem ipsum dolor sit amet consectetur adipisicing elit
              <b><font color="#0000FF">&lt;/div&gt;</font></b>
            <b><font color="#0000FF">&lt;/div&gt;</font></b>
          <b><font color="#0000FF">&lt;/div&gt;</font></b>
        <b><font color="#0000FF">&lt;/div&gt;</font></b>
      <b><font color="#0000FF">&lt;/div&gt;</font></b>
    <b><font color="#0000FF">&lt;/div&gt;</font></b>
  <b><font color="#0000FF">&lt;/div&gt;</font></b>
<b><font color="#0000FF">&lt;/div&gt;</font></b>

</tt></pre>
<p>As an additional benefit you will become better at jQuery. Not only is CSS the query language of the browsers it is the query language of jQuery. Jariba!</p>
<p><a href="http://www.amazon.com/Bulletproof-Web-Design-flexibility-protecting/dp/0321509021?tag=thtasta-20">Bulletproof Web Design</a> is a good book web design, including CSS.</p>
<h2>Decide how "Rich" your application should be</h2>
<p>How rich should your application be? The scale varies from no Javascript to only Javascript, but you will probably want to land somewhere in between. Here are a few suggestions.</p>
<ul>
<li>No Javascript, everything is server generated.</li>
<li>Slightly enhanced pages, simple validations, but no Ajax.</li>
<li>Ajax enhanced pages, but every page still reloads frequently.</li>
<li>Single page per area, entire area is handled by Javascript.</li>
<li>Only Javascript, Ajax interaction with the server</li>
<li>Only Javascript, no interaction with the server.</li>
</ul>
<p>The important thing is to <em>make a decision</em>. If you don't make the decision, everyone will do different things on different parts of the application and you will loose consistency. In GUI, consistency is king. Make a decision and move on, you can always change your decision later.</p>
<h2>Organize your code</h2>
<h3>Javascript</h3>
<p>Make sure that all your Javascript code is namespaced properly. It is impolite to pollute the global namespace and it will bite you in the end. A simple variable declaration will do.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// Common namespace for your entire application</font></i>
<i><font color="#9A1900">// This declaration lets you split your code of multiple files.</font></i>
<i><font color="#9A1900">// If MyNamespace is defined use it, otherwise declare it.</font></i>
MyNamespace <font color="#990000">=</font> MyNamespace <font color="#990000">||</font> <font color="#FF0000">{}</font><font color="#990000">;</font>

</tt></pre>
<p>But, of course, it is also possible to get fancy and encapsulate the functions that you don't want to expose, if that is your cup of tea.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>MyNamespace <font color="#990000">=</font> MyNamespace <font color="#990000">||</font> <font color="#FF0000">{}</font><font color="#990000">;</font>

MyNamespace<font color="#990000">.</font>Tournament <font color="#990000">=</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
	<i><font color="#9A1900">// Private stuff</font></i>
	<b><font color="#0000FF">var</font></b> tournamentCount <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
	<b><font color="#0000FF">function</font></b> <b><font color="#000000">addTournament</font></b><font color="#990000">(</font>tournament<font color="#990000">)</font> <font color="#FF0000">{</font>
		tournamentCount<font color="#990000">++;</font>
	<font color="#FF0000">}</font>

	<b><font color="#0000FF">return</font></b> <font color="#FF0000">{</font>
		<i><font color="#9A1900">//public stuff</font></i>
		numberOfTournaments<font color="#990000">:</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
			<b><font color="#0000FF">return</font></b> tournamentCount<font color="#990000">;</font>
		<font color="#FF0000">}</font>
	<font color="#FF0000">}</font>
<font color="#FF0000">}</font><font color="#990000">();</font>

</tt></pre>
<p>You should also separate your Javascript code into different files. The namespace idiom above helps to have the same namespace across multiple files. The same principles as with other type of code is valid with Javascript, organize the code by area, when it changes, where it is used, etc. Don't be afraid of the additional load time, splitting the files will give you. The files can easily be concatenated with tools  like <a href="http://rake.rubyforge.org/">Rake</a>, <a href="http://www.scons.org/">SCons</a>,  <a href="http://ant.apache.org/">Ant</a> or even a simple:</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ cat file1<font color="#990000">.</font>js file2<font color="#990000">.</font>js file3<font color="#990000">.</font>js <font color="#990000">&gt;</font> all<font color="#990000">.</font>js

</tt></pre>
<p>They can also be compressed with <a href="http://www.crockford.com/javascript/jsmin.html">JSMin</a> or <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>.</p>
<p><em>Optimize your environment for development, not for production!</em></p>
<h3>HTML</h3>
<p>HTML is code! Divide your pages into partials by responsibilities. It allows you to keep your pages DRY and readable. <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">The Single Responsibility Principle</a> applies to HTML too.</p>
<p>Make sure you keep the Javascript with the code that it manipulates. If you, for example, have a calendar partial that uses <a href="http://jqueryui.com/demos/datepicker/">jQuery DatePicker</a>, you have to make sure that the partial includes all the necessary Javascript to configure the calendar. Don't keep Javascript code in the page away from the partial. <a href="http://c2.com/cgi/wiki?CommonClosurePrinciple">Things that change together should be together</a>.</p>
<h3>CSS</h3>
<p>Stylesheets are code too. They should also be split into areas that allow you to easily find and navigate them. Use <a href="http://sass-lang.com/">Sass or SCCS</a> to keep your CSS files DRY. Sass is good for designers to. It gives them the ability to use variable names, mixins, etc. and simplifies their usage of semantic names such as <em>notice</em>, and <em>sidebar</em> instead of <em>yellow</em> and <em>left</em>.</p>
<p><em>Optimize your environment for development, not for production!</em></p>
<h2>Separate your Javascript from your HTML</h2>
<p>All too often I see generated HTML pages with Javascript code in them. Don't do it. Keep the HTML free from Javascript.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- DON'T DO THIS!  --&gt;</font></i>
<b><font color="#0000FF">&lt;button</font></b> <font color="#009900">id</font><font color="#990000">=</font><font color="#FF0000">'update-button'</font> <font color="#009900">onclick</font><font color="#990000">=</font><font color="#FF0000">"MyNamespace.updateList();"</font><b><font color="#0000FF">&gt;</font></b>Update List<b><font color="#0000FF">&lt;/button&gt;</font></b>

</tt></pre>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// In the Javascript file for the page.</font></i>
MyNamespace<font color="#990000">.</font>updateList <font color="#990000">=</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font><font color="#990000">...</font><font color="#FF0000">}</font>

<font color="#990000">&lt;!--</font> DO THIS<font color="#990000">!</font> <font color="#990000">--&gt;</font>
<font color="#990000">&lt;</font>button id<font color="#990000">=</font><font color="#FF0000">'update-button'</font><font color="#990000">&gt;</font>Update List<font color="#990000">&lt;/</font>button<font color="#990000">&gt;</font>

</tt></pre>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// In the Javascript file for the page.</font></i>
MyNamespace<font color="#990000">.</font>updateList <font color="#990000">=</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font><font color="#990000">...</font><font color="#FF0000">}</font>

$<font color="#990000">(</font><b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
  $<font color="#990000">(</font><font color="#FF0000">"#update-button"</font><font color="#990000">).</font><b><font color="#000000">click</font></b><font color="#990000">(</font><b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
    MyNamespace<font color="#990000">.</font><b><font color="#000000">updateList</font></b><font color="#990000">();</font>
  <font color="#FF0000">}</font><font color="#990000">);</font>
<font color="#FF0000">}</font><font color="#990000">);</font>

</tt></pre>
<p>It may seem like there is a lot more code in the good example, but notice the symmetry. The code that attaches the listener is in the same file as the code that uses the listener. This is good. Symmetry is good.</p>
<h3>Use clone()</h3>
<p>Separating the HTML and the Javascript goes both ways. Don't generate HTML code in Javascript. It doesn't matter that it is super simple to do it using <em>jQuery.html()</em>. Keep them separate, use <em>jQuery.clone()</em> instead.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// DON'T DO THIS</font></i>
$<font color="#990000">(</font><font color="#FF0000">"&lt;li data-id='123'&gt;My new item&lt;/li&gt;"</font><font color="#990000">).</font><b><font color="#000000">appendTo</font></b><font color="#990000">(</font><font color="#FF0000">"ul"</font><font color="#990000">);</font>
<i><font color="#9A1900">// OR THIS</font></i>
$<font color="#990000">(</font><font color="#FF0000">"ul"</font><font color="#990000">).</font><b><font color="#000000">append</font></b><font color="#990000">(</font><font color="#FF0000">"&lt;li data-id='123'&gt;My new item&lt;/li&gt;"</font><font color="#990000">);</font>

</tt></pre>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- DO THIS --&gt;</font></i>
<b><font color="#0000FF">&lt;ul&gt;</font></b>
<b><font color="#0000FF">&lt;li</font></b> <font color="#009900">id</font><font color="#990000">=</font><font color="#FF0000">"list-template"</font> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"template"</font><b><font color="#0000FF">&gt;</font></b>All .template are hidden (display: none) in the CSS<b><font color="#0000FF">&lt;/li&gt;</font></b>
<b><font color="#0000FF">&lt;/ul&gt;</font></b>

</tt></pre>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// AND THIS</font></i>
<b><font color="#0000FF">var</font></b> $clone <font color="#990000">=</font> $<font color="#990000">(</font><font color="#FF0000">"#list-template"</font><font color="#990000">).</font><b><font color="#000000">clone</font></b><font color="#990000">();</font>
$clone<font color="#990000">.</font><b><font color="#000000">attr</font></b><font color="#990000">(</font><font color="#FF0000">"data-id"</font><font color="#990000">,</font> <font color="#FF0000">"123"</font><font color="#990000">).</font><b><font color="#000000">text</font></b><font color="#990000">(</font><font color="#FF0000">"My new item"</font><font color="#990000">).</font><b><font color="#000000">removeClass</font></b><font color="#990000">(</font><font color="#FF0000">"template"</font><font color="#990000">);</font>
$<font color="#990000">(</font><font color="#FF0000">"ul"</font><font color="#990000">).</font><b><font color="#000000">append</font></b><font color="#990000">(</font>$clone<font color="#990000">);</font>

</tt></pre>
<p>The point of this is, again, to keep the HTML separate from the Javascript.</p>
<h2>Decide how content flows between, the page, Javascript and the Server.</h2>
<p>Once you have decided how rich your application should be, you have to decide on a method for moving the data between the HTML Page, Javascript and the Server. My preferred choice is to have every page that is served from the server include a <em>context object</em> with all the static data for the page and to have additional data that belongs to parts of the page be sent as <em>data-attributes</em> on the elements concerned.</p>
<p>The context object will contain all the data that is commonly needed in the page.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// Sample context object that is generated with the page.</font></i>
MyNamespace <font color="#990000">=</font> MyNamespace <font color="#990000">||</font> <font color="#FF0000">{}</font><font color="#990000">;</font>
MyNamespace<font color="#990000">.</font>Context <font color="#990000">=</font> <font color="#FF0000">{</font>
  user<font color="#990000">:</font> <font color="#FF0000">{</font>
    id<font color="#990000">:</font> <font color="#FF0000">"28"</font><font color="#990000">,</font>
    name<font color="#990000">:</font> <font color="#FF0000">"Anders Janmyr"</font>
  <font color="#FF0000">}</font><font color="#990000">,</font>
  tournament<font color="#990000">:</font> <font color="#FF0000">{</font>
    id<font color="#990000">:</font> <font color="#FF0000">"78344"</font><font color="#990000">,</font>
    name<font color="#990000">:</font> <font color="#FF0000">"Fifa World Cup"</font>
  <font color="#FF0000">}</font>
<font color="#FF0000">}</font><font color="#990000">;</font>
</tt></pre>
<p>I use the context object(s) to keep state on the client to. If it is important that the page looks exactly the same, even if the user reloads the page, I make sure that the state I stick into my context object is synched back to the server. This can easily be done, asynchronously, with Ajax and does not affect performance noticeable.</p>
<p>Elements specific data is sent along with the element it defines.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- Element specific data attached to the elements with data-attributes --&gt;</font></i>
<b><font color="#0000FF">&lt;ul</font></b> <font color="#009900">id</font><font color="#990000">=</font><font color="#FF0000">"tournament-menu"</font><b><font color="#0000FF">&gt;</font></b>
  <b><font color="#0000FF">&lt;li</font></b> <font color="#009900">data-id</font><font color="#990000">=</font><font color="#FF0000">"78344"</font> <font color="#009900">data-participant-count</font><font color="#990000">=</font><font color="#FF0000">"64"</font><b><font color="#0000FF">&gt;</font></b>Fifa World Cup<b><font color="#0000FF">&lt;/li&gt;</font></b>
  <b><font color="#0000FF">&lt;li</font></b> <font color="#009900">data-id</font><font color="#990000">=</font><font color="#FF0000">"666"</font>  <font color="#009900">data-participant-count</font><font color="#990000">=</font><font color="#FF0000">"44"</font><b><font color="#0000FF">&gt;</font></b>Americas Cup<b><font color="#0000FF">&lt;/li&gt;</font></b>
  <b><font color="#0000FF">&lt;li</font></b> <font color="#009900">data-id</font><font color="#990000">=</font><font color="#FF0000">"1464"</font> <font color="#009900">data-participant-count</font><font color="#990000">=</font><font color="#FF0000">"32"</font><b><font color="#0000FF">&gt;</font></b>Rugby World Cup<b><font color="#0000FF">&lt;/li&gt;</font></b>
<b><font color="#0000FF">&lt;/ul&gt;</font></b>

</tt></pre>
<p>The same argument as with the context object applies, as soon as I change an element in the GUI i need to feed that information back to the server. With elements I usually send the information to the server before updating the GUI, since element specific data is usually permanent data and not just session data.</p>
<p>An alternative solution to the <em>context object</em> above is to use the body element as the data-container, like this:</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><b><font color="#0000FF">&lt;body</font></b> <font color="#009900">data-user-id</font><font color="#990000">=</font><font color="#FF0000">"28"</font> <font color="#009900">data-user-name</font><font color="#990000">=</font><font color="#FF0000">"Anders Janmyr"</font> <font color="#009900">data-tournament-id</font><font color="#990000">=</font><font color="#FF0000">"78344"</font> <font color="#009900">data-tournament-name</font><font color="#990000">=</font><font color="#FF0000">"Fifa World Cup"</font><b><font color="#0000FF">&gt;</font></b>

</tt></pre>
<p>I tend to use the context object because I find it easier to add functionality to it than to the DOM element.</p>
<p>Only send the data that is needed to the client with the page. The rest of the data should be loaded on demand, with Ajax. Both JSON data and HTML templates can be loaded on demand. There is no need to deliver the entire page at once. Experiment and do what gives the best user experience.</p>
<h2>Use file watchers to speed up feedback</h2>
<p>If you compare the feedback cycle of Javascript and HTML development to Java and C# development, you are probably very happy with the short, tight feedback loop. This doesn't mean that you should be content. A feedback cycle cannot be too short.</p>
<p><a href="http://xrefresh.binaryage.com/">xrefresh</a> for Firefox and IE, and <a href="http://github.com/mockko/livereload">LiveReload</a> for Safari and Chrome, are a couple of tools that will tighten your feedback loop even more.</p>
<p>Both tools are file watchers that listen to changes for files and refresh the browser when they change. If you combine this with two screens, you will have one screen for the browser, that updates continuously, while you edit your code on the other screen. Fabulous!</p>
<h2>Conclusion</h2>
<p>Rich web applications are very close to the traditional client-server model. We have to keep state on the client side to give the user a good experience. At the same time the application state, and indeed the entire application, can be swept away by a click of a button or a page reload.</p>
<p>This puts new demands on us as developers. We have to realize that we are responsible for the entire application, not just the business logic, but the HTML and CSS too. More that anything, we have to realize that Javascript is a first class programming language with its own programming techniques, which we need to master to be able to develop good web applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/08/16/good-practices-for-rich-web-applications/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>No Deadlines</title>
		<link>http://blog.jayway.com/2010/08/12/no-deadlines/</link>
		<comments>http://blog.jayway.com/2010/08/12/no-deadlines/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 05:15:58 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=5991</guid>
		<description><![CDATA[deadline, from New Oxford American Dictionary the latest time or date by which something should be completed : the deadline for submissions is February 5th. historical a line drawn around a prison beyond which prisoners were liable to be shot. Deadlines in software development induce unnecessary stress, and transform otherwise enjoyable activities into chores. We [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>deadline</strong>, from New Oxford American Dictionary</p>
<ol>
<li>
<p>the latest time or date by which something should be completed : the deadline for submissions is February 5th.</p>
</li>
<li>
<p>historical a line drawn around a prison beyond which prisoners were liable to be shot.</p>
</li>
</ol>
</blockquote>
<p>Deadlines in software development induce unnecessary stress, and transform otherwise enjoyable activities into chores.</p>
<p>We need to replace deadlines with livelines. A liveline is a deployed, working version of a product. It is after the fact, a milestone set when you are done.</p>
<h2>How Deadlines Are Set</h2>
<p>Deadlines are set in different ways in different projects.</p>
<p>In the classic <a href="http://www.amazon.com/Death-March-2nd-Edward-Yourdon/dp/013143635X?tag=thtasta-20">Death March </a> project, a deadline is set by someone outside the project with no clue whatsoever about how long it will take. Typically this kind of deadline is based on some external event, where the project will be demonstrated. The event may be a conference, or something similar.</p>
<p>In Scrum, the deadlines are set by the process itself. Most Scrum projects I have worked with use a two week deadline instead of the recommended 30 days. The team decides how many stories they can complete by that deadline, based on rough estimations done in the sprint planning.</p>
<p>Some projects set deadlines by a developer being asked (or asking himself) when the task will be done. The developer will say: "I'll have it done by 3 o'clock", a wild guess.</p>
<p>The problem with all these approaches is that the deadlines are, <em>at best</em>, based on guesses of the team doing the development. But guesses are guesses, not something you can set a deadline by.</p>
<p>And deadlines work both ways, a task is <em>very</em> rarely completed before it's deadline.</p>
<h2>Kinds of Deadlines</h2>
<h3>Real Deadlines</h3>
<p>If a task is not completed by a certain time someone will die. This kind of task is really common in novels and movies. A clock is ticking and if the task is not completed by the time the clock reaches zero, BOOM!</p>
<p>If have never seen this kind of deadline in software development, but they may exist.</p>
<h3>Planning Deadlines</h3>
<p>Some deadlines are set in order to simplify planning. In the large Death March projects, the plan is to show the project at a certain date. In integration projects, the deadlines are set to be able to synchronize with other teams working on the same product.</p>
<p>This kind of deadlines are actually understandable, but I am arguing that they actually slow down projects by introducing stress, which introduces bugs. The bugs introduce bugs in the dependent projects, and slows down many projects instead of just one.</p>
<h3>Motivational Deadlines</h3>
<p>Motivation deadlines are set to get people to work. The assumption is that if a deadline is not set people will procrastinate over different ideas, or just slack off since there is no date set for the release anyway.</p>
<p>This is, absolutely, the worst kind of deadline. If the team is not motivated enough to do a good job without a deadline, you need to get a new team, not set a deadline.</p>
<h2>Why Deadlines Are Bad</h2>
<h3>Stress</h3>
<p>Consider walking on a one foot wide plank. If it is on the ground it is easy. If it is two meters up it is difficult, but if you put it at twenty meters it is a whole different ballgame. That is what its like with deadlines, they put an unnecessary pressure on people.</p>
<h3>Loss of Motivation</h3>
<blockquote><p><em>Work</em> consist of whatever a body is obliged to do, and <em>play</em> consists of whatever one is not obliged to do. -- Mark Twain</p>
</blockquote>
<p>In his book, <a href="http://www.amazon.com/Drive-Surprising-Truth-About-Motivates/dp/1594488843?tag=thtasta-20">Drive</a>, Dan Pink differentiates between <em>intrinsic</em> motivation and <em>extrinsic</em> motivation.</p>
<p>Extrinsic motivation is motivation driven by carrots and sticks, rewards and punishment. It works well for simple, well-defined tasks.</p>
<p>Intrinsic motivation works well for creative, ill-defined tasks, like programming.</p>
<p>Intrinsic motivation is fragile, <em>it disappears in the presence of carrots and sticks</em>. A deadline is a stick, whether set by ourselves or someone else.</p>
<h2>Livelines</h2>
<p>A liveline is, quite simply, a task that is done. When a task is done, it is easy for others to use it, in their plans or in reality. If we want to build a stable house, we should build it on stable ground.</p>
<p>When using livelines the iteration length is the same length as a task. This is usually a lot shorter than the usual one to four weeks common in Scrum and other agile methods. It also leads to variations in the iteration length.</p>
<p>If you implement your task all the way into production, you get <a href="http://timothyfitz.wordpress.com/2009/02/10/continuous-deployment-at-imvu-doing-the-impossible-fifty-times-a-day/">Continuous Deployment</a> or <a href="http://www.amazon.com/gp/product/0321601912?tag=thtasta-20">Continuous Delivery</a>. This puts a lot of pressure on your tooling and on automation but, I believe this is the way to go.</p>
<p>It is 2010, it is time to get rid of deadlines.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/08/12/no-deadlines/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Ruby and Rails Summer Reading</title>
		<link>http://blog.jayway.com/2010/06/20/ruby-and-rails-summer-reading/</link>
		<comments>http://blog.jayway.com/2010/06/20/ruby-and-rails-summer-reading/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 06:26:49 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=5782</guid>
		<description><![CDATA[If you ask a Ruby programmer why he is using Ruby, you will probably get several answers like: It is dynamic. I allows me too keep my code DRY. I get results faster. Aside from all these statements, there is one statement that almost always comes up. I use Ruby because it makes me happy! [...]]]></description>
			<content:encoded><![CDATA[<p>If you ask a Ruby programmer why he is using Ruby, you will probably get several answers like: It is dynamic. I allows me too keep my code DRY. I get results faster. Aside from all these statements, there is one statement that almost always comes up.</p>
<blockquote><p><strong>I use Ruby because it makes me happy!</strong></p>
</blockquote>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" src="http://3.bp.blogspot.com/_ELioussa2vo/TB2yZpIl5XI/AAAAAAAAAfw/vCZCP2XcwZE/s320/smiley.jpg" /></div>
<p>If you search Amazon for Ruby you get 8,829 Results and if you search for Rails you get<br />
14,113 Results. What books should you get?</p>
<p>Here are the books I recommend:</p>
<h2>Ruby</h2>
<p><a href="http://www.amazon.com/Beginning-Ruby-Novice-Professional/dp/1590597664?tag=thtasta-20">Beginning Ruby</a> is a superb book for people coming new to Ruby.</p>
<p>If you are not a complete novice, you should instead go for<br />
<a href="http://www.amazon.com/Well-Grounded-Rubyist-David-Black/dp/1933988657?tag=thtasta-20">The Well Grounded Rybyist</a>.</p>
<p>When you have finished <em>the Well Grounded Rubyist</em>, you are ready for <a href="http://www.amazon.com/Metaprogramming-Ruby-Facets-Paolo-Perrotta/dp/1934356476/?tag=thtasta-20">Metaprogramming Ruby</a> where you learn metaprogramming techniques to help you keep your code DRY and readable.</p>
<h2>Rails</h2>
<p>Since Rails is currently being updated to version 3, there are not that many books available. I can recommend <a href="http://www.amazon.com/Rails-Way-Addison-Wesley-Professional-Ruby/dp/0321601661?tag=thtasta-20">The Rails3 Way</a>, currently only <a href="http://www.informit.com/store/product.aspx?isbn=0132480336">available as a Rough-Cut</a>.</p>
<p>The lack of updated books is not a problem. The <a href="http://guides.rails.info/getting_started.html">The Ruby on Rails Guides</a> are excellent. Make sure you select the edge version.</p>
<p>Even more information is available through the videos from <a href="http://en.oreilly.com/rails2010">Railsconf</a>, <a href="http://railsconf.blip.tv/rss/itunes/">subscribe to them in iTunes</a>. The first videos where published, the day after they were filmed. Fantastic!</p>
<p>Have a happy Ruby-red summer.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/06/20/ruby-and-rails-summer-reading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Seamless Web Development</title>
		<link>http://blog.jayway.com/2010/06/08/seamless-web-development/</link>
		<comments>http://blog.jayway.com/2010/06/08/seamless-web-development/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 19:48:36 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=5713</guid>
		<description><![CDATA[Do you remember the time before 9/11 when you could arrive to the airport 10 minutes before the plane's departure and just walk on to the plane. Now, you have to arrive at least an hour before the plane departs and you have to strip to get through a security. The security is just for [...]]]></description>
			<content:encoded><![CDATA[<p>Do you remember the time before 9/11 when you could arrive to the airport 10 minutes before the plane's departure and just walk on to the plane. Now, you have to arrive at least an hour before the plane departs and you have to strip to get through a security.</p>
<p>The security is just for show. I don't know how many times I have forgotten a bottle in my carry-on and I haven't noticed it until I unpacked the bag at home. There a number of ways to get a big bang for your bucks, that aren't checked at security</p>
<p><img src="http://imgs.xkcd.com/comics/bag_check.png" title="XKCD Bag Check" alt="XKCD Bag Check" /></p>
<p>So what does this have to do with web development? Web development in a compiled language is like traveling after the terrorist attacks. You have to go through a lot of time consuming controls that are, mostly, for show. This dramatically slows down your development speed.</p>
<p>Since I did my <a href="http://anders.janmyr.com/2010/04/aspnet-mvc-vs-rails3.html">comparison between Rails and .NET MVC</a> I have done a lot of coding in both environments, and my conclusion is that Rails is a lot faster to develop with than .NET MVC.</p>
<p>The reason for this is that .NET MVC puts up a lot of seams that hinders development.</p>
<h2>Seam #1, Runtime Development</h2>
<p>When I'm using Rails for development I very rarely restart the server. When I make a change to the view, controller, model or database,  the changes are visible on the next request. Immediate feedback!</p>
<p>In Visual Studio, there is something called "Edit and Continue", that you can set to allow you to make changes to the code while you are debugging. Mooah ha ha ha ha ha ha ha haaaaaaa! This sucks so bad that I cannot help bursting out in a crazy laughter. The flow disappears.</p>
<p><img src="http://2.bp.blogspot.com/_ELioussa2vo/TA5505v-TUI/AAAAAAAAAfg/fo658aXs84U/s320/Edit_and_continue.png" title="Edit and Continue in your face!" alt="Edit and Continue" /></p>
<p>If I make changes <em>to the view</em> I can continue, unless I make changes to the I18N resources, because these are obviously not mutable. WTF!</p>
<p>Sometimes it is actually possible to make changes to the code, but when you try to save the changes "Edit and Continue"'s big brother appears and smacks you in the head, and the flow is gone again!</p>
<p><img src="http://1.bp.blogspot.com/_ELioussa2vo/TA555qfu4AI/AAAAAAAAAfo/dfsQxw_s-H8/s1600/Edit_and_continue2.png" title="Mooah ha ha ha ha ha haaaaaaa!" alt="Edit and Continue2" /></p>
<p>There is really no <em>good</em> reason for this. I'm sure there are a number of technical reasons having to do with type safety and class reloading, but I don't care. Just reload everything, do it fast and unnoticeable!</p>
<h2>Seam #2, The Javascript Impedance Mismatch</h2>
<p>Hopefully everyone has realized that Javascript is the hottest thing in web development! A language that has been spat on, and laughed at, has become the most wide spread programming language in the world. It's available in every browser and on every programming platform.</p>
<p>I have been talking about the greatness of Javascript for a few years now and it is great to see when someone finally get it.</p>
<blockquote><p>"Its great, I just change this little thing, then click reload, and it works immediately!" -- A collegue, seeing the coolness of Javascript.</p>
</blockquote>
<p>Javascript is Lisp in C-clothing and Lisp is the language that God used to create the world.</p>
<p><img src="http://imgs.xkcd.com/comics/lisp.jpg" title="XKCD Lisp" alt="Lisp" /></p>
<p>OK, Javascript is cool, and we all use it, but what is this impedance mumbo jumbo? Since a large part of a modern web application will be developed in Javascript, when we move over to the server side and everything is static and compiled, we are in for a lot of frustration.</p>
<p><strong>Common Development Flow</strong></p>
<ul>
<li>Make a change to the GUI, in Javascript.</li>
<li>Reload</li>
<li>Make another change</li>
<li>Reload</li>
<li>Realizing that you need to change the controller for the next change.</li>
<li>Aaaaaaaaaarrrrrrrrrrrggggghhhhhhhh, I have to restart the application.</li>
<li>What was it that I was working on again? I'll go for a cup of coffee!</li>
</ul>
<p>This is the Javascript impedance mismatch. If you are developing in a dynamic language you expect it to work like this all the time. You get used to it. It is better!</p>
<p>With Rails and Ruby, you get the same flow on the backend as you do on the client. The static-dynamic mismatch is gone. (There is still a language mismatch, between Javascript and Ruby, but it is minuscule by comparison.)</p>
<h2>Seam #3, Cruft</h2>
<p>Compare the following two partials</p>
<p><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- BookedCustomer.aspx partial in .NET MVC--&gt;</font></i>
&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<b><font color="#0000FF">&lt;Bergqvists.Models.Booking&gt;</font></b>" %&gt;

<b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"view"</font><b><font color="#0000FF">&gt;</font></b>
    <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"customer title"</font><b><font color="#0000FF">&gt;</font></b>&lt;%= Html.ActionLink(Model.Customer.Fullname, "Details", "Customers", new { Id = Model.CustomerID}, null) %&gt;<b><font color="#0000FF">&lt;/div</font></b> <b><font color="#0000FF">&gt;</font></b>
    <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"status"</font><b><font color="#0000FF">&gt;</font></b>&lt;%= Html.Encode(Model.BookingStatus.Name) %&gt;<b><font color="#0000FF">&lt;/div</font></b> <b><font color="#0000FF">&gt;</font></b>
    <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"booking-date"</font><b><font color="#0000FF">&gt;</font></b>&lt;%=ViewRes.BookingStrings.BookedOn %&gt;
    &lt;%= string.Format("{0:D}", Model.BookingDate) %&gt;<b><font color="#0000FF">&lt;/div&gt;</font></b>

<b><font color="#0000FF">&lt;/div&gt;</font></b>
&lt;% Html.RenderPartial("BookingStatusLinks", Model);%&gt;

</tt></pre>
<p><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- _booked_customer.html.erb partial --&gt;</font></i>
<b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"view"</font><b><font color="#0000FF">&gt;</font></b>
    <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"customer title"</font><b><font color="#0000FF">&gt;</font></b>&lt;%= link_to customer.fullname, customer_path(customer)<b><font color="#0000FF">&lt;/div</font></b> <b><font color="#0000FF">&gt;</font></b>
    <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"status"</font><b><font color="#0000FF">&gt;</font></b>&lt;%= customer.booking_status.name %&gt;<b><font color="#0000FF">&lt;/div</font></b> <b><font color="#0000FF">&gt;</font></b>
    <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"booking-date"</font><b><font color="#0000FF">&gt;</font></b>&lt;%=t :booked_on %&gt;
    &lt;%= customer.booking_date, :format =&gt; :short %&gt; %&gt;<b><font color="#0000FF">&lt;/div&gt;</font></b>

<b><font color="#0000FF">&lt;/div&gt;</font></b>
&lt;%= render :booking_status_links, :locals =&gt; {:customer =&gt; customer} %&gt;

</tt></pre>
<p>As you can see the corresponding ERB is not much different, but at least everything in the code is meaningful. And what customer value does the first line bring?</p>
<p>  &lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;Bergqvists.Models.Booking>" %></p>
<p>Nada! Zilch! It is only there to please the compiler. Cruft!</p>
<p>Now, most Ruby programmers I know use HAML instead of ERB and this cleans the view up considerably.</p>
<p><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><font color="#990000">.</font>view
  <font color="#990000">.</font>customer<font color="#990000">.</font><font color="#009900">title</font><font color="#990000">=</font> link_to customer<font color="#990000">.</font>fullname<font color="#990000">,</font> customer_path<font color="#990000">(</font>customer<font color="#990000">)</font>
  <font color="#990000">.</font><font color="#009900">status</font><font color="#990000">=</font> customer<font color="#990000">.</font>booking_status<font color="#990000">.</font>name
  <font color="#990000">.</font>booking-date
    <font color="#990000">=</font> t <font color="#990000">:</font>booked_on
    <font color="#990000">=</font> customer<font color="#990000">.</font>booking_date<font color="#990000">,</font> <font color="#990000">:</font>format <font color="#990000">=&gt;</font> <font color="#990000">:</font>short

<font color="#990000">=</font> render <font color="#990000">:</font>booking_status_links<font color="#990000">,</font> <font color="#990000">:</font>locals <font color="#990000">=&gt;</font> {<font color="#990000">:</font>customer <font color="#990000">=&gt;</font> customer}

</tt></pre>
<p>Beautiful!</p>
<p>Comparing Haml with ASP is not really fair, since it is possible to use <a href="todo">NHaml</a> instead of ASP in .NET MVC, but no one I know does that, maybe I hang with the wrong .Net people. NHAML is great, please switch it to the default for .NET MVC.</p>
<p>The example above is in the view layer. But the cruft spreads all over the stack.</p>
<h2>Seam #4, Testing</h2>
<p>Testing is always an interesting topic. The number one reason testing is not done is that it is to cumbersome. In .NET MVC I find it painful to test the controller and view layers, to the extent that I don't do it. With Rails on the other hand, you are setup for test from the start.</p>
<p>I always try to put as much code as possible into the model layer, but some code belongs in the controller. I want it to be easily tested too.</p>
<p>It is also worth noting that the Ruby community is driving the testing profession forward, with tools like RSpec, Capybara, Webkit and Cucumber.</p>
<p>Yes, I know that there are several implementation languages for Cucumber. It's possible to write your steps, in C# or Java or almost any other language. My advice is, <em>don't do it!</em> There is compilation, waiting, pain and suffering down that road. Use a dynamic language to test your code.</p>
<h2>Conclusion</h2>
<p>So what's my point? It's time to stop compiling and quit slacking off.</p>
<p><img src="http://imgs.xkcd.com/comics/compiling.png" title="XKCD Compiling" alt="XKCD Compiling" /></p>
<p><strong>Rails should be the default choice for web development.</strong> You should have a very good reason for not choosing Rails on your next web project.</p>
<p>I know it may feel tough to have invested many years in something else, but as the turks say.</p>
<blockquote><p>No matter how far down the wrong path you've gone, turn back! --- Turkish Proverb</p>
</blockquote>
<p>Don't take my word for it. Check out <a href="http://www.infoq.com/articles/architecting-tekpub">this interview</a> and <a href="http://www.infoq.com/presentations/ford-large-rails">this presentation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/06/08/seamless-web-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC vs. Rails3</title>
		<link>http://blog.jayway.com/2010/04/23/asp-net-mvc-vs-rails3/</link>
		<comments>http://blog.jayway.com/2010/04/23/asp-net-mvc-vs-rails3/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 08:58:55 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=5422</guid>
		<description><![CDATA[I recently was contacted to implement an ASP.NET MVC application and I saw this as a great opportunity to compare it with Rails3. What immediately strikes you when you start with ASP.NET MVC is how similar it is to Rails. No one can steal ideas like Microsoft! Rails ASP.NET MVC Purpose (if not obvious) /app/models [...]]]></description>
			<content:encoded><![CDATA[<p>I recently was contacted to implement an ASP.NET MVC application and I saw this as a great opportunity to compare it with Rails3.<br />
What immediately strikes you when you start with ASP.NET MVC is how similar it is to Rails. No one can steal ideas like Microsoft!</p>
<table>
<tbody>
<tr>
<th>Rails
        </th>
<th>ASP.NET MVC
        </th>
<th>Purpose (if not obvious)
    </th>
</tr>
<tr>
<td>/app/models</td>
<td>/Models</td>
<td></td>
</tr>
<tr>
<td>/app/controllers</td>
<td>/Controllers</td>
<td></td>
</tr>
<tr>
<td>/app/views</td>
<td>/Views</td>
<td></td>
</tr>
<tr>
<td>/public/javascript</td>
<td>/Scripts</td>
<td></td>
</tr>
<tr>
<td>/public</td>
<td>/Content</td>
<td></td>
</tr>
<tr>
<td>/db</td>
<td>/App_Data</td>
<td>Database data, such as migrations, and models.</td>
</tr>
<tr>
<td>/test (unit, functional, fixtures, performance)</td>
<td>Separate VS projects</td>
</tr>
<tr>
<td>/config</td>
<td>/Global.asax, /Properties, Web.config</td>
<td>Configuration</td>
</tr>
</tbody>
</table>
<h3>
<p>Project Generation</h3>
<p>Both Rails and ASP.NET MVC relies on code generation to get you started, but the methods they use are different.<br />
Rails uses the command line, which is natural since the Rails approach is to not rely on anything but a good programming editor and the command line.</p>
<pre><tt>$ rails tapir
      create  <span style="color: #990000;">.</span>gitignore
	  <span style="color: #990000;">...</span>
      create  app/controllers/application_controller<span style="color: #990000;">.</span>rb
      <span style="color: #990000;">...</span>
      create  app/views/layouts
      create  config/database<span style="color: #990000;">.</span>yml
      create  db/seeds<span style="color: #990000;">.</span>rb
	  <span style="color: #990000;">...</span>
      create  public/javascripts/application<span style="color: #990000;">.</span>js
	  <span style="color: #990000;">...</span>
      create  test/unit
	  <span style="color: #990000;">...</span>
</tt></pre>
<p>ASP.NET MVC uses Wizards inside Visual Studio, which is also expected since Microsoft has a long history of IDE-centric application building.<br />
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/_ELioussa2vo/S9FeCW86GtI/AAAAAAAAAeg/Fa-g7QGSjkw/s1600/new_asp_mvc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox"><img border="0" src="http://3.bp.blogspot.com/_ELioussa2vo/S9FeCW86GtI/AAAAAAAAAeg/Fa-g7QGSjkw/s320/new_asp_mvc.png" /></a></div>
<p>Worth noting is that I didn't really want to use VS Unit Test, since I normally prefer NUnit, but after one hour of googling and testing I gave up and went with VS Unit Test anyway.</p>
<h3>
<p>Environment</h3>
<p>When Rails is installed it comes pre-configured with three different environment, development, test and production. It is as easy as writing RAILS_ENV=test to switch from the default development environment to the test environment. In this area Rails really shines. There is nothing similar in ASP.NET MVC.</p>
<h3>
<p>The Model</h3>
<h4>
<p>Rails Model</h4>
<p>Rails comes pre-configured with an ActiveRecord model, if you don't write otherwise. If you want to use something else it is very easy. Supported frameworks are among others, Neo4J, MongoDB, and DataMapper.<br />
To create a model in Rails3 you use a command line generator. The generator generates a model, a migration and tests. And you can, of course, choose what kind of model you wish to generate (-o), as well as what kind of testing framework you want to use (-t). Here I just go with the default:</p>
<pre><tt>$ rails g model customer name<span style="color: #990000;">:</span>string email<span style="color: #990000;">:</span>string
      invoke  active_record
      create    db/migrate<span style="color: #990000;">/</span>20100419094010_create_customers<span style="color: #990000;">.</span>rb
      create    app/models/customer<span style="color: #990000;">.</span>rb
      invoke    test_unit
      create      test/unit/customer_test<span style="color: #990000;">.</span>rb
      create      test/fixtures/customers<span style="color: #990000;">.</span>yml

</tt></pre>
<p>Rails comes preconfigured with Sqlite3, and you don't have to do anything to configure the default database. Moreover, the configuration is set up to use three different databases, one for each environment.<br />
Rails, performs all database changes through scripts, migrations. This is invaluable when you want to upgrade a database that is in production, or when multiple developers are changing the same database model. The migration scripts allow seamless migrations between the different databases.</p>
<pre><tt><i><span style="color: #9a1900;"># An example of a migration</span></i>
<b><span style="color: blue;">class</span></b> CreateCustomers <span style="color: #990000;">&lt;</span> ActiveRecord<span style="color: #990000;">::</span>Migration

  <i><span style="color: #9a1900;"># Called when migrating up to this version</span></i>
  <b><span style="color: blue;">def</span></b> <b><span style="color: blue;">self</span></b><span style="color: #990000;">.</span>up
    create_table <span style="color: #990000;">:</span>customers <b><span style="color: blue;">do</span></b> <span style="color: #990000;">|</span>t<span style="color: #990000;">|</span>
      t<span style="color: #990000;">.</span>string <span style="color: #990000;">:</span>name
      t<span style="color: #990000;">.</span>string <span style="color: #990000;">:</span>email
      t<span style="color: #990000;">.</span>timestamps
    <b><span style="color: blue;">end</span></b>
  <b><span style="color: blue;">end</span></b>

  <i><span style="color: #9a1900;"># Called when migrating down from this version</span></i>
  <b><span style="color: blue;">def</span></b> <b><span style="color: blue;">self</span></b><span style="color: #990000;">.</span>down
    drop_table <span style="color: #990000;">:</span>customers
  <b><span style="color: blue;">end</span></b>
<b><span style="color: blue;">end</span></b>

</tt></pre>
<p>To move between the different versions of the database we use the <i>rake db:migrate</i> command.</p>
<pre><tt><i><span style="color: #9a1900;"># Migrate to the latest version</span></i>
$ rake db<span style="color: #990000;">:</span>migrate 

<i><span style="color: #9a1900;"># Migrate to a specific version</span></i>
$ rake db<span style="color: #990000;">:</span>migrate <span style="color: #009900;">VERSION</span><span style="color: #990000;">=</span><span style="color: #993399;">20080906120000</span> 

<i><span style="color: #9a1900;"># Rollback one version</span></i>
$ rake db<span style="color: #990000;">:</span>rollback 

<i><span style="color: #9a1900;"># Rollback three versions</span></i>
$ rake db<span style="color: #990000;">:</span>rollback <span style="color: #009900;">STEP</span><span style="color: #990000;">=</span><span style="color: #993399;">3</span>

</tt></pre>
<p>Read more about migrations in the <a href="http://guides.rubyonrails.org/migrations.html">Migrations Guide</a></p>
<h4>
<p>ASP.NET MVC Model</h4>
<p>ASP.NET MVC is not a full stack framework and it does not come preconfigured with a model. It is possible to choose between many solutions, such as NHibernate, Entity Framework or LINQ-to-SQL. I choose LINQ-to-SQL because I think it is an elegant, lightweight OR-Mapper, that is easy to work with. Too bad, it isn't prioritized by Microsoft.<br />
Unfortunately, there is nothing like migrations in LINQ-to-SQL. So I use the LINQ-to-SQL design tool to design the classes.<br />
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/_ELioussa2vo/S9FezPBTiuI/AAAAAAAAAeo/2-hPL_i1h70/s1600/linq_to_sql_designer.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox"><img border="0" src="http://3.bp.blogspot.com/_ELioussa2vo/S9FezPBTiuI/AAAAAAAAAeo/2-hPL_i1h70/s320/linq_to_sql_designer.png" /></a></div>
<p>
You can then create the database from the model. It is also possible to do it the opposite way, to create the database first and then generate the model, but I prefer this way.</p>
<pre><tt><i><span style="color: #9a1900;">// Creating a database from a LINQ-to-SQL DataContext</span></i>
public <span style="color: teal;">void</span> <b><span style="color: black;">CreateDatabase</span></b><span style="color: #990000;">(</span><span style="color: #009900;">bool</span> force<span style="color: #990000;">)</span>
<span style="color: red;">{</span>
    <span style="color: teal;">var</span> db <span style="color: #990000;">=</span> <span style="color: teal;">new</span> <b><span style="color: black;">TapirDataContext</span></b><span style="color: #990000;">(</span>@<span style="color: red;">"c:</span><span style="color: #cc33cc;">\t</span><span style="color: red;">apirdb.mdf"</span><span style="color: #990000;">);</span>
    <b><span style="color: blue;">if</span></b> <span style="color: #990000;">(</span>db<span style="color: #990000;">.</span><b><span style="color: black;">DatabaseExists</span></b><span style="color: #990000;">()</span> <span style="color: #990000;">||</span> force<span style="color: #990000;">)</span>
    <span style="color: red;">{</span>
        Console<span style="color: #990000;">.</span><b><span style="color: black;">WriteLine</span></b><span style="color: #990000;">(</span><span style="color: red;">"Deleting old database..."</span><span style="color: #990000;">);</span>
        db<span style="color: #990000;">.</span><b><span style="color: black;">DeleteDatabase</span></b><span style="color: #990000;">();</span>
    <span style="color: red;">}</span>
    db<span style="color: #990000;">.</span><b><span style="color: black;">CreateDatabase</span></b><span style="color: #990000;">();</span>
<span style="color: red;">}</span>

</tt></pre>
<p>As you understand this is not a viable solution for migrating a production database, but it is good enough (almost) for development and testing, since I can allow myself to recreate the database every time. Once I get a larger database, the time it takes to set it up will force me to go with a better way. The lack of migrations hurts.</p>
<h4>
<p>Query Language</h4>
<p>Rails3 uses AREL, Active Record Relations, and LINQ-to-SQL uses LINQ (surprise!). They are both beautiful solutions and remarkably similar. Both solutions create lazy, composable queries, that are not executed until the latest possible time, when a result is needed. In LINQ, you can see Eric Meijer's Haskell shining through like magic, and in AREL, the beauty of Ruby.</p>
<pre><tt><i><span style="color: #9a1900;"># A simple query with AREL</span></i>
User<span style="color: #990000;">.</span>where<span style="color: #990000;">(</span>users<span style="color: #990000;">[:</span>name<span style="color: #990000;">].</span>eq<span style="color: #990000;">(</span><span style="color: red;">'Anders'</span><span style="color: #990000;">)).</span>order<span style="color: #990000;">(</span><span style="color: red;">'users.id DESC'</span><span style="color: #990000;">).</span>limit<span style="color: #990000;">(</span><span style="color: #993399;">20</span><span style="color: #990000;">)</span>

</tt></pre>
<pre><tt><i><span style="color: #9a1900;">// The same with C#</span></i>
<i><span style="color: #9a1900;">// Lambda Syntax</span></i>
db<span style="color: #990000;">.</span>Users<span style="color: #990000;">.</span><b><span style="color: black;">where</span></b><span style="color: #990000;">(</span>u <span style="color: #990000;">=&gt;</span> u<span style="color: #990000;">.</span>Name <span style="color: #990000;">==</span> <span style="color: red;">"Anders"</span><span style="color: #990000;">).</span><b><span style="color: black;">orderBy</span></b><span style="color: #990000;">(</span>u <span style="color: #990000;">=&gt;</span> u<span style="color: #990000;">.</span>Id<span style="color: #990000;">).</span><b><span style="color: black;">Take</span></b><span style="color: #990000;">(</span><span style="color: #993399;">20</span><span style="color: #990000;">)</span>

<i><span style="color: #9a1900;">// LINQ Syntax</span></i>
<span style="color: #990000;">(</span>from u <span style="color: teal;">in</span> db<span style="color: #990000;">.</span>Users
<span style="color: teal;">where</span> u<span style="color: #990000;">.</span>Name <span style="color: #990000;">==</span> <span style="color: red;">"Anders"</span>
<span style="color: teal;">orderby</span> u<span style="color: #990000;">.</span>Id descending
<span style="color: teal;">select</span> u<span style="color: #990000;">).</span><b><span style="color: black;">Take</span></b><span style="color: #990000;">(</span><span style="color: #993399;">20</span><span style="color: #990000;">);</span>

</tt></pre>
<p>One thing that you don't get with LINQ-to-SQL is all the methods that are dynamically created, by need, in Rails, such as <i>find_by_name</i>, <i>find_by_name_and_age</i>, etc.</p>
<h3>
<p>The Controller</h3>
<p>In ASP.NET MVC, it is easy to create a controller, you just right-click on the controllers folder and select <i>Add &gt; Controller</i>. You then get a dialog where you can type in the name of the controller and, optionally, if you like to create default methods for the standard CRUD scenario, just select the checkbox.<br />
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/_ELioussa2vo/S9Fe8OUhFHI/AAAAAAAAAe4/8ftOIxwf2Vg/s1600/generate_controller.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox"><img border="0" src="http://1.bp.blogspot.com/_ELioussa2vo/S9Fe8OUhFHI/AAAAAAAAAe4/8ftOIxwf2Vg/s320/generate_controller.png" /></a></div>
<p></p>
<pre><tt>
public <span style="color: teal;">class</span> CustomersController <span style="color: #990000;">:</span> Controller <span style="color: red;">{</span>
      <i><span style="color: #9a1900;">// GET: /Customers/</span></i>
      public <span style="color: teal;">ActionResult</span> <b><span style="color: black;">Index</span></b><span style="color: #990000;">()</span> <span style="color: red;">{</span>
          <b><span style="color: blue;">return</span></b> <b><span style="color: black;">View</span></b><span style="color: #990000;">();</span>
      <span style="color: red;">}</span>

      <i><span style="color: #9a1900;">// GET: /Customers/Details/5</span></i>
      public <span style="color: teal;">ActionResult</span> <b><span style="color: black;">Details</span></b><span style="color: #990000;">(</span><span style="color: #009900;">int</span> id<span style="color: #990000;">)</span> <span style="color: red;">{</span>
          <b><span style="color: blue;">return</span></b> <b><span style="color: black;">View</span></b><span style="color: #990000;">();</span>
      <span style="color: red;">}</span>

      <i><span style="color: #9a1900;">// GET: /Customers/Create</span></i>
      public <span style="color: teal;">ActionResult</span> <b><span style="color: black;">Create</span></b><span style="color: #990000;">()</span> <span style="color: red;">{</span>
          <b><span style="color: blue;">return</span></b> <b><span style="color: black;">View</span></b><span style="color: #990000;">();</span>
      <span style="color: red;">}</span>

      <i><span style="color: #9a1900;">// POST: /Customers/Create</span></i>
      <span style="color: #990000;">[</span>HttpPost<span style="color: #990000;">]</span>
      public <span style="color: teal;">ActionResult</span> <b><span style="color: black;">Create</span></b><span style="color: #990000;">(</span><span style="color: teal;">FormCollection</span> collection<span style="color: #990000;">)</span> <span style="color: red;">{</span>
          try <span style="color: red;">{</span>
              <i><span style="color: #9a1900;">// TODO: Add insert logic here</span></i>
              <b><span style="color: blue;">return</span></b> <b><span style="color: black;">RedirectToAction</span></b><span style="color: #990000;">(</span><span style="color: red;">"Index"</span><span style="color: #990000;">);</span>
          <span style="color: red;">}</span> <b><span style="color: blue;">catch</span></b> <span style="color: red;">{</span>
              <b><span style="color: blue;">return</span></b> <b><span style="color: black;">View</span></b><span style="color: #990000;">();</span>
          <span style="color: red;">}</span>
      <span style="color: red;">}</span>
<span style="color: red;">}</span>

</tt></pre>
<p>As you can see the code generated is simple and clear. That is the benefit of MVC, simpler models, views, and controllers.<br />
The automatic generation of code, that will probably be changed later is commonly known as scaffolding.</p>
<blockquote><p>
<b>Scaffolding</b> is a temporary structure used to support people and material in the construction or repair of buildings and other large structures. --Wikipedia</p></blockquote>
<p>Scaffolding is not meant to be used as is. It is meant to get you started!<br />
In Rails3 you add controllers with a generator. You have a lot more options, below are just a few of them.</p>
<pre><tt>$ rails g controller
Usage<span style="color: #990000;">:</span>
  rails generate controller NAME <span style="color: #990000;">[</span>action action<span style="color: #990000;">]</span> <span style="color: #990000;">[</span>options<span style="color: #990000;">]</span>

Options<span style="color: #990000;">:</span>
  -e<span style="color: #990000;">,</span> <span style="color: #990000;">[</span>--template-engine<span style="color: #990000;">=</span>NAME<span style="color: #990000;">]</span>  <i><span style="color: #9a1900;"># Template engine to be invoked</span></i>
                                <i><span style="color: #9a1900;"># Default: erb</span></i>
  -t<span style="color: #990000;">,</span> <span style="color: #990000;">[</span>--test-framework<span style="color: #990000;">=</span>NAME<span style="color: #990000;">]</span>   <i><span style="color: #9a1900;"># Test framework to be invoked</span></i>
                                <i><span style="color: #9a1900;"># Default: test_unit</span></i>

</tt></pre>
<p>As you can see it is possible to choose what template-engine you want to use, and exactly what actions you want to create, the view templates are created automatically with every action you create.</p>
<pre><tt>$ rails g controller Customer index create
    conflict  app/controllers/customer_controller<span style="color: #990000;">.</span>rb
      create  app/controllers/customer_controller<span style="color: #990000;">.</span>rb
       route  get <span style="color: red;">"customer/create"</span>
       route  get <span style="color: red;">"customer/index"</span>
      invoke  erb
      create    app/views/customer
      create    app/views/customer/index<span style="color: #990000;">.</span>html<span style="color: #990000;">.</span>erb
      create    app/views/customer/create<span style="color: #990000;">.</span>html<span style="color: #990000;">.</span>erb
      invoke  test_unit
    create    test/functional/customer_controller_test<span style="color: #990000;">.</span>rb
      invoke  helper
    create    app/helpers/customer_helper<span style="color: #990000;">.</span>rb
      invoke    test_unit
    create      test/unit/helpers/customer_helper_test<span style="color: #990000;">.</span>rb

If you want to create all the default actions you should instead invoke the scaffold_generator<span style="color: #990000;">.</span>

</tt></pre>
<pre><tt>$ rails g scaffold_controller
Usage<span style="color: #990000;">:</span>
  rails generate scaffold_controller NAME <span style="color: #990000;">[</span>options<span style="color: #990000;">]</span>

</tt></pre>
<p>It will create all the default actions and the views that go with them.</p>
<h4>
<p>The generated code is shown below. Again, you see the similarity between the two solutions. Rails, automatically generates support for both HTML and XML, making it easy to consume the data from other clients.</p>
<pre><tt><b><span style="color: blue;">class</span></b> FishController <span style="color: #990000;">&lt;</span> ApplicationController
  <i><span style="color: #9a1900;"># GET /fish</span></i>
  <i><span style="color: #9a1900;"># GET /fish.xml</span></i>
  <b><span style="color: blue;">def</span></b> index
    <span style="color: #009900;">@fish</span> <span style="color: #990000;">=</span> Fish<span style="color: #990000;">.</span>all

    respond_to <b><span style="color: blue;">do</span></b> <span style="color: #990000;">|</span>format<span style="color: #990000;">|</span>
      format<span style="color: #990000;">.</span>html <i><span style="color: #9a1900;"># index.html.erb</span></i>
      format<span style="color: #990000;">.</span>xml  <span style="color: red;">{</span> render <span style="color: #990000;">:</span>xml <span style="color: #990000;">=&gt;</span> <span style="color: #009900;">@fish</span> <span style="color: red;">}</span>
    <b><span style="color: blue;">end</span></b>
  <b><span style="color: blue;">end</span></b>

  <i><span style="color: #9a1900;"># GET /fish/1</span></i>
  <i><span style="color: #9a1900;"># GET /fish/1.xml</span></i>
  <b><span style="color: blue;">def</span></b> show
    <span style="color: #009900;">@fish</span> <span style="color: #990000;">=</span> Fish<span style="color: #990000;">.</span>find<span style="color: #990000;">(</span>params<span style="color: #990000;">[:</span>id<span style="color: #990000;">])</span>

    respond_to <b><span style="color: blue;">do</span></b> <span style="color: #990000;">|</span>format<span style="color: #990000;">|</span>
      format<span style="color: #990000;">.</span>html <i><span style="color: #9a1900;"># show.html.erb</span></i>
      format<span style="color: #990000;">.</span>xml  <span style="color: red;">{</span> render <span style="color: #990000;">:</span>xml <span style="color: #990000;">=&gt;</span> <span style="color: #009900;">@fish</span> <span style="color: red;">}</span>
    <b><span style="color: blue;">end</span></b>
  <b><span style="color: blue;">end</span></b>

  <i><span style="color: #9a1900;"># GET /fish/new</span></i>
  <i><span style="color: #9a1900;"># GET /fish/new.xml</span></i>
  <b><span style="color: blue;">def</span></b> new
    <span style="color: #009900;">@fish</span> <span style="color: #990000;">=</span> Fish<span style="color: #990000;">.</span>new

    respond_to <b><span style="color: blue;">do</span></b> <span style="color: #990000;">|</span>format<span style="color: #990000;">|</span>
      format<span style="color: #990000;">.</span>html <i><span style="color: #9a1900;"># new.html.erb</span></i>
      format<span style="color: #990000;">.</span>xml  <span style="color: red;">{</span> render <span style="color: #990000;">:</span>xml <span style="color: #990000;">=&gt;</span> <span style="color: #009900;">@fish</span> <span style="color: red;">}</span>
    <b><span style="color: blue;">end</span></b>
  <b><span style="color: blue;">end</span></b>

  <i><span style="color: #9a1900;"># GET /fish/1/edit</span></i>
  <b><span style="color: blue;">def</span></b> edit
    <span style="color: #009900;">@fish</span> <span style="color: #990000;">=</span> Fish<span style="color: #990000;">.</span>find<span style="color: #990000;">(</span>params<span style="color: #990000;">[:</span>id<span style="color: #990000;">])</span>
  <b><span style="color: blue;">end</span></b>

  <i><span style="color: #9a1900;"># POST /fish</span></i>
  <i><span style="color: #9a1900;"># POST /fish.xml</span></i>
  <b><span style="color: blue;">def</span></b> create
    <span style="color: #009900;">@fish</span> <span style="color: #990000;">=</span> Fish<span style="color: #990000;">.</span>new<span style="color: #990000;">(</span>params<span style="color: #990000;">[:</span>fish<span style="color: #990000;">])</span>

    respond_to <b><span style="color: blue;">do</span></b> <span style="color: #990000;">|</span>format<span style="color: #990000;">|</span>
      <b><span style="color: blue;">if</span></b> <span style="color: #009900;">@fish</span><span style="color: #990000;">.</span>save
        format<span style="color: #990000;">.</span>html <span style="color: red;">{</span> redirect_to<span style="color: #990000;">(</span><span style="color: #009900;">@fish</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span>notice <span style="color: #990000;">=&gt;</span> <span style="color: red;">'Fish was successfully created.'</span><span style="color: #990000;">)</span> <span style="color: red;">}</span>
        format<span style="color: #990000;">.</span>xml  <span style="color: red;">{</span> render <span style="color: #990000;">:</span>xml <span style="color: #990000;">=&gt;</span> <span style="color: #009900;">@fish</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span>status <span style="color: #990000;">=&gt;</span> <span style="color: #990000;">:</span>created<span style="color: #990000;">,</span> <span style="color: #990000;">:</span>location <span style="color: #990000;">=&gt;</span> <span style="color: #009900;">@fish</span> <span style="color: red;">}</span>
      <b><span style="color: blue;">else</span></b>
        format<span style="color: #990000;">.</span>html <span style="color: red;">{</span> render <span style="color: #990000;">:</span>action <span style="color: #990000;">=&gt;</span> <span style="color: red;">"new"</span> <span style="color: red;">}</span>
        format<span style="color: #990000;">.</span>xml  <span style="color: red;">{</span> render <span style="color: #990000;">:</span>xml <span style="color: #990000;">=&gt;</span> <span style="color: #009900;">@fish</span><span style="color: #990000;">.</span>errors<span style="color: #990000;">,</span> <span style="color: #990000;">:</span>status <span style="color: #990000;">=&gt;</span> <span style="color: #990000;">:</span>unprocessable_entity <span style="color: red;">}</span>
      <b><span style="color: blue;">end</span></b>
    <b><span style="color: blue;">end</span></b>
  <b><span style="color: blue;">end</span></b>
<span style="color: #990000;">...</span>
<b><span style="color: blue;">end</span></b>

</tt></pre>
<p>Filters</h4>
<p>In Rails it is easy to create filters, that can be applied to specific actions.</p>
<pre><tt><b><span style="color: blue;">class</span></b> ItemsController <span style="color: #990000;">&lt;</span> ApplicationController
  before_filter <span style="color: #990000;">:</span>require_user_admin<span style="color: #990000;">,</span> <span style="color: #990000;">:</span>only <span style="color: #990000;">=&gt;</span> <span style="color: #990000;">[</span> <span style="color: #990000;">:</span>destroy<span style="color: #990000;">,</span> <span style="color: #990000;">:</span>update <span style="color: #990000;">]</span>
  before_filter <span style="color: #990000;">:</span>require_user<span style="color: #990000;">,</span> <span style="color: #990000;">:</span>only <span style="color: #990000;">=&gt;</span> <span style="color: #990000;">[</span> <span style="color: #990000;">:</span>new<span style="color: #990000;">,</span> <span style="color: #990000;">:</span>create<span style="color: #990000;">]</span>
<b><span style="color: blue;">end</span></b>

</tt></pre>
<p>In ASP.NET MVC, the same thing can be accomplished by overriding <b>OnActionExecuting</b>, in the controller.</p>
<pre><tt>override <span style="color: teal;">void</span> <b><span style="color: black;">OnActionExecuting</span></b><span style="color: #990000;">(</span><span style="color: teal;">ActionExecutingContext</span> filterContext<span style="color: #990000;">)</span>
<span style="color: red;">{</span>
    <span style="color: teal;">var</span> action <span style="color: #990000;">=</span> filterContext<span style="color: #990000;">.</span>ActionDescriptor<span style="color: #990000;">.</span>ActionName<span style="color: #990000;">;</span>
    <b><span style="color: blue;">if</span></b> <span style="color: #990000;">(</span><span style="color: teal;">new</span> List<span style="color: #990000;">&lt;</span>string<span style="color: #990000;">&gt;</span><span style="color: red;">{</span><span style="color: red;">"Delete"</span><span style="color: #990000;">,</span> <span style="color: red;">"Edit"</span><span style="color: red;">}</span><span style="color: #990000;">.</span><b><span style="color: black;">Contains</span></b><span style="color: #990000;">(</span>action<span style="color: #990000;">))</span> <span style="color: red;">{</span>
        <b><span style="color: black;">RequireUserAdmin</span></b><span style="color: #990000;">();</span>
    <span style="color: red;">}</span>
    <b><span style="color: blue;">if</span></b> <span style="color: #990000;">(</span><span style="color: red;">"Create"</span><span style="color: #990000;">.</span><b><span style="color: black;">Equals</span></b><span style="color: #990000;">(</span>action<span style="color: #990000;">))</span> <span style="color: red;">{</span>
        <b><span style="color: black;">RequireUserAdmin</span></b><span style="color: #990000;">();</span>
    <span style="color: red;">}</span>
<span style="color: red;">}</span>

</tt></pre>
<p>The functionality may also be extracted into an ActionFilter, which can be applied to the controller or an individual method via an Attribute.</p>
<pre><tt><span style="color: #990000;">[</span><b><span style="color: black;">RequireUserAdmin</span></b><span style="color: #990000;">(</span><span style="color: red;">"Delete"</span><span style="color: #990000;">,</span> <span style="color: red;">"Edit"</span><span style="color: #990000;">)]</span>
<span style="color: #990000;">[</span><b><span style="color: black;">RequireUser</span></b><span style="color: #990000;">(</span><span style="color: red;">"Create"</span><span style="color: #990000;">)]</span>
public <span style="color: teal;">class</span> CustomersController <span style="color: #990000;">:</span> Controller

</tt></pre>
<p>This is a pattern that can be seen everywhere, when Rails uses <i>Class Macros</i>, a term from <a href="http://www.amazon.com/gp/product/1934356476?ie=UTF8&amp;tag=thtasta-20">Meta-Programming Ruby</a>, ASP.NET MVC uses attributes. And this is appropriate since it usually constitutes meta-data.</p>
<h3>
<p>Routing</h3>
<p>The Routing in both Rails and ASP.NET MVC is incredibly flexible.</p>
<h4>
<p>Rails Routing</h4>
<p>In Rails it is possible to put constraints right in the routing table on just about anything.</p>
<pre><tt><i><span style="color: #9a1900;"># config/routes.rb</span></i>
Tapir<span style="color: #990000;">::</span>Application<span style="color: #990000;">.</span>routes<span style="color: #990000;">.</span>draw <b><span style="color: blue;">do</span></b> <span style="color: #990000;">|</span>map<span style="color: #990000;">|</span>
  resources <span style="color: #990000;">:</span>animals

  get <span style="color: red;">"customer/index"</span>
  get <span style="color: red;">"customer/create"</span>

  match <span style="color: red;">"/:year(/:month(/:day))"</span> <span style="color: #990000;">=&gt;</span> <span style="color: red;">"info#about"</span><span style="color: #990000;">,</span>
	<span style="color: #990000;">:</span>constraints <span style="color: #990000;">=&gt;</span> <span style="color: red;">{</span> <span style="color: #990000;">:</span>year <span style="color: #990000;">=&gt;</span> <span style="color: #ff6600;">/\d{4}/</span><span style="color: #990000;">,</span>
		<span style="color: #990000;">:</span>month <span style="color: #990000;">=&gt;</span> <span style="color: #ff6600;">/\d{2}/</span><span style="color: #990000;">,</span>
		<span style="color: #990000;">:</span>day <span style="color: #990000;">=&gt;</span> <span style="color: #ff6600;">/\d{2}/</span> <span style="color: red;">}</span>
  match <span style="color: red;">"/secret"</span> <span style="color: #990000;">=&gt;</span> <span style="color: red;">"info#about"</span><span style="color: #990000;">,</span>
	<span style="color: #990000;">:</span>constraints <span style="color: #990000;">=&gt;</span> <span style="color: red;">{</span> <span style="color: #990000;">:</span>user_agent <span style="color: #990000;">=&gt;</span> <span style="color: #ff6600;">/Firefox/</span> <span style="color: red;">}</span>
<b><span style="color: blue;">end</span></b>

</tt></pre>
<p>As you can see Rails comes pre-configures with RESTful routing, and it is indeed the recommended way to set up your routes in Rails. To see what the routing result is is easy:</p>
<pre><tt>$ rake routes
                GET    /animals<span style="color: #990000;">(.:</span>format<span style="color: #990000;">)</span>          {<span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"index"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"animals"</span>}
        animals POST   /animals<span style="color: #990000;">(.:</span>format<span style="color: #990000;">)</span>          {<span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"create"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"animals"</span>}
     new_animal GET    /animals/new<span style="color: #990000;">(.:</span>format<span style="color: #990000;">)</span>      {<span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"new"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"animals"</span>}
                GET    /animals<span style="color: #990000;">/:</span>id<span style="color: #990000;">(.:</span>format<span style="color: #990000;">)</span>      {<span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"show"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"animals"</span>}
                PUT    /animals<span style="color: #990000;">/:</span>id<span style="color: #990000;">(.:</span>format<span style="color: #990000;">)</span>      {<span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"update"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"animals"</span>}
         animal DELETE /animals<span style="color: #990000;">/:</span>id<span style="color: #990000;">(.:</span>format<span style="color: #990000;">)</span>      {<span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"destroy"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"animals"</span>}
    edit_animal GET    /animals<span style="color: #990000;">/:</span>id/edit<span style="color: #990000;">(.:</span>format<span style="color: #990000;">)</span> {<span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"edit"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"animals"</span>}
 customer_index GET    /customer/index             {<span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"customer"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"index"</span>}
customer_create GET    /customer/create            {<span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"customer"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"create"</span>}
                       <span style="color: #990000;">/:</span>year<span style="color: #990000;">(/:</span>month<span style="color: #990000;">(/:</span>day<span style="color: #990000;">))</span>      {<span style="color: #990000;">:</span><span style="color: #009900;">year</span><span style="color: #990000;">=&gt;/\</span>d{<span style="color: #993399;">4</span>}<span style="color: #990000;">/,</span> <span style="color: #990000;">:</span><span style="color: #009900;">month</span><span style="color: #990000;">=&gt;/\</span>d{<span style="color: #993399;">2</span>}<span style="color: #990000;">/,</span> <span style="color: #990000;">:</span><span style="color: #009900;">day</span><span style="color: #990000;">=&gt;/\</span>d{<span style="color: #993399;">2</span>}<span style="color: #990000;">/,</span> <span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"info"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"about"</span>}
                       /secret                     {<span style="color: #990000;">:</span><span style="color: #009900;">user_agent</span><span style="color: #990000;">=&gt;</span>/Firefox<span style="color: #990000;">/,</span> <span style="color: #990000;">:</span><span style="color: #009900;">controller</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"info"</span><span style="color: #990000;">,</span> <span style="color: #990000;">:</span><span style="color: #009900;">action</span><span style="color: #990000;">=&gt;</span><span style="color: red;">"about"</span>}

</tt></pre>
<h4>
<p>ASP.NET MVC Routing</h4>
<p>ASP.NET MVC Routing is not quite as easy, but everything is possible. The standard routing with paths and parameters works easily out of the box.</p>
<pre><tt><i><span style="color: #9a1900;">// Global.asax.cs</span></i>
 public <span style="color: teal;">class</span> MvcApplication <span style="color: #990000;">:</span> System<span style="color: #990000;">.</span>Web<span style="color: #990000;">.</span>HttpApplication <span style="color: red;">{</span>
	public <b><span style="color: blue;">static</span></b> <span style="color: #009900;">void</span> <b><span style="color: black;">RegisterRoutes</span></b><span style="color: #990000;">(</span><span style="color: teal;">RouteCollection</span> routes<span style="color: #990000;">)</span> <span style="color: red;">{</span>
		routes<span style="color: #990000;">.</span><b><span style="color: black;">IgnoreRoute</span></b><span style="color: #990000;">(</span><span style="color: red;">"{resource}.axd/{*pathInfo}"</span><span style="color: #990000;">);</span> 

		<i><span style="color: #9a1900;">// Constrained route</span></i>
		routes<span style="color: #990000;">.</span><b><span style="color: black;">MapRoute</span></b><span style="color: #990000;">(</span> <span style="color: red;">"Product"</span><span style="color: #990000;">,</span> <span style="color: red;">"Product/{productId}"</span><span style="color: #990000;">,</span>
			new <span style="color: red;">{</span>controller<span style="color: #990000;">=</span><span style="color: red;">"Product"</span><span style="color: #990000;">,</span> action<span style="color: #990000;">=</span><span style="color: red;">"Details"</span><span style="color: red;">}</span><span style="color: #990000;">,</span>
			new <span style="color: red;">{</span>productId <span style="color: #990000;">=</span> @<span style="color: red;">"</span><span style="color: #cc33cc;">\d</span><span style="color: red;">+"</span> <span style="color: red;">}</span> <span style="color: #990000;">);</span> <i><span style="color: #9a1900;">// Constraint</span></i>

		<i><span style="color: #9a1900;">// Route with custom constraint, defined below	</span></i>
		routes<span style="color: #990000;">.</span><b><span style="color: black;">MapRoute</span></b><span style="color: #990000;">(</span> <span style="color: red;">"Admin"</span><span style="color: #990000;">,</span> <span style="color: red;">"Admin/{action}"</span><span style="color: #990000;">,</span>
			new <span style="color: red;">{</span>controller<span style="color: #990000;">=</span><span style="color: red;">"Admin"</span><span style="color: red;">}</span><span style="color: #990000;">,</span>
			new <span style="color: red;">{</span>isLocal<span style="color: #990000;">=</span><span style="color: teal;">new</span> <b><span style="color: black;">LocalhostConstraint</span></b><span style="color: #990000;">()</span><span style="color: red;">}</span> <span style="color: #990000;">);</span>
	<span style="color: red;">}</span>
<span style="color: #990000;">...</span>
<span style="color: red;">}</span>

public <span style="color: teal;">class</span> LocalhostConstraint <span style="color: #990000;">:</span> IRouteConstraint <span style="color: red;">{</span>
	public <span style="color: teal;">bool</span> <b><span style="color: black;">Match</span></b> <span style="color: #990000;">(</span> <span style="color: teal;">HttpContextBase</span> httpContext<span style="color: #990000;">,</span> <span style="color: teal;">Route</span> route<span style="color: #990000;">,</span>
	 	<span style="color: teal;">string</span> parameterName<span style="color: #990000;">,</span> <span style="color: teal;">RouteValueDictionary</span> values<span style="color: #990000;">,</span>
	 	<span style="color: teal;">RouteDirection</span> routeDirection <span style="color: #990000;">)</span>
	<span style="color: red;">{</span>
		<b><span style="color: blue;">return</span></b> httpContext<span style="color: #990000;">.</span>Request<span style="color: #990000;">.</span>IsLocal<span style="color: #990000;">;</span>
	<span style="color: red;">}</span>
<span style="color: red;">}</span> 

</tt></pre>
<p>As you can see, you have the same power in the ASP.NET MVC Routing, but it requires you to add constraints separately.</p>
<h3>
<p>Views</h3>
<p>In both Rails and ASP.NET MVC, the views are automatically matched in the directory with the same name as the controller, and the file name is named by the action.</p>
<pre><tt>app/controllers/customer_controller<span style="color: #990000;">.</span>rb
app/views/customer
app/views/customer/create<span style="color: #990000;">.</span>html<span style="color: #990000;">.</span>erb
app/views/customer/index<span style="color: #990000;">.</span>html<span style="color: #990000;">.</span>erb

</tt></pre>
<p>In Visual Studio it is possible to scaffold a view based on a model, just as it is in Rails. Rails is, of course, more flexible, allowing me to scaffold all or some actions at once. In Visual Studio, it is only possible to do one at a time.</p>
<h4>
<p>Partials</h4>
<p>In both Rails and ASP.NET MVC, a partial is a file that contains a part of a HTML file. The file is written in ASP in ASP.NET MVC and in Rails it is possible to pick the templating language of your choice. Default is ERB, but HAML is also a popular choice.</p>
<pre><tt><span style="color: #990000;">&lt;!--</span> Rails <span style="color: #990000;">--&gt;</span>
<span style="color: #990000;">&lt;%=</span> render <span style="color: red;">'form'</span> <span style="color: #990000;">%&gt;</span>

</tt></pre>
<pre><tt><span style="color: #990000;">&lt;!--</span> ASP<span style="color: #990000;">.</span>NET MVC <span style="color: #990000;">--&gt;</span>
<span style="color: #990000;">&lt;%</span> Html<span style="color: #990000;">.</span><b><span style="color: black;">RenderPartial</span></b><span style="color: #990000;">(</span><span style="color: red;">"Form"</span><span style="color: #990000;">,</span> Model<span style="color: #990000;">);%&gt;</span>

</tt></pre>
<p>In ASP.NET MVC version 2, the preferred way is actually to use two alternate methods to generate the code. They have the advantage that they are type-safe (if that gives you pleasure) and they keep track of nesting.</p>
<pre><tt><span style="color: #990000;">&lt;%=</span> <b><span style="color: black;">DisplayFor</span></b><span style="color: #990000;">(</span><span style="color: red;">"Address"</span><span style="color: #990000;">,</span> m <span style="color: #990000;">=&gt;</span> m<span style="color: #990000;">.</span>Address <span style="color: #990000;">)</span> <span style="color: #990000;">%&gt;</span>

<span style="color: #990000;">&lt;%=</span> <b><span style="color: black;">EditorFor</span></b><span style="color: #990000;">(</span><span style="color: red;">"Address"</span><span style="color: #990000;">,</span> m <span style="color: #990000;">=&gt;</span> m<span style="color: #990000;">.</span>Address <span style="color: #990000;">)</span> <span style="color: #990000;">%&gt;</span>

</tt></pre>
<p>(For Rubyist, the <b>m =&gt; m.Address</b> is not a hash key-value expression, but an anonymous function.)</p>
<h4>
<p>Helpers</h4>
<p>A helper is similar to a partial, but it is not a template, it's a method that generates code.<br />
In Rails you create a helper by creating a simple method.</p>
<pre><tt><b><span style="color: blue;">module</span></b> ApplicationHelper
   <b><span style="color: blue;">def</span></b> label target<span style="color: #990000;">,</span> text
     <span style="color: red;">"&lt;label for='#{target}'&gt;#{text}&lt;/label&gt;"</span>
   <b><span style="color: blue;">end</span></b>
 <b><span style="color: blue;">end</span></b>

</tt></pre>
<p>And so you can in ASP.NET MVC.</p>
<pre><tt>public <span style="color: teal;">class</span> LabelHelper <span style="color: red;">{</span>
    public <b><span style="color: blue;">static</span></b> <span style="color: teal;">string</span> <b><span style="color: black;">Label</span></b><span style="color: #990000;">(</span><span style="color: teal;">string</span> target<span style="color: #990000;">,</span> <span style="color: teal;">string</span> text<span style="color: #990000;">)</span> <span style="color: red;">{</span>
        <b><span style="color: blue;">return</span></b> String<span style="color: #990000;">.</span><b><span style="color: black;">Format</span></b><span style="color: #990000;">(</span><span style="color: red;">"&lt;label for='{0}'&gt;{1}&lt;/label&gt;"</span><span style="color: #990000;">,</span> target<span style="color: #990000;">,</span> text<span style="color: #990000;">);</span>
    <span style="color: red;">}</span>
<span style="color: red;">}</span>

</tt></pre>
<h3>
<p>Conclusion</h3>
<p>All in all, ASP.NET MVC with LINQ-to-SQL, is not a bad experience. Eric Meijer and friends have managed to overcome a lot of the hurdles of static typing. They also, let go of it in cases, where dynamic typing is obviously better, such as in the routing and when populating objects from forms. The lambda expressions and the type inference also removes a lot of the boilerplate common in statically typed languages.<br />
Rails is of course a lot more flexible, and faster to work with. The scaffolding is faster and more flexible, the migrations are, as I said before, invaluable when it comes to move between versions.<br />
But, if I'm thrown out of the dynamic Garden of Eden, I'd rather pick my static apples in Redmond, than in California.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/04/23/asp-net-mvc-vs-rails3/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Static Typing is the Root of All Evil</title>
		<link>http://blog.jayway.com/2010/04/14/static-typing-is-the-root-of-all-evil/</link>
		<comments>http://blog.jayway.com/2010/04/14/static-typing-is-the-root-of-all-evil/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 11:44:49 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=5346</guid>
		<description><![CDATA[I can't take credit for this statement, since I am only drawing the logical conclusion from a statement said by a man far smarter than I. Donald Knuth wrote in his famous paper Structured Programming with go to Statements (PDF): We should forget about small efficiencies, say about 97% of the time: pre-mature optimization is [...]]]></description>
			<content:encoded><![CDATA[<p>I can't take credit for this statement, since I am only drawing the logical conclusion from a statement said by a man far smarter than I.</p>
<p>Donald Knuth wrote in his famous paper <a href="http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf">Structured Programming with go to Statements (PDF)</a>:</p>
<blockquote><p>We should forget about small efficiencies, say about 97% of the time: pre-mature optimization is the root of all evil</p>
</blockquote>
<p>Since compilation is premature optimization, it is therefore, the root of all evil. Simple!</p>
<h2>Static typing, weak typing, dynamic typing, strong typing, WTF?</h2>
<p>There are a number of misconceptions concerning typing.</p>
<p>The meaning of <em>weak</em> and <em>strong</em> typing, <a href="http://en.wikipedia.org/wiki/Strong_typing">is not clearly defined</a> but is mostly interpreted like this.</p>
<blockquote><p>In a weakly typed language, such as C, the types of the variables can be automatically converted from one representation to another, while in a strongly typed language an explict conversion is required.</p>
</blockquote>
<p>This is not what I am writing about here. I am referring to <em>static</em> vs. <em>dynamic</em> typing and the definition I am using is:</p>
<ul>
<li><em>Static typing</em>, the type checking is performed at compile-time.</li>
<li><em>Dynamic typing</em>, the type ckecking is performed at run-time.</li>
</ul>
<h2>Development Mode</h2>
<p>Every time I build my code, my entire code base is type-checked. <em>EVERY TIME!</em> When I am working in development mode, I only care about the method and class that I am currently working on. As long as my tests pass I am happy, type-safe or not.</p>
<p>In development mode it is actually more accurate to call static typing pre-mature <em>de-optimization</em> than pre-mature optimization.</p>
<h2>Production Mode</h2>
<p>The <em>only</em> reason, to <em>ever</em> use static typing, is because the code may be optimized better, to give better performance.</p>
<p>So, the strategy should be:</p>
<ul>
<li>Use a dynamically typed language during development. It gives you faster feedback, turn-around time, and development speed.</li>
<li>If you ever get lucky enough to have performance problems, which cannot be solved with caching or algorithmic optimization, rewrite the problematic code in a statically typed language.</li>
</ul>
<p>This is what Twitter did, and it has worked well for them.</p>
<h2>Other Misconceptions</h2>
<p>Proponents of Java often have the misconception that dynamically typed languages are unsafe, yet they use frameworks, like Spring, and Qi4J, that are littered with reflective code, and without the so-called safety net that static typing is believed to give. The reason these frameworks are popular is because they allow us to be more productive. The reason they are more productive is because they use dynamic programming techniques.</p>
<p>Anyone, who has worked seriously with a modern dynamically typed language like Ruby or Smalltalk, know that they are more productive. Working with waterfall languages after working with agile languages is just painful. (Thanks to Andreas Ronge for coining the term Waterfall Language.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/04/14/static-typing-is-the-root-of-all-evil/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Maven, the new Elephant on the Block</title>
		<link>http://blog.jayway.com/2010/01/23/maven-the-new-elephant-on-the-block/</link>
		<comments>http://blog.jayway.com/2010/01/23/maven-the-new-elephant-on-the-block/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 15:39:11 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[build systems]]></category>
		<category><![CDATA[buildr]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[maven2]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=4500</guid>
		<description><![CDATA[Some of you may remember the article, by Bruce Tate, Don't Make Me Eat the Elephant Again. It was an article about EJB, and Bruce was begging Sun not to make the same mistakes with EJB3 as they had done with EJB, and EJB2. They didn't, Spring came along as better alternative and forced EJB3 [...]]]></description>
			<content:encoded><![CDATA[<p>Some of you may remember the article, by Bruce Tate, <a href="http://today.java.net/pub/a/today/2004/06/15/ejb3.html">Don't Make Me Eat the Elephant Again</a>.<br />
It was an article about EJB, and Bruce was begging Sun not to make the same mistakes with EJB3 as they had done with EJB, and EJB2. They didn't, Spring came along as better alternative and forced EJB3 to become slimmer and better. If not for Spring, EJB3 would probably look very different from what it looks like today.<br />
Well, guess what, there is a new elephant on the block and its name Maven2.</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/_ELioussa2vo/S1sVp6WDq8I/AAAAAAAAAbU/Vsll0_5GjII/s1600-h/maven2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox"><img border="0" height="289" src="http://4.bp.blogspot.com/_ELioussa2vo/S1sVp6WDq8I/AAAAAAAAAbU/Vsll0_5GjII/s320/maven2.png" width="320" /></a></div>
<p>
Just like EJB2, Maven2 was born out of something so unbearable that anything else was bliss. <a href="http://commons.apache.org/jelly/">Jelly</a> anyone!</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/_ELioussa2vo/S1sWI6lm3KI/AAAAAAAAAbc/A6a_3zHxpsc/s1600-h/Maven.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox"><img border="0" height="246" src="http://3.bp.blogspot.com/_ELioussa2vo/S1sWI6lm3KI/AAAAAAAAAbc/A6a_3zHxpsc/s320/Maven.png" width="320" /></a></div>
<p>
But just as EJB was fundamentally flawed, so is Maven2. Build systems, even advanced ones like Maven is fundamentally about two things.</p>
<ol>
<li>Check if something that something else depends on has changed</li>
<li>If so, do something.</li>
</ol>
<p>That's it, that is what is important.<br />
The checking may contain various sophisticated methods for detecting if files, subsets of files, all files, web pages, twitter feeds, etc, has changed, but that is really it.<br />
And the doing can be anything, Copy files, commit files, build websites, run tests, generate code, launch missiles, whatever!<br />
But the key to doing this efficiently is a programming language with easy access to system commands and the ability to create simple abstractions, with methods, variables, and objects. The language should also, preferably, be one without a lot of ceremony, like Ruby, Javascript or Python.<br />
There are already build systems like this out there, <a href="http://buildr.apache.org/">Buildr</a>, <a href="http://www.scons.org/">SCons</a>, and <a href="http://rake.rubyforge.org/">Rake</a> come to mind, but they do not have the momentum of Maven, so a merger between Maven and Buildr would be wonderful.</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/_ELioussa2vo/S1sWTI-SneI/AAAAAAAAAbk/Z0AI_sUPXMs/s1600-h/Maven3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox"><img border="0" src="http://4.bp.blogspot.com/_ELioussa2vo/S1sWTI-SneI/AAAAAAAAAbk/Z0AI_sUPXMs/s320/Maven3.png" /></a></div>
<p>So, Jason, hear my plea, Don't make me eat the elephant again!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/01/23/maven-the-new-elephant-on-the-block/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Scripting in Ruby</title>
		<link>http://blog.jayway.com/2010/01/16/scripting-in-ruby/</link>
		<comments>http://blog.jayway.com/2010/01/16/scripting-in-ruby/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 12:54:25 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=4349</guid>
		<description><![CDATA[I just read, or rather skimmed, the book, called Everyday Scripting with Ruby and it is awful. I had high expectations. I was expecting something like Perl for System Administration, where you right away get into hard core Perl scripting. This book is nothing like that! It is a really basic introduction to Ruby, and [...]]]></description>
			<content:encoded><![CDATA[<p>I just read, or rather skimmed, the book, called <em>Everyday Scripting with Ruby</em> and it is awful. I had high expectations. I was expecting something like<br />
<a href="http://www.amazon.com/Perl-System-Administrators-David-Blank-Edelman/dp/1565926099?tag=thtasta-20">Perl for System Administration</a>, where you right away get into hard core Perl scripting. This book is nothing like that! It is a really basic introduction to Ruby, and if you have any experience programming at all, DON'T BUY THIS BOOK.</p>
<p>OK, enough complaining! I am going to do what this book does not do. I am going to show a good way to write scripts in Ruby. If you want to learn more about Ruby, buy<br />
<a href="http://www.amazon.com/Programming-Ruby-1-9-Pragmatic-Programmers/dp/1934356085?tag=thtasta-20">Programming Ruby</a>, <a href="http://www.amazon.com/Well-Grounded-Rubyist-David-Black/dp/1933988657?tag=thtasta-20">The Well-Grounded Rubyist</a> and <a href="http://www.amazon.com/Ruby-Way-Second-Techniques-Programming/dp/0672328844?tag=thtasta-20">The Ruby Way</a>.</p>
<p>Ruby is an excellent language. It is, in my opinion, the best scripting language and it beats both Perl and Python face down. If you are not scripting in Ruby, you are missing out.<br />
Ok, so here is the script.</p>
<h3>sendgmail</h3>
<p>The script is called <strong>sendgmail</strong> and it sends mail via gmail (surprise!).</p>
<p>This is how the command is used.</p>
<pre lang='bash'>
$ sendgmail --help
/usr/local/bin/sendgmail [options] attachments...
Options are ...
    -t, --to TO                      Send email to recipient
    -m, --message MESSAGE            Include the message.
    -s, --subject SUBJECT            Include the subject.
    -v, --verbose                    Log to standard output.
    -V, --version                    Display the program version.
    -h, -H, --help                   Display this help message.
</pre>
<p>And here is the code, liberally sprinkled with comments.</p>
<pre>
<I>#!/usr/bin/env ruby
</I><I># Use the currently configured ruby version
</I>
<I># optparse contains OptionParser, ostruct: OpenStruct and growl Growl
</I><B>require</B> <B>'optparse'</B>
<B>require</B> <B>'ostruct'</B>
<B>require</B> <B>'growl'</B>

<I># This is the name of the script that is called
</I><I># Whatever you name your script will be reflected here.
</I><I># This can be useful if you want to have the same script do many things
</I><I># Create differently named links to the script
</I><I># and use the program name to select behavior.
</I>PROGRAM_NAME = <B>$0</B>
PROGRAM_VERSION = 1.0

<I># Create an OpenStruct to save the options.
</I><I># OpenStruct allows you to use options.my_option instead of
</I><I># option['my_option'] with a normal hash
</I><I># http://ruby-doc.org/stdlib/libdoc/ostruct/rdoc/classes/OpenStruct.html
</I><B>def</B> <B>options
</B>  <B>@options</B> ||= OpenStruct.new
<B>end</B>

<I># This is the options of the program, see OptionParser
</I><I># http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
</I><B>def</B> <B>program_options
</B>  [
          <I># The values of the array are,
</I>          <I># [long_option, short_option and parameter, description, code to execute]
</I>          [<B>'--to'</B>, <B>'-t TO'</B>, <B>&quot;Send email to recipient&quot;</B>,
           lambda { |value| options.to = value }
          ],
          [<B>'--message'</B>, <B>'-m MESSAGE'</B>, <B>&quot;Include the message.&quot;</B>,
           lambda { |value| options.message = value }
          ],
          [<B>'--subject'</B>, <B>'-s SUBJECT'</B>, <B>&quot;Include the subject.&quot;</B>,
           lambda { |value| options.subject = value }
          ],
          [<B>'--verbose'</B>, <B>'-v'</B>, <B>&quot;Log to standard output.&quot;</B>,
           lambda { |value| options.verbose = <B>true</B> }
          ],
          [<B>'--version'</B>, <B>'-V'</B>, <B>&quot;Display the program version.&quot;</B>,
           lambda { |value|
             puts <B>&quot;#{program_name}, version #{PROGRAM_VERSION}&quot;</B>
             exit
           }
          ]
  ]
<B>end</B>

option_parser = OptionParser.new <B>do</B> |opts|
  opts.banner = <B>&quot;#{PROGRAM_NAME} [options] attachments...&quot;</B>
  opts.separator <B>&quot;&quot;</B>
  opts.separator <B>&quot;Options are ...&quot;</B>

  <I># Add the command on_tail, to make it appear as the last option in the list.
</I>  opts.on_tail(<B>&quot;-h&quot;</B>, <B>&quot;--help&quot;</B>, <B>&quot;-H&quot;</B>, <B>&quot;Display this help message.&quot;</B>) <B>do</B>
    puts opts
    exit
  <B>end</B>

  program_options.each { |args| opts.on(*args) }
<B>end</B>

<B>begin</B>
  <I># Parse the options and remove them from the ARGV array
</I>  option_parser.parse!
<B>rescue</B> OptionParser::ParseError =&gt; error
  puts error.message
  puts option_parser
  exit
<B>end</B>

<B>unless</B> options.to
  puts <B>'Missing required argument --to or -t'</B>
  puts option_parser
  exit
<B>end</B>

options.subject = <B>'No subject'</B> <B>unless</B> options.subject
options.message = <B>''</B> <B>unless</B> options.message

<I># Concatenate the options into a proper command
</I>command = <B>'sendemail -o tls=yes -s smtp.gmail.com -f from@gmail.com -xu from@gmail.com -xp secret'</B>
command += <B>&quot;-t '#{options.to}' -u '#{options.subject}' -m '#{options.message}' &quot;</B>

<I># Append the filenames with the -a option to send them as attachments
</I><I># Only the non options (the filenames) are left in ARGV
</I><B>unless</B> ARGV.empty?
  command += <B>&quot; -a #{ARGV.join(' ')}&quot;</B>
<B>end</B>

<I># Print the command to screen if using verbose mode.
</I>puts command <B>if</B> options.verbose
system command

Growl.notify <B>&quot;#{options.subject}\n#{options.message}&quot;</B>, :icon =&gt; :jpeg, :title =&gt; <B>&quot;Email sent to #{options.to}&quot;</B>
</pre>
<p>The script requires you to install <strong>sendemail</strong>. It also requires you to install the <strong>growlnotify</strong> command line utility that is distributed with <a href="http://growl.info/">Growl</a> and the gem that uses this utility, also conveniently named <strong>growl</strong>.</p>
<h3>Install required dependencies on OS X</h3>
<pre>
<I># Install sendemail and capabilty to send secure mail, required by Gmail
</I>sudo port install sendemail p5-net-ssleay p5-io-socket-ssl

<I># Install growl command utility from the mounted image
</I>sudo sh /Volumes/Growl-1.2/Extras/growlnotify/install.sh

<I># Install the growl gem
</I>sudo gem install growl
</pre>
<p>That&#8217;s it, a simple script that will allow you to send messages and files through<br />
gmail from the command line.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/01/16/scripting-in-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working at Jayway</title>
		<link>http://blog.jayway.com/2009/11/29/working-at-jayway/</link>
		<comments>http://blog.jayway.com/2009/11/29/working-at-jayway/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 07:03:11 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[authority]]></category>
		<category><![CDATA[competence]]></category>
		<category><![CDATA[consultancy]]></category>
		<category><![CDATA[jayway]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[openness]]></category>
		<category><![CDATA[product development]]></category>
		<category><![CDATA[satisfaction]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2299</guid>
		<description><![CDATA[This morning I woke up singing, like I do most mornings. There are so many things ahead of me and most of them I like to do. One of those things is going to work. I worked at Jayway, for five years, three years ago, and I recently came back. The reason I left was [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I woke up singing, like I do most mornings. <img src='http://blog.jayway.com/wordpress/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  There are so many things ahead of me and most of them I like to do. One of those things is going to work. I worked at Jayway, for five years, three years ago, and I recently came back.</p>
<p>The reason I left was that I wanted to work with one product and one team. I wanted to do everything right, I wanted to use pair-programming, domain-driven design and test-driven development. I had many plans. It didn't turn out that way, the people on the team I worked with did not want to use pair-programming, DDD or TDD! <img src='http://blog.jayway.com/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>After a few years I gave up and came back to Jayway and I love it. The company has grown quite a bit, while I was away, and that is a good thing. Three years ago I probably thought that it was a bad thing. It isn't! Three years ago we had to come into a company as resource consultants, but now we, many times, come in as a team or get to do the project in-house. This is a really good thing. Getting to work with other Jayway people is a real Joy. They are smart, motivated and pragmatic. If I leave the project for a week, someone steps into my role and, everything works out fine. <a href="http://agilemanifesto.org/">People and interactions over processes and tools</a> is very, very true!</p>
<p>There are a many reasons why I think it is so nice to work at Jayway.</p>
<p><strong>Natural authority</strong> is a pattern from <a href="http://anders.janmyr.com/2009/11/adrenaline-junkies-and-template-zombies.html">Adrenaline Junkies and Template Zombies</a> that states:</p>
<blockquote><p>The meaning of an authority is a person who knows a great deal about something. Another meaning, in authority, is a person who is in charge. If someone who is <strong>an authority</strong> also is <strong>in authority</strong>, this is a natural authority.</p>
</blockquote>
<p>The person who knows best, gets to make the decisions. This is the way it is at Jayway. You are not assigned to a project, <strong>you are asked</strong> if you want to work on the project and, <strong>it is OK to say no</strong>.</p>
<p><strong>Management</strong>. My wife recently told me about a danish entrepreneur, Lars Kolind. He is usually called in when a company is not doing as well as it should. He talked about something that he called <a href="http://kolindkuren.dk/">Kolindkuren (the Kolind treatment)</a>. What he does in this treatment is that he turns things upside-down. And one specific thing he did was that instead of asking managers who they wanted as employees, he asked the employees who they wanted to have as managers. It turned out that no-one wanted many of the managers.</p>
<p>When I think about this and how this would work out if we did the same thing at Jayway, I don't think that anything would change. I am happy with my managers, I don't see them as managers, I see them as collegues who work to allow me to do the job I want to do. If I got to choose who I wanted to be my boss, I would choose exactly the people we have right now. And, I think we all feel the same way. An example of this came a few years ago.</p>
<blockquote><p>Thomas, the president of Jayway was fired by the board. What happened then was amazing, one week after Thomas was fired, 90 percent of the employees had resigned. <strong>If Thomas can't work for you, then we wont work for you</strong>, was the clear message that was sent. And it had effect, Thomas is back, the board is gone, and we are all happy.</p>
</blockquote>
<p><strong>Competence</strong> is the driving factor of everyone at Jayway. We all have different interests, but the common denominator is that everyone loves programming and want to get better at it. Take a look at this weeks competence workshops, and remember that they are all voluntary!</p>
<p><img src="http://2.bp.blogspot.com/_ELioussa2vo/SxFCBQD9gvI/AAAAAAAAAZ8/hYIqfG63PFk/s320/comptence_jayway.png" title="Competence Calendar at Jayway" alt="Competence Calendar" /></p>
<p><strong>Openness</strong> is very important to me. If I know why a decision has been made, I can understand why it was taken even though I may not agree with it. At Jayway all the managers write a short daily mail about what they are doing during the day. Every week Thomas updates the wiki with what is going on currently and what is planned for the future. Everything that does not have to be secret is open and available. If you want to find it, it is on the wiki.</p>
<blockquote><p>If a doctor wants to chop of my leg I would be happier with the decision if I knew that he wants to do this because I have an incurable tumor in the leg, instead of him wanting to practice his amputation skills.</p>
</blockquote>
<p>So, that is how it is to work at Jayway (at least in my mind). If you feel that competence and humbleness is more important than fancy titles, come and join us.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/11/29/working-at-jayway/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Under the Hood of &#8216;git clone&#8217;</title>
		<link>http://blog.jayway.com/2009/11/24/under-the-hood-of-git-clone/</link>
		<comments>http://blog.jayway.com/2009/11/24/under-the-hood-of-git-clone/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 05:02:08 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[version controlling]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2283</guid>
		<description><![CDATA[When you clone a git repository, everything is automatically setup to allow you to fetch, pull, push to and from the remote repository, origin. But what is really going on? git remote is configured with a few lines of configuration in the config file inside the .git/ directory. Here&#8217;s how it works: Create a new [...]]]></description>
			<content:encoded><![CDATA[<div id="mycontent">
<div class="paragraph">
<p>When you clone a git repository, everything is automatically setup to allow you to fetch, pull, push to and from the remote repository, origin. But what is really going on? <strong>git remote</strong> is configured with a few lines of configuration in the <strong>config</strong> file inside the <strong>.git/</strong> directory.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s how it works:</p>
</div>
<div class="listingblock">
<div class="title">Create a new repository, called base, add a file to it, then commit.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ mkdir base<span style="color: #990000">;</span>cd base<span style="color: #990000">;</span>git init
Initialized empty Git repository <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> /Users/andersjanmyr/tmp/repos/base<span style="color: #990000">/.</span>git<span style="color: #990000">/</span>
$ echo foo <span style="color: #990000">&gt;</span> bar<span style="color: #990000">.</span>txt
$ git add <span style="color: #990000">.</span>
$ git commit -m initial
<span style="color: #990000">[</span>master <span style="color: #990000">(</span>root-commit<span style="color: #990000">)</span> 548d762<span style="color: #990000">]</span> initial
 <span style="color: #993399">1</span> files changed<span style="color: #990000">,</span> <span style="color: #993399">1</span> insertions<span style="color: #990000">(+),</span> <span style="color: #993399">0</span> deletions<span style="color: #990000">(</span>-<span style="color: #990000">)</span>
 create mode <span style="color: #993399">100644</span> bar<span style="color: #990000">.</span>txt</tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Clone this repository, called klon.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ cd <span style="color: #990000">..</span>
$ git clone base klon
Initialized empty Git repository <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> /Users/andersjanmyr/tmp/repos/klon<span style="color: #990000">/.</span>git<span style="color: #990000">/</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Initialize a new repository, called kopy.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ mkdir kopy<span style="color: #990000">;</span>cd kopy<span style="color: #990000">;</span>git init
Initialized empty Git repository <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> /Users/andersjanmyr/tmp/repos/kopy<span style="color: #990000">/.</span>git<span style="color: #990000">/</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">The difference in configuration between the klon and the kopy.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ diff klon<span style="color: #990000">/.</span>git/config kopy<span style="color: #990000">/.</span>git/config
<span style="color: #993399">7</span><span style="color: #990000">,</span>12d6
<span style="color: #990000">&lt;</span> <span style="color: #990000">[</span>remote <span style="color: #FF0000">"origin"</span><span style="color: #990000">]</span>
<span style="color: #990000">&lt;</span>       fetch <span style="color: #990000">=</span> <span style="color: #990000">+</span>refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span>
<span style="color: #990000">&lt;</span>       url <span style="color: #990000">=</span> /Users/andersjanmyr/tmp/repos/base
<span style="color: #990000">&lt;</span> <span style="color: #990000">[</span>branch <span style="color: #FF0000">"master"</span><span style="color: #990000">]</span>
<span style="color: #990000">&lt;</span>       remote <span style="color: #990000">=</span> origin
<span style="color: #990000">&lt;</span>       merge <span style="color: #990000">=</span> refs/heads/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>To set up the newly created repository to work the same way the clone does, all I have to do is to edit this file to make it look the same. This is not what git does, so lets do it the git way.</p>
</div>
<div class="listingblock">
<div class="title">Fixing the remote configuration.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ cd kopy
$ git remote add origin /Users/andersjanmyr/tmp/repos/base</tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">This adds the [remote "origin"] entry to the config file.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="color: #990000">[</span>remote <span style="color: #FF0000">"origin"</span><span style="color: #990000">]</span>
        url <span style="color: #990000">=</span> /Users/andersjanmyr/tmp/repos/base
        fetch <span style="color: #990000">=</span> <span style="color: #990000">+</span>refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Fetching from the origin adds the remote heads to .git/.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ git fetch
remote<span style="color: #990000">:</span> Counting objects<span style="color: #990000">:</span> <span style="color: #993399">3</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">done</span></span><span style="color: #990000">.</span>
remote<span style="color: #990000">:</span> Total <span style="color: #993399">3</span> <span style="color: #990000">(</span>delta <span style="color: #993399">0</span><span style="color: #990000">),</span> reused <span style="color: #993399">0</span> <span style="color: #990000">(</span>delta <span style="color: #993399">0</span><span style="color: #990000">)</span>
Unpacking objects<span style="color: #990000">:</span> <span style="color: #993399">100</span><span style="color: #990000">%</span> <span style="color: #990000">(</span><span style="color: #993399">3</span><span style="color: #990000">/</span><span style="color: #993399">3</span><span style="color: #990000">),</span> <span style="font-weight: bold"><span style="color: #0000FF">done</span></span><span style="color: #990000">.</span>
From /Users/andersjanmyr/tmp/repos/base
 <span style="color: #990000">*</span> <span style="color: #990000">[</span>new branch<span style="color: #990000">]</span>      master     -<span style="color: #990000">&gt;</span> origin/master
$ find <span style="color: #990000">.</span>git/refs
<span style="color: #990000">.</span>git/refs<span style="color: #990000">/</span>
<span style="color: #990000">.</span>git/refs/heads
<span style="color: #990000">.</span>git/refs/remotes
<span style="color: #990000">.</span>git/refs/remotes/origin
<span style="color: #990000">.</span>git/refs/remotes/origin/master
<span style="color: #990000">.</span>git/refs/tags</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Now I can check out the <strong>origin/master</strong>, but if I do it the normal way, the configuration will not be set up correctly to allow me to pull and push the way i can with the clone.</p>
</div>
<div class="listingblock">
<div class="title">Checkout the master version with tracking information.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># DON'T DO THIS, It does not add the tracking information to the config file.</span></span>
$ git checkout -b master origin/master

<span style="font-style: italic"><span style="color: #9A1900"># This add the tracking information to the config file.</span></span>
$ git checkout --track -b master origin/master
Branch master <span style="font-weight: bold"><span style="color: #0000FF">set</span></span> up to track remote branch master from origin<span style="color: #990000">.</span>
Already on <span style="color: #FF0000">'master'</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">The following information is added to .git/config when --track is used.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="color: #990000">[</span>branch <span style="color: #FF0000">"master"</span><span style="color: #990000">]</span>
        remote <span style="color: #990000">=</span> origin
        merge <span style="color: #990000">=</span> refs/heads/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>That&#8217;s it! Now the <strong>.git/config</strong> file looks the same as if I had done a normal clone, but lets continue. What do the entries in the config file mean.</p>
</div>
<div class="listingblock">
<div class="title">Definition of the remote.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="color: #990000">[</span>remote <span style="color: #FF0000">"origin"</span><span style="color: #990000">]</span>
        url <span style="color: #990000">=</span> /Users/andersjanmyr/tmp/repos/base
        fetch <span style="color: #990000">=</span> <span style="color: #990000">+</span>refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span></tt></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Definition of the remote as git config commands.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ git config remote<span style="color: #990000">.</span>origin<span style="color: #990000">.</span>url /Users/andersjanmyr/tmp/repos/base
$ git config remote<span style="color: #990000">.</span>fetch <span style="color: #990000">=</span> <span style="color: #990000">+</span>refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span></tt></pre>
</div>
</div>
<div class="paragraph">
<p>The first part is just declaring the alias <strong>origin</strong> for the remote url (or local in this case <img src='http://blog.jayway.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
</div>
<div class="paragraph">
<p>The second part of the definition is more interesting. It sets up the <strong>refspec</strong> that will be used if you don&#8217;t provide anything on the command line. As we usually don&#8217;t provide a full refspec, most people don&#8217;t know what it is, this is extremely useful. In case you don&#8217;t know, the remote commands of git, <strong>push</strong>, <strong>pull</strong>, and <strong>fetch</strong> take a refspec as their last parameter. It is just that we usually just refer to a small part of it.</p>
</div>
<div class="listingblock">
<div class="title">Usage of the remote git commands.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>git pull <span style="color: #990000">&lt;</span>options<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>repository<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>refspec<span style="color: #990000">&gt;...</span>
git fetch <span style="color: #990000">&lt;</span>options<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>repository<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>refspec<span style="color: #990000">&gt;...</span>
git push <span style="color: #990000">&lt;</span>options<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>repository<span style="color: #990000">&gt;</span> <span style="color: #990000">&lt;</span>refspec<span style="color: #990000">&gt;...</span></tt></pre>
</div>
</div>
<div class="paragraph">
<p>The format of a <strong>refspec</strong> parameter is an optional <strong>plus +</strong>, followed by the source ref <strong>src</strong>, followed by a <strong>colon :</strong>, followed by the destination ref <strong>dest</strong>.</p>
</div>
<div class="paragraph">
<p>It defines what dest object should be updated by the src object.</p>
</div>
<div class="listingblock">
<div class="title">Example definition of refspec.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># The local</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># +&lt;src&gt;:&lt;dest&gt;</span></span>
<span style="color: #990000">+</span>refs/heads/spike<span style="color: #990000">:</span>refs/remotes/origin/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>In our day-to-day usage of git, we usually don&#8217;t use the full syntax of the refspec. Instead we just refer to simple names. Like this.</p>
</div>
<div class="listingblock">
<div class="title">Day-to-day usage of refspecs.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Push the local branch to the remote branch with the same name</span></span>
$ git push origin
<span style="font-style: italic"><span style="color: #9A1900"># Pull the master into the local master.</span></span>
$ git pull origin master
<span style="font-style: italic"><span style="color: #9A1900"># Fetch the master of the origin and put the result in the remote experimental</span></span>
$ git fetch origin master<span style="color: #990000">:</span>refs/remotes/origin/experimental</tt></pre>
</div>
</div>
<div class="paragraph">
<p>The above really means:</p>
</div>
<div class="listingblock">
<div class="title">Definition of the branch, expanded</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Push the local branch to the remote branch with the same name</span></span>
$ git push refs/heads<span style="color: #990000">/*:</span>refs/remotes/origin<span style="color: #990000">/*</span>
<span style="font-style: italic"><span style="color: #9A1900"># Pull the master into the local master.</span></span>
$ git pull origin refs/heads/master<span style="color: #990000">:</span>refs/remotes/origin/master
<span style="font-style: italic"><span style="color: #9A1900"># Fetch the master of the origin and put the result in the remote experimental</span></span>
$ git fetch origin refs/heads/master<span style="color: #990000">:</span>refs/remotes/origin/experimental</tt></pre>
</div>
</div>
<div class="paragraph">
<p>From the above syntax, it is also possible to decrypt the obscure syntax used when deleting a remote branch. Deleting is the same as pushing to a remote branch without giving a local branch.</p>
</div>
<div class="listingblock">
<div class="title">Delete a remote branch.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Delete the remote branch serverfix</span></span>
git push origin <span style="color: #990000">:</span>serverfix</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Now, we are down to the last part of the configuration, the branch definition.</p>
</div>
<div class="listingblock">
<div class="title">Definition of the branch</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="color: #990000">[</span>branch <span style="color: #FF0000">"master"</span><span style="color: #990000">]</span>
        remote <span style="color: #990000">=</span> origin
        merge <span style="color: #990000">=</span> refs/heads/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>The first part <strong>branch.master.remote</strong>, tells git to use <strong>origin</strong> as the default remote, if none is given for this local branch.</p>
</div>
<div class="paragraph">
<p>The second part tells git which remote branch to use when merging. This also affects pull and fetch. Depending on your settings of <strong>push.default</strong>, it will also affect push.</p>
</div>
<div class="paragraph">
<p>Hopefully this has clarified some of the intricacies of git remoting. Just remember that if you make a mistake, you can always fire up an editor and edit the config file directly.</p>
</div>
<div class="paragraph">
<p>I&#8217;ll finish up with some more commands that can be used to get information about the remote.</p>
</div>
<div class="listingblock">
<div class="title">Additional remote commands, to explore a remote.</div>
<div class="content"><!-- Generator: GNU source-highlight 3.0.1<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Show all remote branches</span></span>
$ git branch -r
  origin/cucumber
  origin/customercare-<span style="color: #993399">0.6</span><span style="color: #990000">.</span>x
  origin/master

<span style="font-style: italic"><span style="color: #9A1900"># Show all remotes verbosely</span></span>
$ git remote -v
origin  /Users/andersjanmyr/tmp/repos/base <span style="color: #990000">(</span>fetch<span style="color: #990000">)</span>
origin  /Users/andersjanmyr/tmp/repos/base <span style="color: #990000">(</span>push<span style="color: #990000">)</span>

<span style="font-style: italic"><span style="color: #9A1900"># Show info about the remote</span></span>
$ git remote show origin
<span style="color: #990000">*</span> remote origin
  Fetch URL<span style="color: #990000">:</span> /Users/andersjanmyr/tmp/repos/base
  Push  URL<span style="color: #990000">:</span> /Users/andersjanmyr/tmp/repos/base
  HEAD branch<span style="color: #990000">:</span> master
  Remote branches<span style="color: #990000">:</span>
    experimental stale <span style="color: #990000">(</span>use <span style="color: #FF0000">'git remote prune'</span> to remove<span style="color: #990000">)</span>
    master       tracked
  Local branch configured <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #FF0000">'git pull'</span><span style="color: #990000">:</span>
    master merges with remote master
  Local ref configured <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #FF0000">'git push'</span><span style="color: #990000">:</span>
    master pushes to master <span style="color: #990000">(</span>up to date<span style="color: #990000">)</span>

<span style="font-style: italic"><span style="color: #9A1900"># List the remote heads of the origin</span></span>
$ git ls-remote --heads origin
548d7624f5385d36314e8ab61e61e8872c0bfe90        refs/heads/master</tt></pre>
</div>
</div>
<div class="paragraph">
<p>That&#8217;s it for today.</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/11/24/under-the-hood-of-git-clone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adrenaline Junkies and Template Zombies</title>
		<link>http://blog.jayway.com/2009/11/10/adrenaline-junkies-and-template-zombies/</link>
		<comments>http://blog.jayway.com/2009/11/10/adrenaline-junkies-and-template-zombies/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 04:41:32 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2223</guid>
		<description><![CDATA[Since I had plenty of time to read on my flights back and forth to OOPSLA, I managed to read through a few books. One of them was Adrenaline Junkies and Template Zombies by Tom DeMarco et al. Being the sceptic that I am, my attitude when starting to read this book was: "Yeah, I [...]]]></description>
			<content:encoded><![CDATA[<p>Since I had plenty of time to read on my flights back and forth to OOPSLA, I managed to read through a few books. One of them was <a href="http://www.amazon.com/Adrenaline-Junkies-Template-Zombies-Understanding/dp/0932633676?tag=thtasta-20">Adrenaline Junkies and Template Zombies</a> by Tom DeMarco et al. Being the sceptic that I am, my attitude when starting to read this book was: "Yeah, I know a lot of people has praised this book and I know that Tom DeMarco has written <a href="http://www.amazon.com/Peopleware-Productive-Projects-Teams-Second/dp/0932633439?tag=thtasta-20">Peopleware</a>, but what the hell do <a href="http://www.systemsguild.com/">these bozos</a> know anyway!" <img src='http://blog.jayway.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I figured that the six of them could probably scrape together a few decent people patterns, but I am a bit fed up with the whole pattern template style, so my expectations were not as high as they should have been.</p>
<p>Anyway, the book is amazing, the pattern template is really lightweight, basically, a name, an image, a statement, and a story. And the stories, are <strong>good</strong>. The authors have a remarkable ability to observe human nature and also the ability to write about what they see.</p>
<h3>Some Patterns</h3>
<p>The book contains 86 patterns, most of them are negative since they are funnier, as one of the authors said on a podcast.</p>
<h4>Dead Fish</h4>
<p>A dead fish is a project, that every one knows is impossible to start out with, but nobody says anything since the culture in the company is that way.<br />
If you say something you may get responses like,</p>
<blockquote><p>Prove it! Prove that it is not feasible that this project will succeed!</p>
</blockquote>
<p>Or,</p>
<blockquote><p>Are you a weenie or a layabout?</p>
</blockquote>
<p>Projects like this are usually worked on until it is inevitable that they will be late, and then everybody acts surprised.</p>
<h4>Nanny</h4>
<p>A nanny is a project manager that is aware of the capabilities of her staff and nurtures them and lets them at their peek. The nanny is responsible for improving her staff and make responsible project citizen of them. A nanny enables workers to do their job.</p>
<h4>Eye Contact</h4>
<p>If your life depended on a project, would you want them working close together or in different corners of the world? Human communication goes way beyond words, and it is foolish to think that it is possible to work at full speed with people who don't know each other and live in different places.</p>
<h4>Dashboards</h4>
<p>A dashboard is a highly visible board, that enable the project members and others to get an instant view of the status of the project. It can be a web page or a board on the wall. What is significant with a dashboard is that it is updated as soon as anything important happens in the project. All project members care for the dashboard since that is the place where they can find out how they are doing. Dashboards contain just the right amount of data.</p>
<h4>Film Critics</h4>
<p>A film critic is a project member or someone related to the project who thinks that they can succeed even if the project is a failure. They may often have good points, but usually when it is too late to do something about it. It is no use to have a person like this on the team, since they are not really on the team if they don't go down with the ship.</p>
<h4>Natural Authority</h4>
<p>The word authority have several meanings. The meaning of <em>an authority</em> is a person who knows a great deal about something. Another meaning, <em>in authority</em>, is a person who is in charge. A person who is an authority and in authority is a natural authority. This is the healthy pattern.</p>
<h4>The White Line</h4>
<p>The white line is the line on a tennis court. The line is a clear signal if the ball is in or out. Occasional dispute may arise over a questionable judgment call, but the line is respected by everyone. Most projects don't have this line. Create a white line for your project so that you know what is inside the project scope and what is not.</p>
<h4>Silence Gives Consent</h4>
<p>If someone don't oppose an idea, it is, usually, taken as consent. Especially from people who come from different working areas, like management and programmers. Silent consent is not good for anyone, because nobody is sure what has been decided and what has not. A way to remedy this problem is to keep a list of commitments where it is written down who has promised who what. The Scrum sprint backlog is similar to such a list.</p>
<h4>Time Removes Cards from Your Hand</h4>
<p>The earlier a decision can be made, the better. If you know that a project will not make a deadline, the decision to change the scope should be made as early as possible, since that will allow the team to work on the most important features first. If a decision is delayed until it is too late, the decision is made implicitly by time.</p>
<h4>Rhythm</h4>
<p>Instead of being daunted by overwhelming tasks, projects with rhythm take small, regular steps thus establishing a regular beat that carries them toward their goal.</p>
<blockquote><p>This journey of a thousand miles begins with a single step --Lao Tzu</p>
</blockquote>
<h4>False Quality Gates</h4>
<p>False quality gates are quality checks that don't do anything to promote the quality of the project. It is a sign that more attention is concentrated on format, rather than content. It can be a glossary of terms with the wrong content or a word template where most of the sections are filled in with the words "This section must contain text to fulfill company guidelines".</p>
<h4>Testing Before Testing</h4>
<p>Testing before testing refers to the practice of thinking about <em>how</em> to test a feature at the same time you think about how to implement it. If it cannot be tested how can you know that it does what you say?</p>
<h4>Cider House Rules</h4>
<p>Cider house rules are rules written by someone unconnected to the project. Rules like this, that give no apparent value, are a burden to the project and therefore often ignored.</p>
<blockquote><p>Nobody pays attention to them rules. Every year Olive writes them up and every year nobody pays any attention to them. -- John Irving, The Cider House Rules</p>
</blockquote>
<h4>Talk Then Write</h4>
<p>The team makes decisions during conversation, and then immediately communicates the decisions in writing. <strong>This is a really important pattern that it is easy to forget!</strong>. A common place where this kind of decisions are written down is very helpful.</p>
<h4>Practicing the End Game</h4>
<p>A team that does not release often and regularly will often take a long time to make a release. The act of releasing a product should be practiced often so that is becomes a natural part of the project.</p>
<h4>Data Quality</h4>
<p>Data quality often sucks! A common solution is often to attack the problem with technology instead of putting in the manpower that is actually needed to improve the quality of the data. Company web-sites are the prime example of this. They are often full of completely useless information.</p>
<h4>Undivided Attention</h4>
<p>Complex work is hard and it requires undivided attention to be performed properly. Splitting people's attention over multiple project will severely hinder their performance.</p>
<blockquote><p>By doing two things at once, you've cut your IQ in half, and believe me, those 40 points can really make a difference. -- Dale Dauden, The New York Times</p>
</blockquote>
<h4>Orphaned Deliverables</h4>
<p>Orphaned deliverables are deliverables that no-one values enough to pay for. Always make sure that there is a sponsor for every artifact that you are developing.</p>
<h4>Hidden Beauty</h4>
<p>Hidden beauty inside a program, that little extra thing, that may seem unnecessary, is what shows that the creator cares about his work. <em>It is not unnecessary!</em> This caring is what separates a quality product from garbage.</p>
<h4>I Don't Know</h4>
<p>If you are afraid of saying the words, "I don't know!", you are probably working in an organization where saying it means that you will be taken for a fool. In a healthy organization, "I don't know!", means that you don't know, but you will in a while, if it is important enough.</p>
<h4>Loud and Clear</h4>
<p>Having a clear goal, that everyone agrees to, is vital to a project. Clear goals allows you to focus the project activity if it starts to move away from its purpose. A PAM statement, that contains the Purpose, Advantage, and Measurements of a project is very helpful.</p>
<h3>Conclusion</h3>
<p>The patterns described above are just my short summaries, and I don't do them justice, but hopefully I have awoken your interest in this wonderful book.</p>
<p>It made my top-ten list and I recommend it to everyone from programmer to president. I like that the authors don't always provide a solution, but instead just describe the way they see it, it is up to you to figure out a solution to the problem yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/11/10/adrenaline-junkies-and-template-zombies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Craftsman Analogy</title>
		<link>http://blog.jayway.com/2009/11/07/the-craftsman-analogy/</link>
		<comments>http://blog.jayway.com/2009/11/07/the-craftsman-analogy/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 11:54:19 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2214</guid>
		<description><![CDATA[The analogy of software developers as craftsmen has become very popular. I don't know where it started, but the first book I read about it was the excellent book The Pragmatic Programmer by Andy Hunt and Dave Thomas. I really liked this analogy, it seemed right. A few years later, Pete McBreen released the book [...]]]></description>
			<content:encoded><![CDATA[<p>The analogy of software developers as craftsmen has become very popular. I don't know where it started, but the first book I read about it was the excellent book <a href="http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X?tag=thtasta-20">The Pragmatic Programmer</a> by Andy Hunt and Dave Thomas. I really liked this analogy, it seemed right.</p>
<p>A few years later, Pete McBreen released the book <a href="http://www.amazon.com/Software-Craftsmanship-Imperative-Pete-McBreen/dp/0201733862?tag=thtasta-20">Software Craftsmanship</a>, where he articulates that software development should be more like craftsmanship. Pete writes eloquently about programming masters that should be paid ten times more than their apprentices because they are at least ten times more effective. The masters also have the responsibility to take on journeymen and apprentices to train in their particular flavor of software development. This also rang very true to me.</p>
<p>But, there is something fishy with this analogy. Something ain't right!</p>
<p>I have come to understand that the analogy refers to how it is believed that the craftsman "industry" worked ages ago, rather than how it is today. If you hire a carpenter today he may tell you that he will come "sometime next week". I have rarely been given a time that is more exact than a four hour span, to just meet up.</p>
<p>After the meeting has been scheduled, I have to be very lucky if my craftsman actually appears at the appointed time. Most of the time he will not show up at all!</p>
<p>If I happen to be lucky enough to get a craftsman to show up or to call and tell me that he can't make it, I usually make a note of this guy as being, <em>a highly reliable craftsman</em>, worth hiring again. He gets a golden star for just calling to tell me that he won't come.</p>
<p>When we finally meet up, the craftsman may do a terrific job and I will happily recommend him to anyone, but most likely we will talk and he will tell me that he doesn't have the time to do the job right now, but that he can come back tomorrow. If you let him go with that, he most likely will not come back tomorrow or the next day. He will come back when you call to remind him that he should have come back. And even better, if you pay him in advance you will never see him again, ever!</p>
<p>So, if our goal is to get programmers to be viewed as craftsmen, we're already there. Just change the statement <em>those f***ing carpenters never do what we expect!</em> to <em>those f***ing programmers never do what we expect!</em></p>
<p>Maybe the whole idea of programmers as craftsmen is just:</p>
<blockquote><p>It was better in the old days.</p>
</blockquote>
<p>It wasn't, it is better now!</p>
<p>I have learned one thing through all my years of programming:</p>
<blockquote><p>The more I learn, the more I learn how little I know. --Socrates</p>
</blockquote>
<p>I'm not a software craftsman, I'm a <a href="http://www.cs.utexas.edu/~EWD/transcriptions/EWD03xx/EWD340.html">humble programmer</a>, a good one, and proud of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/11/07/the-craftsman-analogy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>OOPSLA 2009 Thursday, October 29th</title>
		<link>http://blog.jayway.com/2009/10/29/oopsla-2009-thursday-october-29th/</link>
		<comments>http://blog.jayway.com/2009/10/29/oopsla-2009-thursday-october-29th/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 18:51:21 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2210</guid>
		<description><![CDATA[Moving Fast at Scale, Lessons Learned at Facebook, Robert Johnson Facebook has over 1 million active users per engineer. Slowing down to get it right is not a good idea, unless you know exactly that your idea is right. If you try things fast, you can try out more things and you can get feedback [...]]]></description>
			<content:encoded><![CDATA[<h3>Moving Fast at Scale, Lessons Learned at Facebook, Robert Johnson</h3>
<p>Facebook has over 1 million active users per engineer.</p>
<p>Slowing down to get it right is not a good idea, unless you know exactly that your idea is right. If you try things fast, you can try out more things and you can get feedback fast.</p>
<p>How do you get fast?</p>
<ul>
<li>Never block developers</li>
<li>Give developers control. At Facebook developers code, test and deploy. No QA is involved.</li>
<li>Tune processes for speed</li>
<li>No deadlines, but the site cannot go down.</li>
<li>Frequent small changes, no delays, easier to isolate bugs.</li>
<li>All development in trunk with weekly releases.</li>
<li> Deployment tools</li>
<li> Gatekeeper<br/>
</li>
<li>Do less work</li>
<li>Build tools</li>
<li>phpsh -interactive development</li>
<li>diffcamp - code review</li>
<li>XHProf - profiler</li>
<li>Scribe - moves data from server to central repository.</li>
<li>Hive - data warehouse infrastructure on top of hadoop</li>
<li>Work with open source</li>
</ul>
<p>How to deal with a lot of users?</p>
<ul>
<li>Scale Horizontally</li>
<li>Web Server, the relations have moved to the web layer from the database.</li>
<li>Memcache</li>
<li>Database, only used as a persistence layer. No joins etc.</li>
<li>Thrift</li>
<li>C++, Java, Erlang, Python</li>
</ul>
<p>Open Problems/Future Work<br />
<em> Languages for real-time data-access parallel with lots of dependencies.<br />
</em> Distributed indexing<br />
<em> Automatic clustering of data<br />
</em> Profiling of  parallel data<br />
* Better ways of expressing client and server code<br />
 + Javascript and PHP are not well matched.</p>
<h3>Toward Cloud-Agnostic Middlewares, E. Michael Maximilien</h3>
<h4>The Cloud Computing Landscape</h4>
<ul>
<li>Service Providers</li>
<li>Platform Providers</li>
<li>Service Brokers</li>
<li>Application Providers (SaaS)</li>
<li>Users</li>
</ul>
<h4>Challenges in Cloud Computing</h4>
<ul>
<li>Data lock-in</li>
<li>Application programming lock-in</li>
<li>Management lock-in</li>
<li>API lock-in</li>
<li>IncreaseRisk</li>
<li>Security and Privacy</li>
<li>Catastrophic failures</li>
<li>Business models and impacts</li>
</ul>
<h4>Research Opportunities</h4>
<ul>
<li>Cloud middleware</li>
<li>Agnostic wit respect to providers, frameworks and interfaces.</li>
<li>Learn Best Practices</li>
<li>Fluid cloud application deployment</li>
<li>Optimize could usage prices</li>
<li>Give indication of cloud readiness</li>
</ul>
<h4>Use Cases</h4>
<ul>
<li>COBRA Java text analytics solution. (JavaEE)</li>
<li>CoScripter application (RoR)</li>
<li>JumpStart sMash application (WebSphere, Smash)</li>
</ul>
<h4>The Architecture</h4>
<ul>
<li>Core APIs</li>
<li>Cloud APIs</li>
<li>Cloud Adapters</li>
<li>Clouds and Brokers</li>
</ul>
<h4>IBM Altocumulus</h4>
<p>Altocumulus is a configuration tool that helps you to deploy your application into different clouds. It supports multiple different service and platform providers. It helps you configure your deployment so that it follows the commonly known "good" practices. You can use it via the Web or via a RESTful API. It also supports Atom and RSS feeds. It is very interesting.</p>
<h4>Lessons Learned</h4>
<ul>
<li>Cloud Providers need to include some support service s to be enterprise ready</li>
<li>Cloud Providers need to expose flexible image creation facilities</li>
<li>Cloud virtual machines are mostly hardware based and their memory management is suboptimal</li>
<li>Best Practice Pattens works but need to evolve.</li>
<li>Standardized hardware is important when implementing cloud infrastructures</li>
<li>Instance monitoring capabilities should coma as part of the cloud facilities and APIs</li>
<li>The cloud space is still maturing</li>
</ul>
<h3>When Users Become Collaborators: Towards Continuous and Context-Aware User Input, Walid Maalej et al.</h3>
<p>User input is <em>critical</em> for the success of projects.</p>
<p>Various types of input:</p>
<ul>
<li>Field observation, Lead Users</li>
<li>Perpetual Beta, Legacy Documents, Usage Data</li>
<li>Issue and Bug Report, Enhancement Request, Feature Request</li>
<li>Workshop, Interview, Survey, Classification Requests</li>
</ul>
<h4>Built in Feedback Mechanisms</h4>
<p>Examples: Application Bug Reports, Application Usage Data, Discussion groups</p>
<p>Most applications don't have feedback mechanisms built into them.</p>
<p><em>Users are motivated by feedback, so if they submit a report and don't get any feedback, they will probably not do it again.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/10/29/oopsla-2009-thursday-october-29th/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OOPSLA 2009 Wednesday, October 28th</title>
		<link>http://blog.jayway.com/2009/10/29/oopsla-2009-wednesday-october-28th/</link>
		<comments>http://blog.jayway.com/2009/10/29/oopsla-2009-wednesday-october-28th/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 13:37:54 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[conference]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2207</guid>
		<description><![CDATA[This post is cross-posted at my personal blog. Jeannette Wing, CMU, Frontiers in Research and Education in Computing Jeanette said that there has been a paradigm shift. Not just about computing's metal tools (transistors and wires), but also our mental tools (abstraction and methods) Is this really a new paradigm shift? Maybe for the National [...]]]></description>
			<content:encoded><![CDATA[<p>This post is cross-posted at <a href="http://anders.janmyr.com">my personal blog</a>.</p>
<h3>Jeannette Wing, CMU, Frontiers in Research and Education in Computing</h3>
<p>Jeanette said that there has been a paradigm shift.</p>
<blockquote><p>Not just about computing's metal tools (transistors and wires), but also our mental tools (abstraction and methods)</p>
</blockquote>
<p>Is this really a new paradigm shift? Maybe for the National Science Foundation (NSF), certainly not for anyone that has been working with software the last ten years.</p>
<p>The limits of Moore's Law forces the NSF to focus on programming languages and abstractions.</p>
<p>Three drivers of computing research, Society, Science, Technology.</p>
<h4>Encouraged research areas:</h4>
<ul>
<li>Data Intensive Computing</li>
<li>Cloud Computing</li>
<li>
<p>Map-Reduce</p>
</li>
<li>
<p>Cyber-Physical Systems (computational core that interacts with the physical world)</p>
</li>
<li>Smart vehicles</li>
<li>Smart Flyers</li>
<li>
<p>Smart Devices</p>
</li>
<li>
<p>Network Science and Engineering</p>
</li>
<li>Understand the complexity of large scale networks
<ul>
<li><a href="http://www.research.att.com/~pamela/">Software Engineering for the Next Internet</a></li>
</ul>
</li>
<li>
<p>Trustworthy Computing</p>
</li>
<li>
<p>Socially Intelligent Computing</p>
</li>
<li>Humans are still much better at image recognition</li>
<li>
<p>Programs where the human is a port of the program.</p>
</li>
<li>
<p>IT and Sustainability (Energy, Environment, Climate)</p>
</li>
<li>
<p>Computer Science and Economics</p>
</li>
<li>AdSense</li>
<li>
<p>eBay</p>
</li>
<li>
<p>Computer Science and Biology</p>
</li>
</ul>
<h3>Agile development: Overcoming a short-term focus in implementing best practices, Karthik Dinakar</h3>
<p>In the project they concluded on the following good practices.</p>
<ul>
<li>Good version control</li>
<li>Coding guidelines</li>
<li>Build automation</li>
<li>Unit testing framework</li>
<li>Automatic sanity tests</li>
<li>Accurate task estimations</li>
<li>Effective pre-spring planning</li>
<li>Solid design discussions</li>
<li>Involve QA and Operations</li>
<li>Effective post-sprint-reviews</li>
</ul>
<p>They also thought that it is difficult to implement best practices under way.</p>
<p>They had many problems:</p>
<ul>
<li>Integration was not in the plan</li>
<li>Sprint backlog changing all the time.</li>
<li>Long sprint meetings</li>
</ul>
<p>Management did not allow them to implement the changes that they needed and the reason was <strong>"It's Agile!"</strong></p>
<p>All in all, their problems seemed to be the usual, they had no idea of what it meant to do Scrum in the first place. Don't people read books anymore?</p>
<h3>Are systems Green? Panel with Steve Easterbrook et al</h3>
<ul>
<li>A Google query has a Carbon footprint.</li>
<li>We don't know what it is.</li>
<li>It may actually be less than the energy it uses since it may permit the person posing the query to save a lot of energy.</li>
<li>The term Green is just marketing bullshit.</li>
<li>It is not measurable at all.</li>
<li>Carbon Emissions are permanent.</li>
<li>It won't go away even if we stop burning any carbon today.</li>
<li>The goal of emissions are <strong>ZERO</strong>, anything else is not sustainable.</li>
</ul>
<p>There is a book called <a href="http://www.amazon.com/Green-Dummies-Computer-Tech/dp/0470386886?ie=UTF8&amp;tag=thtasta-20">Green IT for Dummies</a></p>
<ul>
<li>What can we as a computing industry do.</li>
<li>Analyze the problem.</li>
<li>Make a list of what we need and can do.</li>
<li>Create a wiki.</li>
</ul>
<p><strong>If you are going to read an article for more than three minutes, YOU SHOULD PRINT IT OUT!</strong> Believe it or not, but check your facts.</p>
<h3>Architecture in an Agile World, Panel with Steven Fraser et al</h3>
<p><em>Randy Miller:</em> We allow the customers to make changes, but we don't tell them what the cost will be. If we have no architecture the cost will be high. The people behind the agile manifesto were all good at architecture and that is why the importance of architecture was not emphasized in the manifest.</p>
<p><em>Bill Opdyke:</em> Some people seem to see a difference between architects and agilists. But most people that are good don't have the this problem. Architects can learn from agilists that change is not that hard. Agilists can learn from architects that architecture matters. There is a middle ground.</p>
<p><em>Ethan Hadar:</em> We need a stable vision of what the architecture should be while delivering solutions iteratively. Show me the architecture road map of your product, because it will be integrated with another program in nine months. Accountability and responsibility for the architecture is important.</p>
<p><em>Dennis Mancl:</em> You need to plan architecture early, or you will have to do it later on and then it will be harder.</p>
<p><em>Audience:</em> How does an architect work in an agile team?</p>
<p><em>Randy Miller:</em> From an agile team, you're all part of the team. There are no distinctions. The architect is in the team to make sure that</p>
<blockquote><p>The architecture in the system is the point in time in which you have to step back and think about how everything interacts.</p>
</blockquote>
<p><em>Ethan Hadar:</em> The architect is the person, who needs to interact with the testers and operations to explain how and why the system is the way it is.</p>
<p><em>Dennis Mancl:</em> The architect is responsible to the stake holders and he is responsible to know the problem domain.</p>
<p><em>Irit Hadar:</em> The architect's role is to take a step back and say when it is time to review the architecture.</p>
<p><em>Audience:</em> The architecture is what you get, regardless of what you do.</p>
<p>An interesting discussion, that could not find a consensus to if there is a need for a single architect or not.</p>
<h3>Agile Anthropology and Alexander's Architecture, Jenny Quillien, Dave West, Pam Rostal</h3>
<p>Do we need to pay any interest of to Christopher Alexanders' new book <a href="http://www.amazon.com/Phenomenon-Life-Nature-Building-Universe/dp/0972652914?ie=UTF8&amp;tag=thtasta-20">The Nature of Order</a>?</p>
<p>The software community has always taken interest in Alexanders' books, but we take interest in the wrong things. We have only understood some rules, we have not grasped the deeper part of it, because we don't understand the culture of architecture.</p>
<p>In a pattern language, we looked at patterns, but we dismissed the QWAN. We missed the holistic point-of-view. Everything is part of the system, people, organizations. He is writing about things that are multi-dimensional and multi-faceted, not things that are simple and exact.</p>
<p>The Nature of Order contains the same multi-faceted ideas and if we look at it with the same eyes, we will miss the point again.</p>
<p>Alexander looked at centers and centers affect other centers. And there is no right or wrong, there are only degrees.</p>
<p>In Alexanders' world there is only one system, the Universe. Everything is connected!</p>
<h3>Writing Code for Other People, Tom Mullen</h3>
<h4>Chunking and Memory</h4>
<ul>
<li>The mind groups memory into chunks. Most chunks are stored in long-term memory. Out conscious is in long-term memory.</li>
</ul>
<p>Short-time memory can only hold about four relations. Short-time memory is also <em>short</em> <img src='http://blog.jayway.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  This gives us a time-limit when traversing code.</p>
<p>Meyers' open-closed principle is an echo of the mind's way to learn things.</p>
<p>If the code is a reflection of our brains, then most brains contain spaghetti.</p>
<h4>Analogies</h4>
<p>Analogies is the mapping between one thing to another.</p>
<h4>Conclusion</h4>
<p>Our brains are not good a processing more than four chunks at the time. This implies that we should write methods with less than four lines. Classes with less than four methods, modules with less than four classes, and applications with less than four modules.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/10/29/oopsla-2009-wednesday-october-28th/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Essential Java Generics</title>
		<link>http://blog.jayway.com/2007/02/01/essential-java-generics/</link>
		<comments>http://blog.jayway.com/2007/02/01/essential-java-generics/#comments</comments>
		<pubDate>Thu, 01 Feb 2007 13:46:56 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[jayview]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=3647</guid>
		<description><![CDATA[Once you get past simple usage of Java Generics and start implementing generic classes yourself it may seem quite intimidating. It is tricky, so it is important to remember a few rules. Subtyping The Liskov Substitution Principle, the rule that says that subclasses should be substitutable for their base classes, does not apply to generic [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Once you get past simple usage of Java Generics and start implementing generic classes yourself it may seem quite intimidating. It is tricky, so it is important to remember a few rules. </strong></p>
<h2>Subtyping</h2>
<p>The Liskov Substitution Principle, the rule that says that subclasses should be substitutable for their base classes, does not apply to generic elements! </p>
<ul>
<li> <code>Integer</code> is a subtype of <code>Number</code>.
<li> <code>Integer</code> is a subtype of <code>Comparable</code>.
<li> <code>List</code> is a subtype of <code>Collection</code>.
<li> <code>List&lt;Integer&gt;</code> is a subtype of <code>Collection&lt;Integer&gt;</code>.
<li> <code>List&lt;Integer&gt;</code> is <strong>not</strong> a subtype of List<code>&lt;Number&gt;</code>.
<li> <code>List&lt;Integer&gt;</code> is <strong>not</strong> a subtype of <code>List&lt;Comparable&gt;</code>.
</ul>
<pre>
// Example why generic elements are not proper subtypes:
List&lt;Integer&gt; integers = <strong>new</strong> LinkedList&lt;Integer&gt;;
List&lt;Number&gt; numbers = integers;    // Won’t compile!
numbers.add(3.14);                  // Integers cannot contain 3.14
</pre>
<p>The fact that the Liskovs Substitution Principle does not apply to generics restricts<br />
their usefulness; we need wildcards to loosen some of these restrictions. </p>
<h2>Wildcards</h2>
<p>To loosen the constraint above, <strong>wildcards</strong> may be used. Wildcards are used with the<br />
keywords extends and super. </p>
<ul>
<li> <code>&lt;? extends Number&gt;</code> means all types that are subclasses of <code>Number</code> are allowed.
<li> <code>&lt;? super Integer&gt;</code> means all types that are superclasses of <code>Integer</code> are allowed.
</ul>
<p><strong>The Get and Put Principle</strong>: use <code>extends</code> <strong>only</strong> when you intend to <strong>get</strong> values out of a<br />
structure. Use <code>super</code> <strong>only</strong> when you intend to <strong>put</strong> values into a structure. </p>
<p><code>The container</code> that you get something out of is guaranteed to contain elements that<br />
are instances of the expected class or of a subclass and may be used properly by the<br />
recipient of the get. </p>
<p><code>The container</code> that you put something into is guaranteed to contain at least in-<br />
stances of  the expected class or a superclass ensuring that the put is valid. </p>
<p>This also implies: <strong>don’t use any wildcards</strong> when you intend to <strong>both</strong> get and put<br />
values into and out of a structure. </p>
<pre>// Extends wildcard violation
List&lt;Integer&gt; integers = <strong>new</strong> LinkedList&lt;Integer&gt;();
List&lt;? <strong>extends</strong> Number> numbers = integers;
numbers.get(i);                                 // Works ﬁ ne!
numbers.add(3);                                 // Won’t compile!
// Super wildcard violation
List&lt;Number&gt; numbers = <strong>new</strong> LinkedList&lt;Number&gt;();
List&lt;? <strong>super</strong> Integer> integers = numbers;
integers.add(3);  // Works ﬁ ne!
<strong>int</strong> i = integers.get(0); // Won’t’ compile!
Object o = integers.get(0); // Works ﬁne, object is upper bound!
// Copy all elements, subclasses of T, from source to dest which con-
tains elements that are superclasses of T.
<strong>public static</strong> &lt;T&gt; <strong>void</strong> copy(List&lt;? <strong>super</strong> T> dest, List&lt;? <strong>extends</strong> T>
source) {
   <strong>for</strong> (<strong>int</strong> i = 0; i < source.size(); i++) {
       dest.set(i, source.get(i));
   }
}          </pre>
<p>In addition to the above principle there are also a few restrictions on wildcards:<br />
Don’t use wildcards when creating instances, specifying generic method calls or ex-<br />
tending superclasses: </p>
<pre>
List&lt;?&gt; integers = <strong>new</strong> LinkedList&lt;?&gt;();  // Won’t compile, instance
creation!
List&lt;?&gt; integers = Lists.&lt;?&gt;factory();   // Won’t compile, generic
method!
<strong>class</strong> AnyList <strong>implements</strong> List&lt;?&gt; {}      // Won’t compile, extend su-
perclass!
</pre>
<p>The syntax above is valid if any of the question marks is replaced by a proper class.<br />
The generic method is shown here in case the syntax looks unfamiliar. </p>
<pre>class Lists {
    static &lt;T&gt; List&lt;T&gt; factory() {
        return new LinkedList&lt;T&gt;();
    }
} </pre>
<h2>Bounds </h2>
<p>Bounds are used to make sure that generic parameters are of a speciﬁed subtype. </p>
<pre>
// The generic parameter of Query must extend (or implement) Entity and
Entity must have a getId method!
<strong>public class</strong> Dao&lt;T <strong>extends</strong> Entity&gt; {
   T createOrUpdate(T entity) {
       <strong>if</strong> (entity.getId() != null) {
           <strong>return</strong> update(entity);
       } <strong>else</strong> {
           <strong>return</strong> create(entity);
       }
   }
}
// Using Dao
// Works ﬁ ne since Person extends Entity!
Dao&lt;Person&gt; personDao = <strong>new</strong> Dao&lt;Person&gt;();
// Wont compile since String does not extend Entity!
Dao&lt;String&gt; stringDao = <strong>new</strong> Dao&lt;String&gt;(); </pre>
<p>Bounds may also be used in more advanced ways. The example below is a simpliﬁ ed<br />
version from <code>java.util.Collections</code> and show <code>a <strong>recursive</strong></code> bound. The generic<br />
parameter T is also used inside the bound <code>Comparable&lt;T&gt;</code> to make sure that the<br />
objects contained in the collection are comparable amongst themselves.</p>
<pre>// The method max takes a parameter which must contain elements of a
subclass of Comparable.
// In addition the Comparable class must be comparable with the declared
type
<strong>public static</strong> &lt;T <strong>extends</strong> Comparable&lt;T&gt;&gt; T max(Collection&lt;T&gt; collection)
{
   T currentMax = collection.iterator().next();
   <strong>for</strong> (T element: collection) {
       <strong>if</strong> (currentMax.compareTo(element) &lt; 0) currentMax = element;
   }
   <strong>return</strong> currentMax;
}</pre>
<p>By far the most difﬁ cult generic declaration comes from java.lang.Enum and looks<br />
like this <code>Class Enum&lt;E extends Enum&lt;E&gt;&gt; implements Comparable&lt;E&gt;</code>. Like the<br />
above declaration this is a recursive bound but it is even more constrained than the<br />
above. The key to understanding this is to know how enums are implemented in Java.  </p>
<pre>
// Declaring an enum
enum Tapir {MALAYAN, BRAZILIAN, BAIRD, MOUNTAIN}
// creates a class similar to this!
<strong>public ﬁnal class</strong> Tapir <strong>extends</strong> Enum&lt;Tapir&gt; <strong>implements</strong> Comparable&lt;Tapir&gt;
{
   <strong>private</strong> Tapir(String name, <strong>int</strong> ordinal) {<strong>super</strong>(name, ordinal)}
   <strong>public static ﬁnal</strong> Tapir MALAYAN = <strong>new</strong> Tapir(<strong>”MALAYAN”</strong>, 0);
   <strong>public static ﬁnal</strong> Tapir BRAZILIAN = <strong>new</strong> Tapir(<strong>”BRAZILIAN”</strong>, 1);
   <strong>public static ﬁnal</strong> Tapir BAIRD = <strong>new</strong> Tapir(<strong>”BAIRD”</strong>, 2);
   <strong>public static ﬁnal</strong> Tapir MOUNTAIN = <strong>new</strong> Tapir(<strong>”MOUNTAIN”</strong>, 3);
   <strong>private static ﬁnal</strong> Tapir[] VALUES = {MALAYAN, BRAZILIAN, BAIRD,
MOUNTAIN};
   <strong>public static</strong> Tapir[] values() {<strong>return</strong> VALUES.clone()}
   public static Tapir valueOf(String name) {
       <strong>for</strong> (Tapir t: VALUES) if t.getName().equals(name) <strong>return</strong> t;
       <strong>throw new</strong> IllegalArumentException();
   }
} </pre>
<p>As can be seen in the code above <code>E extends Enum&lt;E&gt;</code> maps to <code>Tapir extends<br />
Enum&lt;Tapir&gt;</code> and <code>Comparable&lt;E&gt;</code> maps to <code>Comparable&lt;Tapir&gt;</code>. This makes sure<br />
that enums of one type can only be compared with enums of the same type. The<br />
innermost generic parameter, <code>Enum&lt;E extends Enum&lt;<strong>E</strong>&gt;&gt;</code>, makes the subclass’ type<br />
available to the superclass, allowing it to deﬁ ne methods whose parameters and<br />
return values are that of the subclass’. </p>
<p>Generic parameters may also have multiple bounds. The signature of the simpliﬁ ed<br />
example above actually looks like this: </p>
<pre>// Actual signature of max from Java Collections
<strong>public static</strong> &lt;T <strong>extends</strong> Object & Comparable&lt;? <strong>super</strong> T&gt;&gt; T max(Collection&lt;?
<strong>extends</strong> T&gt; collection);
</pre>
<p>When multiple bounds appear the ﬁ rst bound is used for erasure and the reason for<br />
the <code>Object</code> in the signature above is that it makes the signature backwardly compat-<br />
ible. The reason for the <code>super</code> and the <code>extends</code> are the same as above to make the<br />
method more generic. </p>
<p>The method takes a collection of Ts or a collection of Ts subclasses (Collection&lt;? <strong>ex-<br />
tends</strong> T&gt;) where T or one of Ts superclasses implements Comparable with erasure<br />
Object (&lt;T <strong>extends</strong> Object & Comparable&lt;? <strong>super</strong> T&gt;&gt;). </p>
<h2>Erasure </h2>
<p>Java Generics is implemented by <strong>erasure</strong>. This means that the generic information<br />
is removed when the class is compiled:</p>
<ul>
<li> The erasure of <code>List&lt;Integer&gt;, List&lt;String&gt;, List&lt;List&lt;Integer&gt;&gt;</code> is <code>List</code>.
<li> The erasure of <code>Comparable&lt;? super T&gt;</code> is <code>Comparable</code>.
<li> The erasure of Object & Comparable is the leftmost, Object.
</ul>
<p>Another thing to be aware of is that the implementation of generics with erasure<br />
forces the compiler to insert additional methods into the class ﬁles. </p>
<pre>// Additional methods are compiled into generic classes
<strong>public interface</strong> Foo&lt;T&gt; {
   <strong>void</strong> foo(T param);
}
<strong>public class</strong> Bar <strong>implements</strong> Foo&lt;Bar&gt; { 

   // This method will appear twice once with Object as parameter and
once with Bar.
    <strong>public void</strong> foo(Bar param) {} 

   <strong>public static void</strong> main(String[] args) {
       <strong>for</strong> (Method m : Bar.<strong>class</strong>.getMethods())
           <strong>if</strong> (m.getName().startsWith(<strong>”foo”</strong>))
               System.out.println(m.toGenericString());
   }
} 

$ java Bar
public void Bar.foo(Bar)
public volatile void Bar.foo(java.lang.Object) </pre>
<p>This can trip you up if you try to overload a method to accept Object as a parameter<br />
too. It has never been a good idea to overload with Object as well as a subclass of<br />
Object but now it will not even compile: </p>
<pre>Error:line (6)name clash: foo(java.lang.Object) <strong>in</strong> Bar and foo(T) <strong>in</strong>
Foo&lt;Bar&gt; have the same erasure, yet neither overrides the other </pre>
<h2>Compatibility</h2>
<p>All in all, the implementation of generics in Java is a wonderful example of crafts-<br />
manship. The solution is <em>binary compatible</em> both backwardly and forwardly, allowing<br />
new code to use old libraries as well as allowing old code to use new libraries. I do,<br />
however, wish that they had skipped the compatibility and made generic classes<br />
aware of what they are at runtime. </p>
<p>If you want to know more about generics I highly recommend the book <strong>Java Gener-<br />
ics</strong> by Philip Wadler and Maurice Naftalin. </p>
<p><em>Originally published in <a href="http://jayway.se/jayview">JayView</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2007/02/01/essential-java-generics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
