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

  <title><![CDATA[Open Eyes Working Brain]]></title>
  <link href="http://federico.galassi.net/atom.xml" rel="self"/>
  <link href="http://federico.galassi.net/"/>
  <updated>2012-08-06T14:03:51+02:00</updated>
  <id>http://federico.galassi.net/</id>
  <author>
    <name><![CDATA[Federico Galassi]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[The Vim Holy Grail]]></title>
    <link href="http://federico.galassi.net/2012/06/20/the-vim-holy-grail/"/>
    <updated>2012-06-20T17:44:16+02:00</updated>
    <id>http://federico.galassi.net/2012/06/20/the-vim-holy-grail</id>
    <content type="html"><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/The_Da_Vinci_Code">Da Vinci Code</a> is an engaging fictional detective story about a great historical deception. The dark con of man, perpetrated against humanity. The <a href="http://en.wikipedia.org/wiki/Holy_Grail">Holy Grail</a> revealed to be nothing less than the ultimate proof of the deception and the key to set men free and change the world. It&#8217;s amazing how history can mislead people and how a single secret can debunk a long-standing myth. <a href="http://en.wikipedia.org/wiki/Vim_%28text_editor%29">Vim</a> is an old editor and the Vim community has long been a victim of such a myth: The <a href="http://en.wikipedia.org/wiki/Esc_key">Esc key</a>. With Vim best strength being hand posture and efficiency of the <a href="http://en.wikipedia.org/wiki/Touch_typing">home row</a>, tons of Vim users have been wondering</p>

<p>Why the hell is the Esc key so awkward to type?</p>

<p>And even feeling the pain, most of them just kept using it as it is, because that&#8217;s how it was conceived so it must be right. Welcome to the <a href="http://en.wikipedia.org/wiki/Historian's_fallacy">Historian&#8217;s Fallacy</a>. It&#8217;s that way but it was never conceived that way. Let me show you the Grail.</p>

<p><a href="http://federico.galassi.net/images/terminal_ADM-3A_keyboard.jpg"><img src="http://federico.galassi.net/images/terminal_ADM-3A_keyboard-e1340186979254.jpg" alt="Terminal ADM-3A" /></a></p>

<p>This is a <a href="http://en.wikipedia.org/wiki/ADM-3A">Lear Siegler ADM3A terminal</a>, produced in 1975. The one used by <a href="http://en.wikipedia.org/wiki/Bill_Joy">Bill Joy</a> while at <a href="http://en.wikipedia.org/wiki/University_of_California,_Berkeley">Berkeley</a> he developed the <a href="http://en.wikipedia.org/wiki/Ex_%28text_editor%29">Ex editor</a> and then <a href="http://en.wikipedia.org/wiki/Vi">Vi</a>, starting since summer 1976. Now look at the Esc key. It was where today the very convenient Tab key is, just top left of the home row! That&#8217;s why he chose it. But with the need of typing escape sequences going down and down, it was moved &#8230;</p>

<p><a href="http://federico.galassi.net/images/IBM_5150_Keyboard.jpg"><img src="http://federico.galassi.net/images/IBM_5150_Keyboard.jpg" alt="IBM 5150 Keyboard" /></a></p>

<p>Here in the <a href="http://en.wikipedia.org/wiki/IBM_PC_keyboard">IBM 83-key keyboard</a> (1981). And it was moved &#8230;</p>

<p><a href="http://federico.galassi.net/images/800px-ModelM.jpg"><img src="http://federico.galassi.net/images/800px-ModelM.jpg" alt="Model M" /></a></p>

<p>Here in the <a href="http://en.wikipedia.org/wiki/Model_M_keyboard">IBM Model M</a>, second half of the eighties. Where it was left for the next almost three decades, in the very inconvenient top left of the keyboard. <a href="http://en.wikipedia.org/wiki/Control_key">Control key</a> had the same fate, just in the other direction. The two fantastic spots close to the home row were taken respectively by the <a href="http://en.wikipedia.org/wiki/Tab_key">Tab key</a> and the <a href="http://en.wikipedia.org/wiki/Caps_lock">Caps lock key</a>. Now you know it was not meant to be that painful. That&#8217;s the great deception, but we can fix it by answering another one million dollar question</p>

<p>What the hell is the Caps lock needed for?</p>

<p>It turns out it&#8217;s even more legacy than Esc. It dates back to <a href="http://en.wikipedia.org/wiki/Typewriter">mechanical typewriters</a> (gosh) as a lock for the Shift key. Needed because pressing the Shift key physically shifted the positioning of the typebars relative to the ink ribbon, so it was tiring. It&#8217;s a dinosaur that can be sacrificed to rectify the flow and there are two reasonable ways. You could remap the Caps lock to Esc, and that would be fine. But there&#8217;s an even smarter approach i highly suggest if you have an easy to type &#8220;[&#8221; key (like in the <a href="http://en.wikipedia.org/wiki/Keyboard_layout#United_States">US layout</a>):</p>

<p><strong>Remap your Caps lock to Control and use Vim alternative way to Esc, that is Control + [</strong></p>

<p>Caps lock (as Control) and &#8220;[&#8221; are keys very close to the home row, hit by different hands, so hardly more difficult than typing Caps lock (as Esc) alone. What&#8217;s nice is you can also benefit when typing those Control/something combos that are pretty common. This way you&#8217;ll get the best of both worlds and guess what, if you have a nice OS <a href="http://docs.info.apple.com/article.html?path=Mac/10.4/en/mh1011.html">that&#8217;s gonna take just 30 seconds</a>. For the others <a href="http://www.google.com/">Google</a> is your friend.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Global Education 1.0]]></title>
    <link href="http://federico.galassi.net/2012/03/17/global-education-1-0/"/>
    <updated>2012-03-17T14:13:53+01:00</updated>
    <id>http://federico.galassi.net/2012/03/17/global-education-1-0</id>
    <content type="html"><![CDATA[<p><img alt="" src="http://federico.galassi.net/images/global_education-150x150.jpg" class="post_image" />I am a knowledge worker. Seeking new knowledge in computer science and technologies is part of my job and i know that finding good knowledge is about finding good sources. There are many of them: <a href="http://www.ruby-lang.org/en/community/">good language communities</a>, <a href="http://pragprog.com/titles">good</a> <a href="http://shop.oreilly.com/category/browse-subjects.do">publishers</a>, <a href="http://www.crockford.com/">good people</a>. But there are places that are real <a href="http://thetalentcode.com/">hotbeds</a>, in which all the cool things seem to happen, over and over again. They&#8217;re top american engineering and technology universities. It&#8217;s where most of the history of computers happened. From <a href="http://en.wikipedia.org/wiki/Vi#Creation">Bill Joy coding up Vi for BSD</a> at <a href="http://berkeley.edu/">Berkeley</a>, to <a href="http://mitpress.mit.edu/sicp/">Abelson and Sussman teaching SICP</a> at <a href="http://mit.edu/">MIT</a>, to <a href="http://en.wikipedia.org/wiki/Google#History">Brin and Page starting Google as a research project</a> at <a href="http://www.stanford.edu/">Stanford</a>, to many many more. These are places you have absolutely to watch out for good stuff.</p>

<p>Traditionally top universities have always been elitist with knowledge considered a precious good for a few who typically can pay big money. But with the advent of internet something changed. A first wave of web projects came out with the intent of giving free public online education. <a href="http://ocw.mit.edu/index.htm">MIT OpenCourseWare</a> and <a href="http://webcast.berkeley.edu/">Berkeley Webcast</a> in 2002 and later <a href="http://see.stanford.edu/">Stanford Engineering Everywhere</a>. They all started to give out material of some of their courses and then kept expanding their offer. Free education for the masses, but with one glaring omission compared to their traditional curricula. You get this as a gift, but you&#8217;re on your own. No feedback loop, no legal recognition, no tutoring. These are for &#8220;real&#8221; alumni only.</p>

<p>Today, with internet getting faster, social networks exploding, technology advancing, the snowball is really starting to roll down hill. You can see it from the second wave of sites. Recently born <a href="http://www.coursera.org/">Coursera</a>, <a href="http://www.udacity.com/">Udacity</a>, <a href="http://mitx.mit.edu/">MITx</a> are now taking online enrollments, giving some tutoring through forums, real-time schedules, exercises automatically checked, short digestible video lectures, certificates of completion. The idea that excellent education, with the <a href="http://classx.stanford.edu/ClassX/stanford_front_pages/Showcase/demos.php">help of technology</a>, can stop being a scarce good traded for another scarce good, money, is really catching on. Maybe good education can <a href="http://en.wikipedia.org/wiki/Post_scarcity">be abundant</a>, freely available everywhere, so as to improve the entire world, digging up the actual most precious resource: talented, well educated, smart people.</p>

<p>What&#8217;s next? The point is education for the masses is not only good for the world, it can be also very good for the wallet. Cutting costs, giving ubiquitous access and making their curricula more flexible and self-paced can open these educators to a new world full of potential clients craving to learn from the best. You can already tell it because these initiatives are starting as private commercial companies <a href="http://www.udacity.com/us">backed by investors</a>. It doesn&#8217;t take much to figure out which will be the last fig leaf to fall off. In the next years, we&#8217;ll see education still given for free, but greatly expanded and side by side with commercial services, more certificates and, in the end, real online degrees with legal recognition. Freemium mainstream education, what a great opportunity. Don&#8217;t miss it, <a href="http://www.class-central.com/">start now</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Die Semicolon Die!]]></title>
    <link href="http://federico.galassi.net/2011/05/25/die-semicolon-die/"/>
    <updated>2011-05-25T21:05:54+02:00</updated>
    <id>http://federico.galassi.net/2011/05/25/die-semicolon-die</id>
    <content type="html"><![CDATA[<p><img alt="" src="http://federico.galassi.net/images/semicolon.jpg" class="post_image" />I&#8217;ve always put <a href="http://en.wikipedia.org/wiki/JavaScript_syntax#Whitespace_and_semicolons">javascript&#8217;s automatic semicolon insertion</a> (ASI for short) under the bad parts of the language. That is based on <a href="http://googlecode.blogspot.com/2009/03/doug-crockford-javascript-good-parts.html">Douglas Crockford&#8217;s explanation</a> of how the feature is tricky and easily leads to mistakes, with the canonical example being:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="c1">// good, returns the object</span>
</span><span class='line'><span class="k">return</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// wrong! returns undefined</span>
</span><span class='line'><span class="k">return</span>
</span><span class='line'>    <span class="p">{</span>
</span><span class='line'>        <span class="p">...</span>
</span><span class='line'>    <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Fair enough. Lately i&#8217;ve been doing more and more ruby. Ruby is a language universally praised for its elegant, easy to read syntax. One of the strong points of the syntax is its terseness, that is, you can <a href="http://martinfowler.com/bliki/SyntacticNoise.html">omit a lot of punctuation</a>. Semicolons as well. Wait a moment&#8230;</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">def</span> <span class="nf">test</span>
</span><span class='line'>    <span class="k">return</span>
</span><span class='line'>        <span class="p">{</span>
</span><span class='line'>            <span class="o">.</span><span class="n">.</span><span class="o">.</span>
</span><span class='line'>        <span class="p">}</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="nb">test</span> <span class="c1"># returns nil !!</span>
</span></code></pre></td></tr></table></div></figure>


<p>Same thing! Having the meaning of a program change due to an end-of-line is not a good thing in ruby as well, but it&#8217;s widely accepted because of the benefits. This must be true for javascript as well, so first point:</p>

<p><strong>Removing semicolons and other punctuation clutter is not just a liability. It actually makes your code look better.</strong></p>

<p>So both the languages have to decide when a statement implicitly terminates. But is ruby implementation really the same as javascript? It turns out it&#8217;s not, ruby takes a quite safer approach. A statement in ruby is finished on an end-of-line if it&#8217;s syntactically valid by itself, it spans multiple lines if it&#8217;s not:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># this works, the trailing dot means the statement is not finished</span>
</span><span class='line'><span class="n">object</span><span class="o">.</span>
</span><span class='line'>    <span class="n">method1</span><span class="o">.</span>
</span><span class='line'>    <span class="n">method2</span><span class="o">.</span>
</span><span class='line'>    <span class="n">method3</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># syntax error, first line is a valid statement by itself, second line calls method1 on nothing</span>
</span><span class='line'><span class="n">object</span>
</span><span class='line'>    <span class="o">.</span><span class="n">method1</span>
</span><span class='line'>    <span class="o">.</span><span class="n">method2</span>
</span><span class='line'>    <span class="o">.</span><span class="n">method3</span>
</span></code></pre></td></tr></table></div></figure>


<p>It&#8217;s safe because how a line is parsed depends on the line itself, not by other lines that could be written &#8220;by others&#8221;. The bad part is how it makes method chaining on multiple lines look ugly. This is why ruby 1.9 introduced the exception &#8220;the statement continues if the first character of next line is a dot&#8221;.</p>

<p>Javascript takes a step further to solve this bad part. A controversial step. A statement is finished on an end-of-line if the first character of the next line cannot be correctly parsed as if it was part of the line. Otherwise, the statement goes on. This removes the clutter and gives nice chaining:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="c1">// just works</span>
</span><span class='line'><span class="nx">object</span>
</span><span class='line'>    <span class="p">.</span><span class="nx">method1</span><span class="p">()</span>
</span><span class='line'>    <span class="p">.</span><span class="nx">method2</span><span class="p">()</span>
</span><span class='line'>    <span class="p">.</span><span class="nx">method3</span><span class="p">()</span>
</span></code></pre></td></tr></table></div></figure>


<p>Unfortunately, you now have a nasty problem. 2 lines which are supposed to be 2 different statements, but with the first character of the second line being a valid continuation of the first, will be treated as one statement with unpredictable results. This practically happens only when a line starts with either ( [ + - /</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="c1">// function call instead of grouping</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">b</span> <span class="o">+</span> <span class="nx">c</span>
</span><span class='line'><span class="p">(</span><span class="nx">d</span> <span class="o">+</span> <span class="nx">e</span><span class="p">).</span><span class="nx">print</span><span class="p">()</span>
</span><span class='line'><span class="c1">// is really</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">b</span> <span class="o">+</span> <span class="nx">c</span><span class="p">(</span><span class="nx">d</span> <span class="o">+</span> <span class="nx">e</span><span class="p">).</span><span class="nx">print</span><span class="p">()</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// array index instead of array literal</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">]</span>
</span><span class='line'><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">].</span><span class="nx">forEach</span><span class="p">(</span> <span class="p">...</span> <span class="p">)</span>
</span><span class='line'><span class="c1">// is really</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">].</span><span class="nx">forEach</span><span class="p">(</span> <span class="p">...</span> <span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// binary math operator instead of unary</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">b</span> <span class="o">+</span> <span class="nx">c</span>
</span><span class='line'><span class="o">-</span><span class="mi">1</span> <span class="o">==</span> <span class="nx">string</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">query</span><span class="p">)</span> <span class="o">||</span> <span class="nx">die</span><span class="p">()</span>
</span><span class='line'><span class="c1">// is really</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">b</span> <span class="o">+</span> <span class="nx">c</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">==</span> <span class="nx">string</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">query</span><span class="p">)</span> <span class="o">||</span> <span class="nx">die</span><span class="p">()</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// division instead of regular expression</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span>
</span><span class='line'><span class="o">/</span><span class="p">[</span><span class="nx">a</span><span class="o">-</span><span class="nx">z</span><span class="p">]</span><span class="o">/</span><span class="nx">g</span><span class="p">.</span><span class="nx">exec</span><span class="p">(</span><span class="nx">s</span><span class="p">)</span>
</span><span class='line'><span class="c1">// is really</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span> <span class="o">/</span><span class="p">[</span><span class="nx">a</span><span class="o">-</span><span class="nx">z</span><span class="p">]</span><span class="o">/</span><span class="nx">g</span><span class="p">.</span><span class="nx">exec</span><span class="p">(</span><span class="nx">s</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>Well, this sucks, so what should you do? I could say that i remember being caught by this problem just once in many years of javascript. The return problem or starting a line the nasty way is something <em>extremely rare</em>. But even if you don&#8217;t want to afford the risk, why avoid ASI without even knowing about it? Without even thinking about a reasonable fix, given the nicer syntax? And this leads me to the second point:</p>

<p>To write semicolon-free code and avoid getting bitten, you just need to remember 2 rules:</p>

<ol>
<li><strong>Don&#8217;t put an end-of-line between return, break, continue, throw, postfix ++, postfix &#8211; and their operand</strong></li>
<li><strong>Avoid starting a line with ( [ +  - / but if you have to, prepend it with a semicolon</strong></li>
</ol>


<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="c1">// everything&#39;s fine</span>
</span><span class='line'><span class="k">return</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span>
</span><span class='line'><span class="k">continue</span> <span class="nx">label</span>
</span><span class='line'><span class="k">break</span> <span class="nx">label</span>
</span><span class='line'><span class="k">throw</span> <span class="nx">error</span>
</span><span class='line'><span class="nx">counter</span><span class="o">++</span>
</span><span class='line'><span class="nx">counter</span><span class="o">--</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">b</span> <span class="o">+</span> <span class="nx">c</span>
</span><span class='line'><span class="p">;(</span><span class="nx">d</span> <span class="o">+</span> <span class="nx">e</span><span class="p">).</span><span class="nx">print</span><span class="p">()</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">]</span>
</span><span class='line'><span class="p">;[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">].</span><span class="nx">forEach</span><span class="p">(</span> <span class="p">...</span> <span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">b</span> <span class="o">+</span> <span class="nx">c</span>
</span><span class='line'><span class="p">;</span><span class="o">-</span><span class="mi">1</span> <span class="o">==</span> <span class="nx">string</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">query</span><span class="p">)</span> <span class="o">||</span> <span class="nx">die</span><span class="p">()</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span>
</span><span class='line'><span class="p">;</span><span class="sr">/[a-z]/g</span><span class="p">.</span><span class="nx">exec</span><span class="p">(</span><span class="nx">s</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>Is it that taxing to remember? Automatic semicolon insertion is of course controversial, but using it is not a complete failure. It&#8217;s a matter of taste, a trade-off between cleaner nicer code and some tough albeit avoidable pitfall.</p>

<p>While i&#8217;m at it, let&#8217;s debunk some well known myths that always show up</p>

<ul>
<li><p><strong>&#8220;I could know ASI but others don&#8217;t and they will mess things out&#8221;</strong>
Well this may be true. It depends on where you work, the skill of your peers, etc.. To me, a javascript programmer is just supposed to know this stuff as he knows of prototype and first class functions. If they don&#8217;t, supposing they got the opposable thumbs, as they can be told to put semicolons everywhere, they can be told to remember the above 2 simple rules.</p></li>
<li><p><strong>&#8220;It&#8217;s not gonna work the same way on every browser&#8221;</strong>
It&#8217;s in the specs since more than a decade. I think browser bugs are a thing of the past and even proponents of this theory look unable to find <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=238945">something newer than 5 years ago</a>, so.</p></li>
<li><p><strong>&#8220;It breaks the tools. You cannot minify code anymore, etc&#8230;&#8221;</strong>
Let&#8217;s be clear about this. It&#8217;s officially part of the language. A tool unable to cope with ASI is a broken tool, period. Anyway, i have never had a problem with <a href="http://code.google.com/closure/compiler/">google closure compiler</a>.<strong> </strong></p></li>
<li><p><strong>&#8220;Jslint doesn&#8217;t work with it&#8221;</strong>
<a href="http://www.jslint.com/">Jslint</a> enforces the vision of Douglas and it&#8217;s pretty strict about it. This is fair, yet for those having another vision nothing is wrong with using <a href="http://jshint.com/">Jshint</a> which has an option to accept ASI. <strong> </strong></p></li>
</ul>


<p>Let&#8217;s close with two very nice articles that explain the details and of course you can always read the ecmascript specs:</p>

<p><a href="http://inimino.org/~inimino/blog/javascript_semicolons">The most well-written comprehensive article</a></p>

<p><a href="http://lucumr.pocoo.org/2011/2/6/automatic-semicolon-insertion/">Very good explanation of the pitfalls</a></p>

<p><a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">The plain specs </a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Lot of Javascript Love]]></title>
    <link href="http://federico.galassi.net/2010/11/12/a-lot-of-javascript-love/"/>
    <updated>2010-11-12T01:22:39+01:00</updated>
    <id>http://federico.galassi.net/2010/11/12/a-lot-of-javascript-love</id>
    <content type="html"><![CDATA[<p><img alt="" src="http://federico.galassi.net/images/love_bear_small.jpg" class="post_image" />I am back from <a href="http://webtechcon.it/">Webtech Conference Italia 2010</a>. One of the first in Italy featuring a full <a href="http://webtechcon.it/2010/sessions/?tid=1752">javascript day</a> with six talks. Not counting javascript related talks in other tracks. It has been exciting to see javascript explained in patterns, historically and computationally analyzed, tuned for faster websites, organized in popular libraries, used to query modern databases, to extract data from the web, to mashup those data, to program mobile devices, improved in latest browsers and at last on the server side to build scalable, fast network applications.</p>

<p>We&#8217;re witnessing the exponential rise of a neglected little broken language. A language that obviously started with <a href="http://en.wikipedia.org/wiki/First-class_function">something very right</a> and <a href="http://www.yuiblog.com/blog/2008/08/14/premature-standardization/">grew up even better</a>.</p>

<p>A language that is finally gonna get A LOT of love.</p>

<p>P.S. Here are my talks:</p>

<iframe src="http://www.slideshare.net/slideshow/embed_code/5742893" width="427" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen> </iframe>


<p> <div style="margin-bottom:5px"> <strong> <a href="http://www.slideshare.net/fgalassi/event-driven-javascript" title="Event Driven Javascript" target="_blank">Event Driven Javascript</a> </strong> from <strong><a href="http://www.slideshare.net/fgalassi" target="_blank">Federico Galassi</a></strong> </div></p>

<p><strong>update</strong>: now i am linking to the updated version of javascript the new parts given at Javascript Day 2011.</p>

<iframe src="http://www.slideshare.net/slideshow/embed_code/7944920" width="427" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen> </iframe>


<p> <div style="margin-bottom:5px"> <strong> <a href="http://www.slideshare.net/fgalassi/javascript-the-new-parts-v2" title="Javascript the New Parts v2" target="_blank">Javascript the New Parts v2</a> </strong> from <strong><a href="http://www.slideshare.net/fgalassi" target="_blank">Federico Galassi</a></strong> </div></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Complexity killed the Wave]]></title>
    <link href="http://federico.galassi.net/2010/08/07/complexity-killed-the-wave/"/>
    <updated>2010-08-07T02:11:41+02:00</updated>
    <id>http://federico.galassi.net/2010/08/07/complexity-killed-the-wave</id>
    <content type="html"><![CDATA[<p><img alt="" src="http://federico.galassi.net/images/nelson.jpg" class="post_image" />So, Google is going to <a href="http://googleblog.blogspot.com/2010/08/update-on-google-wave.html">kill Wave</a>.</p>

<blockquote><p>But despite these wins, and numerous loyal fans, Wave has not seen the user adoption we would have liked. We don’t plan to continue developing Wave as a standalone product, but we will maintain the site at least through the end of the year and extend the technology for use in other Google projects.</p></blockquote>

<p>That&#8217;s a great example of why &#8220;do one thing well&#8221; is better than &#8220;do it all&#8221;. Not only because, as <a href="http://en.wikipedia.org/wiki/Gall's_law">Gall&#8217;s law</a> implies, it&#8217;s easier to get a simple system straight, but also because once you get a complex system straight, you still have to make people get their mind around it. Wave made chat and e-mail play well together, with a great replay feature, bots and translation. Twitter gives short text updates. Adoption declared the winner, but we <a href="http://federico.galassi.net/2009/06/09/google-wave-fallacy/">already knew it</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Please Don't Touch the Slow Parts]]></title>
    <link href="http://federico.galassi.net/2010/05/08/please-dont-touch-the-slow-parts/"/>
    <updated>2010-05-08T13:58:09+02:00</updated>
    <id>http://federico.galassi.net/2010/05/08/please-dont-touch-the-slow-parts</id>
    <content type="html"><![CDATA[<p>I spoke at <a href="http://www.bettersoftware.it">Better Software</a> 2010, together with <a href="http://www.ideato.it">Fullo</a>, about speeding up web applications. The talk draws heavily from <a href="http://www.stevesouders.com/">Steve&#8217;s work</a>, but it&#8217;s a little bit different from current literature because it tries to organize best practices not as flat list but under macro-areas emerged as &#8220;slow parts&#8221;. Also, i concluded with <a href="http://federico.galassi.net/2009/11/15/javascript-performance-make-the-browser-happy-and-you-sad/">my obsession</a> that complexity inherently introduced by performance optimizations should not be dealt with by programmers directly, but by means of automation and abstraction.</p>

<p>Here it is.</p>

<p><strong>update</strong>: now i am linking to the extended version which i gave at From the Front 2011</p>

<iframe src="http://www.slideshare.net/slideshow/embed_code/7315806" width="427" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen> </iframe>


<p> <div style="margin-bottom:5px"> <strong> <a href="http://www.slideshare.net/fgalassi/please-dont-touch-the-slow-parts-v3" title="Please Don&#39;t Touch the Slow Parts V3" target="_blank">Please Don&#39;t Touch the Slow Parts V3</a> </strong> from <strong><a href="http://www.slideshare.net/fgalassi" target="_blank">Federico Galassi</a></strong> </div></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Happy Birthday Blog]]></title>
    <link href="http://federico.galassi.net/2010/04/03/happy-birthday-blog/"/>
    <updated>2010-04-03T17:04:28+02:00</updated>
    <id>http://federico.galassi.net/2010/04/03/happy-birthday-blog</id>
    <content type="html"><![CDATA[<p>Exactly one year ago i posted here for the first time. <a href="http://federico.galassi.net/2009/04/03/hello-world/">A hello world</a> tentatively saying &#8220;Let&#8217;s see what happens&#8221;. Now, a year, 16 posts and more than 1000 unique visitors later i can state that maybe it didn&#8217;t happen that much, but i liked the journey. So, let&#8217;s celebrate this first year with a collage of people, places, companies, technologies, tools, products, devices, books, etc&#8230; that influenced and, sometimes, even inspired me in my professional life . Thanks to all.</p>

<p><img src="http://federico.galassi.net/images/blog_birthday_1_small.png" alt="" /></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[All Software Works Ok]]></title>
    <link href="http://federico.galassi.net/2010/04/01/all-software-works-ok/"/>
    <updated>2010-04-01T01:58:10+02:00</updated>
    <id>http://federico.galassi.net/2010/04/01/all-software-works-ok</id>
    <content type="html"><![CDATA[<p><img alt="" src="http://federico.galassi.net/images/drinking_bird.jpg" class="post_image" />We live in times of complexity, and even though <a href="http://nodejs.org/">neat technologies</a> and <a href="http://nokogiri.org/">elegant software</a> can be found at times, the market is still definitely dominated by absurdly heavy solutions. <a href="http://www.tbray.org/ongoing/When/201x/2010/01/02/Doing-It-Wrong">Enterprise is imploding</a> and a wind of change towards <a href="http://en.wikipedia.org/wiki/NoSQL">more sustainable approaches</a> is blowing all around us, yet the mainstream scene is comparatively stagnant and all the pain inflicted to people is not really causing the deserved rebellion.</p>

<p>Why is that? Why when confronted by the possibility of rewriting their untestable bloatware, customer&#8217;s reply is almost always invariably &#8220;No, we don&#8217;t need it. We&#8217;ll just have to fix known bugs and add a couple of features, because right as it is, the software works ok&#8230;&#8221;?. What does &#8220;works ok&#8221; really mean? In my experience, it translates roughly to &#8220;The software does not physically blows up our office, it does some of the things we need to do, and over the years our employees have developed a thick skin against all the nuisances and a baggage of manual tricks, passed on by mouth, to get the rest of the work done anyway. Oh, and we already paid a lot for it&#8221;.</p>

<p>Recently, i got a taste of this mindset myself, when i booked online 2 tickets to <a href="http://www.avatarmovie.com/">Avatar</a> at the <a href="http://www.cinedream.it/">local cineplex</a></p>

<blockquote><p>&#8220;Hello this is my reservation code&#8221;</p></blockquote>

<p>&#8220;Sorry Mr, those seats are reserved&#8221;</p>

<p>&#8220;Sure, by me&#8221;</p>

<p>&#8220;No, actually by others&#8221;</p>

<p>&#8220;What? see, i made this online reservation&#8230;&#8221;</p>

<p>&#8220;I see, but we take reservations both online and by phone, sometimes they overlap and phone is given priority&#8221;</p>

<p>&#8220;Overlap?! No trust me, i am a programmer, overlapping reservations are not supposed to happen, because your system has to take care&#8221;</p>

<p>&#8220;Oh, but evidently it doesn&#8217;t&#8221;</p>

<p>&#8220;WTF?!?!&#8221;</p>

<p>&#8220;Please, don&#8217;t get mad, i am gonna give you other seats. Today is not even bad. You should see how many angry people we must manage during christmas holidays when all movies are sold out!&#8221;.</p>

<p>Now, given that reservation means <em>&#8220;An arrangement by which accommodations are secured in advance&#8221;</em>, how would you rate a reservation system that does not guarantee secure accommodations? Like a fish unable to breathe underwater, yet they live with it, and this takes me to the point.</p>

<p>First, humans are best when it comes to adaptation. That means we naturally adapt to pain so that we don&#8217;t feel so bad, and adapt to pleasure so that we don&#8217;t feel so good. Perception of any external stimulus in the end comes to balance. <a href="http://federico.galassi.net/2009/06/12/on-the-paradox%E2%80%A6omer-happiness/">Barry Schwartz in the Paradox of Choice</a> says:</p>

<blockquote><p>respondents were asked to rate their happiness on a 5-point scale. Some of them had won between $50,000 and $1 million in state lotteries within the last year. Others had become paraplegic or quadriplegic as a result of accidents. Not surprisingly, the lottery winners were happier than those who had become paralyzed. What is surprising, though, is that the lottery winners were no happier than people in general. And what is even more surprising is that the accident victims, while somewhat less happy than people in general, still judged themselves to be happy.</p></blockquote>

<p>Second, humans are also very bad at admitting sunk costs. The idea of having spent money on something not worth is the ultimate inconvenient truth. Again Barry</p>

<blockquote><p>Aversion to losses also leads people to be sensitive to what are called “sunk costs.” Imagine having a $50 ticket to a basketball game being played an hour’s drive away. Just before the game there’s a big snowstorm—do you still want to go? Economists would tell us that the way to assess a situation like this is to think about the future, not the past. The $50 is already spent; it’s “sunk” and can’t be recovered. What matters is whether you’ll feel better safe and warm at home, watching the game on TV, or slogging through the snow on treacherous roads to see the game in person. That’s all that should matter. But it isn’t all that matters. To stay home is to incur a loss of $50, and people hate losses, so they drag themselves out to the game.</p></blockquote>

<p>Third, as brilliantly pointed out by <a href="http://programmer.97things.oreilly.com/wiki/index.php/Code_Is_Design">Ryan Brush&#8217;s &#8220;Code is Design&#8221;</a> in <a href="http://oreilly.com/catalog/9780596809492">97 Things Every Programmer Should Know</a> and by <a href="http://www.gabrielelana.it/archives/47">Gabriele&#8217;s &#8220;Waterfall Pitfall #1&#8221; (italian)</a>, <del>uninformed</del> most people understand software construction in terms of the better known building construction. Now, since programs are built out of bytes (not bricks), which are practically nothing, using mind (not excavators), which has no physical constraints, actual construction must be very cheap. This gives them the false hope of having an easy exit strategy at their disposal: fixing the software when an emergency comes up. Would they wait for a defective bridge to show the first cracks before attempting to fix it? Their unconstrained minds seem to be unable to realize that story construction aka book writing, built out of words, might represent a more fitting comparison and that <a href="http://en.wikipedia.org/wiki/Divina_commedia">The Divine Comedy</a> took <a href="http://en.wikipedia.org/wiki/Dante_Alighieri">Dante</a>, a renowned genius, more than ten years to finish.</p>

<p>Last but not least, mainstream has made a really good job at covering mistakes of incompetent programmers. From the almost sandboxed life cycle of a php script, to the rigid syntax of java and its <a href="http://wiki.eclipse.org/FAQ_What_is_a_Quick_Fix%3F">self-correcting IDEs</a>, to the plethora of <a href="http://www.codinghorror.com/blog/2007/01/do-certifications-matter.html">useless certifications</a>, great efforts have been devoted to make any primate with opposable thumbs able to program with very limited competence. Many and cheap, that&#8217;s how economy of scale is supposed to <del>fail</del> work, and that&#8217;s how we got this <a href="http://butunclebob.com/ArticleS.UncleBob.TheNextBigThing">horde of unprofessional programmers</a> sacking the best projects.</p>

<p>All of these points help to explain proliferation of crappy software. Maybe, they get it from some body rental which pays more for advertising than for the army of juniors that actually does the job. At the beginning it hurts, but they spent good money and cannot afford to accept failure, so lies are told and more time and money are invested to improve the situation. Then workarounds, albeit inefficient, come and direct suffering somehow decreases. Eventually, the pile of workarounds becomes part of company culture, and all is back to balance: the software starts working ok.</p>

<p>Unfortunately, this means that the quest for better <del>software</del> workflows can hardly come out of necessity, it must come out of vision, and vision takes <strong>inspiration</strong> fed to <strong>working brains</strong> then <strong>time</strong> for the masses to catch up. With Universe hopefully taking care of latter two, i like to think we, professional programmers, are those in charge of the former.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How I did It: Touch Typist in five months]]></title>
    <link href="http://federico.galassi.net/2010/01/27/how-i-did-it-touch-typist-in-five-months/"/>
    <updated>2010-01-27T19:22:52+01:00</updated>
    <id>http://federico.galassi.net/2010/01/27/how-i-did-it-touch-typist-in-five-months</id>
    <content type="html"><![CDATA[<blockquote><p><img alt="it-could-work" src="http://federico.galassi.net/images/it-could-work.jpg" class="post_image" />Until, from the midst of this darkness, a sudden light broke in upon me, a light so brilliant and wonderous, and yet so simple. Deep practice, eradicate errors and deep practice again. I alone succeeded in discovering the secret of bestowing skill. Nay, even more, I myself became capable of bestowing mastery upon apprentice matter.</p></blockquote>

<p><strong>It could work.</strong></p>

<p>At the end of august 2009, while i was reading about <a href="http://steve-yegge.blogspot.com/2008/09/programmings-dirtiest-little-secret.html">the importance for a programmer to touch type</a>, i found out many programmers could type at 80 <a href="http://en.wikipedia.org/wiki/Words_per_minute">wpm</a> and above. I tried myself and consistently scored 60 wpm or below. I have been spending many hours a day at the keyboard since at least 1996. How could it be i am not as fast? I already knew about the importance of practice, but i did practice for years, didn&#8217;t I? Well, uhm, no.</p>

<p>Think of the career of a professional <a href="http://en.wikipedia.org/wiki/Soccer_player">football (soccer) player</a>. How does he get there, does he play all the time for years? Actually, he spends most of the week <a href="http://www.soccer-training-info.com/sample_workout_routine.asp">training</a>: stretching, pushups, sprints, weights, long runs, ball work, etc&#8230; Only a small percentage of time is indeed to play short games and the main game on sunday. That&#8217;s because play alone can only push your performance to the upper end of the range set by current skill. It&#8217;s not going to push you to the next level, to the next order of magnitude, and it doesn&#8217;t keep you from developing bad habits. And that&#8217;s where i got, very fast at typing in my very flawed 7-fingers posture. Not able to improve any further, not even in more than 10 years.</p>

<p>I really <a href="http://en.wikipedia.org/wiki/Kaizen">wanted to get better</a>, so the questions were How? and How long will it take? I didn&#8217;t know the answer to the latter but the former was by then clear in my mind. Find a keyboard dojo, do keyboard <a href="http://federico.galassi.net/2009/09/02/code-katas-programmers-deep-practice/">katas</a> and take the needed time. After trying a lot of viable solutions i found my dojo at <a href="http://www.typingweb.com/">www.typingweb.com</a>. To add some salt to the challenge i switched keyboard layout from italian to U.S., which is quite better for programming, and i started practicing daily with their courses, routinely taking tests to record my progress. Two <a href="http://www.pomodorotechnique.com/">pomodoros</a> a day for the first two months, then one, then again two when i was reaching the end. Always striving to get 97% or above accuracy at the higher possible speed for every single lesson.</p>

<p>Now, five months and about 120 pomodoros of deep practice later, i am writing this to shout to the world that IT COULD WORK. Next i&#8217;ll be moving to <a href="http://federico.galassi.net/2009/08/01/vim-or-the-inevitable-value-of-complexity/">vim</a> katas, while still having some fun at <a href="http://www.typeracer.com">www.typeracer.com</a>, because you never really stop to practice right?!</p>

<p>Yours sincerely,
ten fingers typist
american layout
80 wpm average
up to 100 wpm under a good moon
Federico.</p>

<p><img src="http://federico.galassi.net/images/typing_sep092.png" alt="typing_sep09" /></p>

<p><img src="http://federico.galassi.net/images/typing_nov09-gen10.png" alt="typing_nov09-gen10" /></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Web Authentication as it SHOULD have been]]></title>
    <link href="http://federico.galassi.net/2009/12/31/web-authentication-as-it-should-have-been/"/>
    <updated>2009-12-31T20:19:51+01:00</updated>
    <id>http://federico.galassi.net/2009/12/31/web-authentication-as-it-should-have-been</id>
    <content type="html"><![CDATA[<p><img alt="" src="http://federico.galassi.net/images/auth_small.jpg" class="post_image" />REST is not an easy concept to grasp but once you get it you finally see the light on many different things. Having just read RESTful Web Services, i wanted to point out some unusual revelation that came to me: form based authentication with its login/session/logout workflow, which is currently dominant on the web, is hopelessly broken.</p>

<p>First two words about REST. It&#8217;s a set of constraints, of simplifying assumptions which, if applied to an architecture, will guarantee a number of good properties such as simplicity, scalability and reliability. The best known implementation of a RESTful architecture is the web and its backbone protocol, HTTP. HTTP RESTfulness made it good and yet so easy to implement that it eventually emerged as the great darwinian winner. Either your router or a pretty rabbit, if it&#8217;s networked it&#8217;s likely to speak HTTP.</p>

<p>Instead of giving yet another list of REST rules, i am going to give you a feeling of how the web works from a REST perspective. There&#8217;s a server which keeps state of the application, split into meaningful resources. Each resource has its own name (URI). That&#8217;s all the server knows. Then there&#8217;s a client which acts as a finite state machine visiting resources and then moving to other ones through links and forms. The state of the conversation, the session, where the client have been and where it is now, it&#8217;s something the client is in full control of. Server knows nothing about it. That&#8217;s statelessness.</p>

<p>Having recently read <a href="http://www.amazon.com/Restful-Web-Services-Leonard-Richardson/dp/0596529260">RESTful Web Services</a>, i wanted to write about the most interesting of my REST-induced epiphanies:</p>

<p><a href="http://en.wikipedia.org/wiki/Form_based_authentication">Form based authentication</a> with its login/session/logout workflow, which is currently dominant on the web, is hopelessly broken.</p>

<p>To understand why, one has to grasp how the greatest living RESTful implementation, the web and its backbone protocol <a href="http://www.w3.org/Protocols/">HTTP</a>, was <a href="http://www.ted.com/talks/tim_berners_lee_on_the_next_web.html">meant to work</a>. In a nutshell, there&#8217;s a server that keeps the state of the web application, split into meaningful <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_2_1_1">resources</a>. Each resource has its own name (<a href="http://en.wikipedia.org/wiki/Uniform_Resource_Identifier">URI</a>) and a set of available <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_2_1_2">representations</a> of itself. That&#8217;s all the server knows. Then there&#8217;s a client that acts as a <a href="http://en.wikipedia.org/wiki/Finite-state_machine">finite state machine</a> visiting resources, getting representations and then moving to other resources through links and forms. <a href="http://en.wikipedia.org/wiki/Session_%28computer_science%29">The state of the conversation, the session</a>, where a client has been and where it is now, is something that belongs to the client. Server drives the client by feeding him a graph made of states and links to other states, but it&#8217;s the client who is in charge of following a path. That&#8217;s <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_3">statelessness</a>, the simplifying property that made the web triumph as a <a href="http://en.wikipedia.org/wiki/Survival_of_the_fittest">darwinian winner</a>.</p>

<p>In this view, authentication should have been largely a client-side business.
The client visits resources anonymously. If it wants to be authenticated, it just starts sending authentication data with <strong>each</strong> further request. If it wants to be anonymous again, it just stops. It could as well send a mix of authenticated and anonymous requests.
The server doesn&#8217;t care of what happens between requests. If a single request carries authentication data, it checks the data and possibly replies as if the client were authenticated. If a request has no authentication data, a generic response is returned. There&#8217;s no server-side login through a form, there&#8217;s no server-side logout, and above all, there&#8217;s no temporal ordering between those two and hence no server tracked session. All of a sudden, the beauty of this comes with great force. By delegating authentication to the browser using the standard HTTP mechanism we can greatly <strong>simplify</strong> application code.</p>

<p>Unfortunately, in reality this is not the case. During its race to the top, HTTP lost part of its original vision, mainly due to implementation mistakes.</p>

<ol>
<li><p><a href="http://www.ietf.org/rfc/rfc2617.txt">The specs</a> failed to hit the sweet spot of authentication security. They standardized <a href="http://en.wikipedia.org/wiki/Basic_access_authentication">Basic Authentication</a> which, by sending user and password in plain text, scared people to death and <a href="http://en.wikipedia.org/wiki/Digest_access_authentication">Digest</a> which, due to its complexity and required server cooperation, never really caught on. A client-side mechanism with cheap yet reasonable security such as <a href="http://www.oasis-open.org/committees/wss/documents/WSS-Username-02-0223-merged.pdf">WSSE UsernameToken</a>, <a href="http://www.xml.com/pub/a/2003/12/17/dive.html">later adopted by atom</a>, would have been optimal.</p></li>
<li><p>Browsers took away login from client&#8217;s hands by showing the popup dialog to input user/password <strong>only</strong> after a 401 http error code <strong>from server</strong>. There should have been an always visible &#8220;login&#8221; button since <a href="http://tools.ietf.org/html/rfc2617">the specs</a> said &#8220;A user agent that wishes to authenticate itself with an origin server&#8211;usually, but <strong>not necessarily</strong>, after receiving a 401&#8230;&#8221;.</p></li>
<li><p>Browsers practically took away logout from client&#8217;s hands by requiring to close the browser in order to clean the passwords cache. There should have been an always visible &#8220;logout&#8221; button.</p></li>
<li><p>Browsers gave no chance to customize the ugly and annoyingly modal login dialog. HTML and/or CSS could have been used.</p></li>
<li><p>Browsers gave no client-side storage needed to keep session data but again turned back to server with <a href="http://en.wikipedia.org/wiki/HTTP_cookie">cookies</a>. They should have given something like upcoming HTML5 <a href="http://www.w3.org/TR/2009/WD-webstorage-20091222/">localStorage and sessionStorage</a>.</p></li>
</ol>


<p>Now there&#8217;s not much that can be done short of a collaborative effort by all browser vendors. Meanwhile we can keep dealing with authentication in application code on the server, in a never ending pile of custom solutions, each one slightly different, for yet another pretty standard problem. A problem solved <a href="http://tools.ietf.org/html/rfc1945#section-11">15 years ago</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Javascript Performance: Make the Browser Happy (and You Sad)]]></title>
    <link href="http://federico.galassi.net/2009/11/15/javascript-performance-make-the-browser-happy-and-you-sad/"/>
    <updated>2009-11-15T22:40:11+01:00</updated>
    <id>http://federico.galassi.net/2009/11/15/javascript-performance-make-the-browser-happy-and-you-sad</id>
    <content type="html"><![CDATA[<p><img alt="BENDER" src="http://federico.galassi.net/images/BENDER1.jpeg" class="post_image" />The browser is emerging as the <a href="http://en.wikipedia.org/wiki/HTML5">best platform</a> for applications, so a large community is growing to address its final weakness: speed. <a href="http://code.google.com/speed/">Google</a>, <a href="http://developer.yahoo.com/performance/">Yahoo</a> and <a href="http://javascriptrocks.com/performance/">various independent programmers</a> are all pushing a bunch of clever techniques to boost performance and please end users. That&#8217;s nice, yet as Mark Twain once said, <em>half of the results of good intentions are evil</em> and i see potential danger in many of the suggestions made. Here a representative short list of them:</p>

<ul>
<li><p>Avoid for-in and forEach in favor of optimized while loops</p></li>
<li><p>Before making modifications to a DOM node remove it and then re-insert it</p></li>
<li><p>To insert multiple DOM nodes, first insert them into a Document Fragment and then add it to the DOM</p></li>
<li><p>Join all scripts into a single file</p></li>
<li><p>Load javascript files on demand</p></li>
</ul>


<p>Let&#8217;s make it clear for once, execution speed is not a human problem, that&#8217;s what computers are for, they execute our commands fast. The human problem is programming speed and writing down clear, readable, maintainable commands aka programs. forEach loops make sense to me, they say &#8220;i want to do something on each item&#8221;, optimized while loops make sense to computers. If i want to add DOM nodes or modify one, i don&#8217;t care of removing it or document fragments, browsers care. To me it&#8217;s just noise. Almost all of the problems addressed by those techniques stem from lack of smartness in the browser, and that&#8217;s where fixes belong to, on the machine side. The fact that there are <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">inept browser makers</a> is no excuse. Fixes still belong to the machine, they&#8217;re repeatable and can be made automatic. We have a long history of programs automatically converting human friendly code to machine friendly code. They&#8217;re called <a href="http://en.wikipedia.org/wiki/Compiler">compilers</a> and the output either machine code or optimized javascript doesn&#8217;t matter.</p>

<p>So, learn about javascript performance since knowledge is always the way, but don&#8217;t turn yourself into a machine, you&#8217;d be an awful one. Use the tools and wait for browsers to catch up.</p>

<ul>
<li><p><a href="http://www.aptimize.com/">Aptimize</a></p></li>
<li><p><a href="http://code.google.com/closure/compiler/">Closure Compiler</a></p></li>
<li><p><a href="http://developer.yahoo.com/yui/3/yui/#use">YUI 3 use</a></p></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Google Test Automation Conference: Testing is not enough]]></title>
    <link href="http://federico.galassi.net/2009/10/26/google-test-automation-conference-testing-is-not-enough/"/>
    <updated>2009-10-26T02:19:22+01:00</updated>
    <id>http://federico.galassi.net/2009/10/26/google-test-automation-conference-testing-is-not-enough</id>
    <content type="html"><![CDATA[<p><img alt="niklaus wirth at google" src="http://federico.galassi.net/images/niklaus.jpg" class="post_image" />If i had to award the best talk at <a href="http://www.gtac.biz/">GTAC 2009</a>, the no-brainer choice would be Prof. <a href="http://en.wikipedia.org/wiki/Niklaus_Wirth">Niklaus Wirth</a> <a href="http://www.youtube.com/watch?v=8W5Jd_wzB90">opening talk</a>. That&#8217;s not surprising if you consider who the speaker is, one of the great pioneers of computer science in the field of <a href="http://en.wikipedia.org/wiki/Pascal_(programming_language">programming languages</a>). What&#8217;s most surprising to me is that he presented a (pre)historical review of problems which turned out to be incredibly relevant today and, somehow, forced me to reframe my understanding of testing.</p>

<p>Building on <a href="http://www.cs.utexas.edu/users/EWD/transcriptions/EWD03xx/EWD340.html">1972 Dijkstra dismissal of software testing</a></p>

<blockquote><p>program testing can be a very effective way to show the presence of bugs, but is hopelessly inadequate for showing their absence.</p></blockquote>

<p>Wirth explained that testing is treating symptoms instead of the disease, with the disease being our failure to prove correctness of programs by analytical means. This failure has its roots in distant past but it still holds today with languages and tools too complex and unreliable. Languages and tools providing proper abstraction, <em>really</em> hiding the system beneath, would give us the simple and rigorous ground to make programs easy to prove correct, so that no testing would be needed. Unfortunately, this looks far from happening</p>

<blockquote><p>Programming languages are further from being mathematically nice than they were 50 years ago! They&#8217;re huge and complicated. They contain big libraries, and most of a programmer&#8217;s time is spent finding and learning the right libraries.</p></blockquote>

<p>and again</p>

<blockquote><p>What progress has this field actually made? We still struggle with the same problems as 50 years ago: iteration times, debugging, scratching our heads trying to figure out what went wrong.</p></blockquote>

<p>How insightful! Empirical evidence that computer science made no sizable improvement in software construction is everywhere. It&#8217;s like a hamster in a wheel, running nowhere. Why is that? Maybe, we&#8217;ve been piling <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">leaky abstractions</a> on leaky abstractions, apparently hiding information without really simplifying, to the point where progress is drowning in complexity.</p>

<p>Testing is a nice way to easily lay down executable specifications, yet it requires maintenance and quickly degrades as we try to cover more cases. But when we code we have the chance to write self-describing programs which <em>are</em> executable specifications, reducing the coverage of tests needed, ideally to zero.</p>

<p>What does it mean in practice? Whenever it&#8217;s possible one should aim at <a href="http://en.wikipedia.org/wiki/Declarative_programming">declarative code</a>. <a href="http://www.martinfowler.com/bliki/DomainSpecificLanguage.html">Domain specific languages</a> and <a href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</a> come to mind. The point being, if a program matches closely its specification, what&#8217;s left to test?</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">def</span> <span class="nf">factorial</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
</span><span class='line'>    <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">0</span>
</span><span class='line'>        <span class="mi">1</span>
</span><span class='line'>    <span class="k">else</span>
</span><span class='line'>        <span class="n">n</span> <span class="o">*</span> <span class="n">factorial</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
</span><span class='line'>    <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Refactoring to Unobtrusive Javascript]]></title>
    <link href="http://federico.galassi.net/2009/09/29/refactoring-to-unobtrusive-javascript/"/>
    <updated>2009-09-29T01:49:06+02:00</updated>
    <id>http://federico.galassi.net/2009/09/29/refactoring-to-unobtrusive-javascript</id>
    <content type="html"><![CDATA[<p>I&#8217;ve been thinking for a while about techniques to enforce maximum <a href="http://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a> in the client-side web technology stack. Even though, total separation of presentation, content and business logic may well be a utopia, the list of refactorings i collected over time are generally good to improve code quality and the whole concept of refactoring unusually applied to javascript is quite interesting per se. Here&#8217;s a talk about it i gave at <a href="http://www.javascriptcamp.com/">Javascript Camp 2009</a>.</p>

<iframe src="http://www.slideshare.net/slideshow/embed_code/2081724" width="427" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen> </iframe>


<p> <div style="margin-bottom:5px"> <strong> <a href="http://www.slideshare.net/fgalassi/refactoring-to-unobtrusive-javascript" title="Refactoring to Unobtrusive Javascript" target="_blank">Refactoring to Unobtrusive Javascript</a> </strong> from <strong><a href="http://www.slideshare.net/fgalassi" target="_blank">Federico Galassi</a></strong> </div></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Code Katas: Programmer's Deep Practice]]></title>
    <link href="http://federico.galassi.net/2009/09/02/code-katas-programmers-deep-practice/"/>
    <updated>2009-09-02T21:27:46+02:00</updated>
    <id>http://federico.galassi.net/2009/09/02/code-katas-programmers-deep-practice</id>
    <content type="html"><![CDATA[<p><img alt="karate_champ" src="http://federico.galassi.net/images/karate_champ.png" class="post_image" />I&#8217;ve recently <a href="http://federico.galassi.net/2009/08/28/teach-yourself-anything-in-10000-hours/">blogged about talent and how it&#8217;s grown</a> through disciplined, committed, error focused practice at the edge of your ability, known as deep practice. I guess now it makes sense to approach it from the perspective of programming: What&#8217;s programmer&#8217;s deep practice? Unsurprisingly, inspiration can be found in the great japanese culture, people who highly value <a href="http://en.wikipedia.org/wiki/Bushid%C5%8D">discipline</a> and <a href="http://en.wikipedia.org/wiki/Kaizen">self improvement</a>. Specifically i&#8217;m talking of martial arts. If you were to learn, say, karate you would go to a <a href="http://en.wikipedia.org/wiki/Dojo">dojo</a> and perform <a href="http://en.wikipedia.org/wiki/Kata">katas</a>. If you happen to be a programmer, you can go to a coding dojo and practice code katas.</p>

<p><a href="http://en.wikipedia.org/wiki/Kata_%28programming%29">Code katas</a>, a term first coined by Pragmatic Programmer <a href="http://en.wikipedia.org/wiki/Dave_Thomas_%28programmer%29">Dave Thomas</a>, are small programming exercises geared to hone a specific programming skill. Traditionally, they tend to be <a href="http://en.wikipedia.org/wiki/Algorithm">algorithmic</a> like parsing or visiting graphs but could as well aim to improve understanding of particular <a href="http://en.wikipedia.org/wiki/Programming_paradigm">programming paradigms</a>, like functional or object oriented, or a specific language. Also, <a href="http://matteo.vaccari.name/blog/archives/177">as remarkably pointed out by Matteo</a>, katas can be crafted to master a certain technology like web or database. While, as you may guess, Coding Dojos are sites, groups or communities which propose and maintain collections of katas hopefully with solutions and reviews.</p>

<p>So, how do you practice? I suggest you solve a kata, review your work, compare it to other solutions, share your code with others and discuss it. Then solve it again trying to take a different path, balance pros and cons, then solve it again and again, until you <em>feel you internalized the essence of the problem</em>. Finally, you can move to another kata. If it feels like a lot of work, then you got it right. No question mastership requires time and effort but, then again, masters are those destined for greatness.</p>

<p><strong>Resources</strong></p>

<ul>
<li><p><a href="http://www.katacasts.com/">Katacasts</a></p></li>
<li><p><a href="http://codekata.pragprog.com/2007/01/code_kata_backg.html">21 Code Katas by Dave Thomas</a></p></li>
<li><p><a href="http://www.rubyquiz.com/">Lots of Code Quizzes with Ruby Solutions</a></p></li>
<li><p><a href="http://matteo.vaccari.name/blog/archives/177">Matteo Vaccari&#8217;s Technological Katas</a></p></li>
<li><p><a href="http://codingdojo.org/cgi-bin/wiki.pl?KataCatalogue">Coding Dojo Code Katas</a></p></li>
<li><p><a href="http://charlesmaxwood.com/8-lessons-from-corey-haines-performance-kata/">Corey Haines Video Solution in Ruby of String Template</a></p></li>
<li><p><a href="http://butunclebob.com/ArticleS.UncleBob">Uncle Bob</a> Code Katas (search &#8220;kata&#8221;, ie bowling kata)</p></li>
<li><p><a href="http://rubyconf2008.confreaks.com/ruby-kata-and-sparring.html">Micah Martin on Code Katas and Video Solution in Ruby of Langton&#8217;s Ant</a></p></li>
<li><p><a href="http://sparring.rubyforge.org/battleship/">Micah Martin&#8217;s BattleShip Tournament</a></p></li>
<li><p><a href="http://code.google.com/codejam/">Google Code Jam</a></p></li>
<li><p><a href="http://www.codinghorror.com/blog/archives/001138.html">Jeff Atwood on Code Katas</a></p></li>
<li><p><a href="http://steve.yegge.googlepages.com/practicing-programming">Steve Yegge on Code Katas
</a></p></li>
<li><p><a href="http://norvig.com/21-days.html">Peter Norvig on Deep Practice</a></p></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Teach Yourself Anything in 10000 hours]]></title>
    <link href="http://federico.galassi.net/2009/08/28/teach-yourself-anything-in-10000-hours/"/>
    <updated>2009-08-28T18:42:39+02:00</updated>
    <id>http://federico.galassi.net/2009/08/28/teach-yourself-anything-in-10000-hours</id>
    <content type="html"><![CDATA[<p><img alt="talent_small" src="http://federico.galassi.net/images/talent_small.jpg" class="post_image" />During my holidays, on a beautiful spot by the river, i had the opportunity to finish <a href="http://thetalentcode.com/">The Talent Code</a>. This nice book brings empirical evidence and <a href="http://en.wikipedia.org/wiki/Myelin#Function_of_myelin_layer">scientific foundations</a> to something i have felt for quite some time:
Talent isn&#8217;t born, it&#8217;s grown.</p>

<p>Actually this has been something known to humanity for at least a century and it&#8217;s best explained by this quote from <a href="http://en.wikipedia.org/wiki/Thomas_Edison">Thomas Edison</a>:</p>

<blockquote><p>Genius is 1% inspiration and 99% perspiration</p></blockquote>

<p>The point is that becoming great at something is largely a matter of the amount and quality of practice one does. While God given talent can only boost this process, but it&#8217;s by no means the most influential factor.</p>

<p>About the amount of practice, there&#8217;s the old <a href="http://norvig.com/21-days.html">&#8220;Ten Years Rule&#8221;</a> and <a href="http://www.amazon.com/Cambridge-Expertise-Performance-Handbooks-Psychology/dp/0521600812">a more refined study by Anders Ericsson</a> who sets in 10000 hours of committed practice the time taken to achieve expert level. From the <a href="http://www.pomodorotechnique.com">Pomodoro Technique</a>, we know one can do about 5 hours/day of efficient work (10 pomodoros). That means 5 years and a half, 5 hours every day of hard work could be a good guess to the question &#8220;How long does it take?&#8221;.</p>

<p>About the quality of practice, the book calls the good one &#8220;deep practice&#8221;</p>

<blockquote><p>working on technique, seeking constant critical feedback and focusing ruthlessly on shoring up weaknesses</p></blockquote>

<p>So deep practice has a pretty simple recipe:</p>

<ul>
<li><p>practice just beyond your current ability</p></li>
<li><p>focus on errors</p></li>
<li><p>fix them</p></li>
<li><p>repeat</p></li>
</ul>


<p>Basically, it&#8217;s tenacious, steady continuous improvement, so it&#8217;s not surprising <a href="http://en.wikipedia.org/wiki/Kaizen">Kaizen</a> is mentioned in the book.</p>

<p>In the end, we are left with two news: one bad, one awesome. The bad one is if you fail to reach master level in a discipline you care of, there&#8217;s no one to blame but yourself. Sadly, you got to <a href="http://federico.galassi.net/2009/06/12/on-the-paradox-of-choice-and-customer-happiness/">take responsibility even for that</a>. But the awesome news is you can really become what you want be. Just keep working.</p>

<p>Let&#8217;s close with this sweet advice from great italian poet <a href="http://en.wikipedia.org/wiki/Giovanni_Papini">Giovanni Papini</a></p>

<blockquote><p>Chiunque, purché sappia                  chiaramente cosa vuol divenire e non perda un solo secondo della                  sua vita, può issarsi al livello di coloro che dettano                  le leggi alle cose e che creano vite più degne. (Da &#8220;Diventar Genio&#8221; - 1912)</p></blockquote>

<p>and my rough translation</p>

<blockquote><p>Anyone, as long as he clearly knows what he wants to become and doesn&#8217;t waste a single second of his life, can raise himself to the level of those who lay down the laws of things and create more worthy lives (From &#8220;Becoming Genius&#8221; - 1912)</p></blockquote>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Vim or the Inevitable Value of Complexity]]></title>
    <link href="http://federico.galassi.net/2009/08/01/vim-or-the-inevitable-value-of-complexity/"/>
    <updated>2009-08-01T01:59:12+02:00</updated>
    <id>http://federico.galassi.net/2009/08/01/vim-or-the-inevitable-value-of-complexity</id>
    <content type="html"><![CDATA[<p><img alt="vim" src="http://federico.galassi.net/images/vim.png" class="post_image" />It&#8217;s becoming clear to me that a programmer is probably closer to a <a href="http://manifesto.softwarecraftsmanship.org/">craftsman</a> than a scientist. The craftsman greatest strength is mastership of his tools. So just as the carpenter masters the plane to shape wood, the programmer must master a text editor to shape programs. I&#8217;ve spent enough time wandering aimlessly around a lot of editors and IDE&#8217;s. It&#8217;s time for me to settle down, make a competent choice and <a href="http://norvig.com/21-days.html">take the years</a> needed to become proficient in it. I wanted something possibly simple, light and which would <a href="http://blog.alagad.com/2007/06/15/changing-the-font-size-in-eclipse/">leave <strong>me</strong> in control</a>. That means an editor over an IDE, but which one? I did some deep research and after an endless stream of positive reviews backed by <a href="http://www.gabrielelana.it/">Gabriele</a> &#8220;warm&#8221; suggestion, i bought <a href="http://www.amazon.com/Learning-Vim-Editors-Arnold-Robbins/dp/059652983X/">&#8220;Learning the Vi and Vim Editors 7th edition&#8221;</a>. <a href="http://www.vim.org/">Vim</a> is 1991 software based on a 1970s one, and it&#8217;s great. Btw my second best was <a href="http://www.gnu.org/software/emacs/emacs.html">emacs</a>, another 1970s software. This must say something about advances in text editing software industry. Anyway, now that i&#8217;ve finished the book and daily using Vim, i realize its very existance is relevant to the <a href="http://federico.galassi.net/category/simplicity/">&#8220;simplicity in software&#8221;</a> debate.</p>

<p>Is Vim amazing software? Yes. Is Vim simple? No. This could imply that simplicity is a highly overrated software value, but i think it&#8217;s not. It just implies that, as any other thing under the sun, simplicity is a relative value. Relative to what? I guess to user&#8217;s knowledge of the domain. Let me explain.</p>

<p>Simple software is one that provides a few objects and a few rules to compose those objects coherently into newer more complex abstractions. This makes an optimal hotbed to learn. Few objects are easy to understand and remember. Few corner case free rules give confidence while exploring the unknown. It&#8217;s important that the learner is not exposed to further possibly useful complexity which is not ready for yet. Only some to ignite inspiration, but greater power cannot come a priori, but as a consequence of greater understanding of the domain. This way user and software evolve together.</p>

<p>&#8220;Good&#8221; Complex software, which still tries to minimize basic objects and rules and completely avoid corner cases, may ship equipped with many levels of abstraction relevant to the domain. That&#8217;s for the sake of efficiency, so that the skilled user will be able to manage complex scenarios by quickly referring those abstractions. Give something too simple to the master and he will end up bored and unproductive. Give something too complex to the apprentice and he will run away confused.</p>

<p>Vim is extremely good and complex software which comes with a <a href="http://vimdoc.sourceforge.net/htmldoc/usr_toc.html">plethora of short keyboard commands</a> to make any conceivable manoeuvre on text at top speed. Optimized for being efficient with keyboard, which already happens to be the most efficient input device, usually much better than mouse. That&#8217;s heaven for <a href="http://en.wikipedia.org/wiki/Touch_typing">touch typists</a> as i am. The nice thing about efficiency is that it can be easily quantified by time. Same goal, the faster the better.</p>

<p>Let&#8217;s close with a fulgid example of vim capabilities with a common editing pattern: swapping two words.
An usual hybrid keyboard/mouse approach on windows:</p>

<ul>
<li><p>Select the first word (click/drag the mouse or double click)</p></li>
<li><p>Cut (ctrl+x or right click and use menu)</p></li>
<li><p>Move the cursor after the next word (move the mouse and click)</p></li>
<li><p>Paste (ctrl+v or right click and use menu)</p></li>
</ul>


<p>I guess it takes 3-4 seconds to complete correctly</p>

<p>Vim keyboard based approach:</p>

<ul>
<li>type dwwP</li>
</ul>


<p>An average good typist can do 50 <a href="http://en.wikipedia.org/wiki/Words_per_minute">wpm</a> which means it takes about 1 second to type 4 characters. That&#8217;s efficient.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[On The Paradox of Choice and Customer Happiness ]]></title>
    <link href="http://federico.galassi.net/2009/06/12/on-the-paradox-of-choice-and-customer-happiness/"/>
    <updated>2009-06-12T22:35:27+02:00</updated>
    <id>http://federico.galassi.net/2009/06/12/on-the-paradox-of-choice-and-customer-happiness</id>
    <content type="html"><![CDATA[<p><img alt="paradox_choice" src="http://federico.galassi.net/images/paradox_choice.jpg" class="post_image" />The more i read about psychology the more i feel it&#8217;s compelling knowledge to anyone especially in the software business.</p>

<p><a href="http://www.amazon.com/Paradox-Choice-Why-More-Less/dp/0060005696">The Paradox of Choice</a> by <a href="http://www.swarthmore.edu/SocSci/bschwar1/">Barry Schwartz</a> is enlightening on this respect. Humans inherently crave control, autonomy, self determination and so choices which are natural means to express this essential demand of freedom. Yet, humans used to have simple lives with limited amount of choices. Now, in these days of <a href="http://www.youtube.com/watch?v=ljbI-363A2Q">exponential growth</a> and exploding options, they just can&#8217;t cope anymore. They&#8217;re overwhelmed by escalating possibilities in all fields of life ending up paralyzed, frustrated, dissatisfied if not plain depressed.</p>

<p>Schwartz comes to the conclusion that, to relieve distress, they have to fight back their inner impulse and learn to accept some constraints are good, that simplicity, more often than not, can be the golden path to well-being. In a later <a href="http://video.google.com/videoplay?docid=6127548813950043200">talk at Google</a>, he goes as far as pointing out that software/product makers should embrace <a href="http://en.wikipedia.org/wiki/Soft_paternalism">libertarian paternalism</a>, which in a nutshell means: give them choices but also apply soft contraints to ease their path to &#8220;good&#8221; decisions. Those that will probably make them better.</p>

<blockquote><p>Greek Diners in New York City. Their menus are about a thousand pages. There is no dish anyone has ever eaten it isn&#8217;t somewhere on those menus and tucked in the front cover of the menu there&#8217;s a little piece of paper with &#8220;today&#8217;s specials&#8221; - four or five items. Inadvertently you create an insoluble problem by giving people 10,000 things to choose from and then you solve it for them by giving them today&#8217;s specials and people are driven to choose, take your advice, take your recommendation.</p></blockquote>

<p>This sheds new light on the company vs customer, simple vs full featured software picture i&#8217;m still trying to figure out. As <a href="http://www.jnd.org/dn.mss/simplicity_is_highly.html">Don Norman puts it</a> &#8220;People want the features&#8221; and &#8220;Features win over simplicity&#8221; and as <a href="http://www.joelonsoftware.com/items/2006/12/09.html">Joel Spolsky notices</a> &#8220;With six years of experience running my own software company I can tell you that nothing we have ever done at Fog Creek has increased our revenue more than releasing a new version with more features. Nothing.&#8221;. That&#8217;s obvious. That&#8217;s what people naturally do, the way society drives them to do: Manifest control by claiming more options, more variety.</p>

<p>But then there&#8217;s the other side of the coin. Many of them will reject using such software or at least defend themselves by restricting to very basic usage and, in the end, they&#8217;ll feel bad about it. Empirical evidence is already there in stats about <a href="http://www.slideshare.net/gabriele.lana/sustainable-agile-development/15">unused features</a>. People also seem to feel it as the great success of &#8220;for dummies&#8221; books and simplicity buzzword in advertising underline. Using Schwartz words:</p>

<blockquote><p>A majority of people want more control over the details of their lives, but a majority of people also want to simplify their lives. the paradox of our times.</p></blockquote>

<p>Customers bombarded by never ending stream of choices and responsabilities are to me much like children in need of a good parent. So companies as anyone really or virtually in charge of other human beings are subjected to the same old ethical question:</p>

<p><em>Do we care for us or for them?</em></p>

<p><em>Are we in the business of making money or in the business of making happy customers?</em></p>

<p>If you like me <a href="http://startup2startup.com/2009/05/01/steve-blank-and-eric-ries-customers-customers-customers/">value the latter</a>, then maybe, it&#8217;s time to start acting as a lovely father who takes best choices for his offspring but as they grow safe, empower them day by day. Instead if money drives your actions, i just got one more question for you:</p>

<p><em>Do you think such economy is REALLY sustainable?</em></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Google Wave Fallacy]]></title>
    <link href="http://federico.galassi.net/2009/06/09/google-wave-fallacy/"/>
    <updated>2009-06-09T17:36:26+02:00</updated>
    <id>http://federico.galassi.net/2009/06/09/google-wave-fallacy</id>
    <content type="html"><![CDATA[<p> </p>

<p><img alt="google_wave_logo" src="http://federico.galassi.net/images/google_wave_logo.png" class="post_image" /><a href="http://wave.google.com/">Google Wave</a> is an impressive product. If you haven&#8217;t seen the <a href="http://www.youtube.com/watch?v=v_UyVmITiYQ">Google IO Preview video</a>, i highly suggest you do it know and come back later. Even if you don&#8217;t care, there&#8217;s a long list of smart ideas, patterns and neat technical solutions packed into Wave that deserve to be studied. Let me mention a few:</p>

<ul>
<li><p>One unique state, on the server</p></li>
<li><p>Operational Transformations</p></li>
<li><p>Statistical spell checker</p></li>
<li><p>Real time collaboration</p></li>
<li><p>Real time search</p></li>
<li><p>Federation</p></li>
<li><p>Playback of changes over time</p></li>
<li><p>Applications as Robots</p></li>
<li><p>Openness of protocol, api, extension</p></li>
</ul>


<p>and much more, but even though all this goodness and google involvement are exciting and indeed already suggest a planetary success, i am a little skeptical.</p>

<p>First, in our times of <a href="http://www.slideshare.net/MobiusView/simplicity-523441">overwhelming complexity</a>, when products like <a href="http://twitter.com/">Twitter</a> can WIN not by augmenting capabilities but by restricting them (<a href="http://twitter.com/about#like">to a single short answer</a>), Wave  <a href="http://wave.google.com/help/wave/about.html">rich complexity</a> will have to prove itself. But there&#8217;s more. Something feels wrong to me in this catch-all approach to communication, and i came to believe it&#8217;s how all this empowerment is unevenly distributed among different <a href="http://en.wikipedia.org/wiki/Faceted_classification">facets</a> of communication itself.</p>

<p>Let me explain trying to determine a few of those facets:</p>

<ul>
<li><p>Retention. How long information will remain available. e.g. From ephemeral spoken words to durable written words.</p></li>
<li><p>Responsiveness. Whether information is taken in immediately or at a later time. e.g. From asynchronous mail to synchronous phone.</p></li>
<li><p>Relevance. How much information is specific and important to a certain matter or goal. e.g. From generic chit-chat to focused articles.</p></li>
</ul>


<p>It&#8217;s easy to see that high retention and asynchronicity are symbiotic. There can be no asynchronous transfer of information if that information is not stored somewhere waiting to be consumed. What&#8217;s harder to see, but empirically true afaic, is that high relevance is related as well. Maybe it&#8217;s the effort traditionally required to store information in a durable form, maybe it&#8217;s because people have more time to think on what they want to say, maybe it&#8217;s that information is produced in isolation helping to concentrate, but it seems asynchronous highly persistent communication tends to be more focused, worth and relevant.</p>

<ul>
<li><p>You&#8217;d write a book about origami, but probably not about your last vacation.</p></li>
<li><p>You&#8217;d write a blog post about your last vacation, but maybe not about today&#8217;s weather.</p></li>
<li><p>You&#8217;d twitter about weather, but hopefully not that you&#8217;re turning down volume on the ipod.</p></li>
<li><p>Yet you could say that to a friend being around.</p></li>
</ul>


<p>Conversely, as communication responsiveness bar raises up, we keep putting in more and more trivial, irrelevant, conversational stuff. That&#8217;s easily common sense. Take the word &#8220;chat&#8221; and how it often has negative connotation. Chat as a waste of time. Chat as enemy of focused productive work (pomodoro technique anyone?). It would be foolish to say that all real time communication is irrelevant, or that irrelevant information is always bad, yet down that path, we often digress from the meaningful and, in that circumstance, high retention is at least useless if not undesirable.</p>

<p>So what&#8217;s the problem with <a href="http://wave.google.com/">Google Wave</a>?</p>

<p>It innovates by opening the entire spectrum of responsiveness possibilities. Users can communicate from asynchronous e-mail to true real time chat. Wonderful. But what about other facets? </p>

<ul>
<li><p>Retention is fixed and very high. In fact so high that waves can be viewed as conversations or even documents. Stored forever in the cloud. I guess they have or will have a delete button but that would be quite coarse-grained anyway.</p></li>
<li><p>Relevance has even weaker support. You have wave title and tags and that&#8217;s it.</p></li>
</ul>


<p>Without further control, i don&#8217;t see how people will be kept from mixing those different kinds of communication in wrong ways, especially as number of participants goes up. I imagine carefully built documents polluted by real time blabbering, collaborative flame wars producing endless amounts of noise and whole branches of waves slipping out of topic. Trivial fast-paced conversations and relevant slowly crafted documents, all together in a persistent rich beautiful mess called the wave.</p>

<p>I hope to see odds of such hellish prophecy mitigated by some good moderation system and/or by giving better control on retention, otherwise Wave may become yet another perfect illustration of <a href="http://dictionary.reference.com/browse/give+him+enough+rope+and+he'll+hang+himself">&#8220;giving enough rope&#8221;</a>. In conclusion, some pretty tentative attempts to contribute:</p>

<ul>
<li><p>an additional chat system orthogonal to wave content</p></li>
<li><p>tags and votes on content and ability to show/hide based on that</p></li>
<li><p>content that fades away unless marked &#8220;important&#8221;</p></li>
<li><p>content time to live</p></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Farewell Fravia+]]></title>
    <link href="http://federico.galassi.net/2009/06/04/farewell-fravia/"/>
    <updated>2009-06-04T18:45:38+02:00</updated>
    <id>http://federico.galassi.net/2009/06/04/farewell-fravia</id>
    <content type="html"><![CDATA[<p><img alt="fravia" src="http://federico.galassi.net/images/fravia.jpg" class="post_image" />For the man who had wisdom to seek truth and knowledge and love to teach us.</p>

<p>thank you</p>

<p><a href="http://www.searchlores.org">Fravia+</a>, searcher and reverse engineer, 1952-2009</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Javascript the good parts Talk]]></title>
    <link href="http://federico.galassi.net/2009/05/18/javascript-the-good-parts-talk/"/>
    <updated>2009-05-18T00:22:41+02:00</updated>
    <id>http://federico.galassi.net/2009/05/18/javascript-the-good-parts-talk</id>
    <content type="html"><![CDATA[<p><img alt="js1" src="http://federico.galassi.net/images/js1.gif" class="post_image" />I&#8217;m just back from <a href="http://www.phpday.it">phpDay 2009</a> in Verona, where i gave a <a href="http://www.slideshare.net/fgalassi/javascript-the-good-parts-v2-1447479">revised edition</a> of my &#8220;Javascript the Good Parts&#8221; talk, based on <a href="http://www.crockford.com/">Douglas Crockford</a>&#8217;s great material (first edition being one i gave at <a href="http://www.phpcon.it/">PHPCon</a> in march). It&#8217;s been a pleasure to stay there along with nice people such as <a href="http://www.gabrielelana.it">Gabriele</a>, <a href="http://www.fullo.net/">Fullo</a> and many others. Also I found out a growing interest in the javascript language which may end up in some sort of italian javascript focused conference or barcamp. Now that would be nice. If anyone out there would be interested in such event, feel free to <a href="mailto:federico.galassi@gmail.com">e-mail me</a>.</p>

<p>In the mean time, here comes a list of resources for those who want to deepen their knowledge about content of the talk:</p>

<p><strong>Books</strong></p>

<ul>
<li><p><a href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742">Javascript the good parts</a> - Kind of self explaining&#8230;where it all started. It&#8217;s slim yet dense. Some stuff is advanced.</p></li>
<li><p><a href="http://www.amazon.com/JavaScript-Definitive-Guide-David-Flanagan/dp/0596101996/">Javascript the definitive guide</a> - Best reference book and more.</p></li>
<li><p><a href="http://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X">Secrets of the Javascript Ninja</a> - Upcoming Resig Book. Doomed to be good.</p></li>
</ul>


<p><strong>People</strong></p>

<ul>
<li><p><a href="http://www.crockford.com/">Douglas Crockford</a> - Senior <em>JavaScript</em> Architect at Yahoo! and JSON father - Listen and read EVERYTHING</p></li>
<li><p><a href="http://ejohn.org/">John Resig</a> - JavaScript Evangelist for the Mozilla Corporation and jQuery author - Listen and read EVERYTHING<a href="http://en.wikipedia.org/wiki/Brendan_Eich"></a></p></li>
<li><p><a href="http://en.wikipedia.org/wiki/Brendan_Eich">Brendan Eich</a> - Mozilla CTO and Javascript Father - Greatest historical figure<a href="http://www.quirksmode.org/"></a></p></li>
<li><p><a href="http://www.quirksmode.org/">Peter-Paul Koch</a> - quirksmode.com - King of compatibility matters<a href="http://stevesouders.com/"></a></p></li>
<li><p><a href="http://stevesouders.com/">Steve Souders</a> - Google employee and author of &#8220;High Performance Web Sites&#8221; - King of performance matters (together with Resig)</p></li>
</ul>


<p><strong>Videos</strong></p>

<ul>
<li><p><a href="http://developer.yahoo.com/yui/theater/">YUI Theater</a></p></li>
<li><p><a href="http://video.yahoo.com/video/play?vid=111593">YUI Theater - Douglas Crockford - The JavaScript Programming Language (4 parts)</a></p></li>
<li><p><a href="http://video.yahoo.com/video/play?vid=111582">YUI Theater - Douglas Crockford - An Inconvenient API: The Theory of the DOM (3 parts)</a></p></li>
<li><p><a href="http://video.yahoo.com/video/play?vid=111585">YUI Theater - Douglas Crockford - Advanced JavaScript (3 parts)</a></p></li>
<li><p><a href="http://www.youtube.com/watch?v=hQVTIJBZook">Youtube - Douglas Crockford - Javascript The Good Parts</a></p></li>
<li><p><a href="http://video.yahoo.com/watch/4403981/11812238">YUI Theater - John Resig - The DOM is a Mess</a></p></li>
<li><p><a href="http://www.youtube.com/watch?v=0LKDImgRfrg">Youtube - John Resig - Best Practices in Javascript Library Design</a></p></li>
<li><p><a href="http://www.youtube.com/watch?v=Kq4FpMe6cRs">Youtube - Google - Changes to JavaScript, Part 1: EcmaScript 5</a></p></li>
</ul>


<p><strong>Articles</strong></p>

<ul>
<li><p><a href="http://ejohn.org/blog/javascript-language-abstractions/">John Resig - Javascript Language Abstractions</a></p></li>
<li><p><a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">Joel Spolsky - The Law of Leaky Abstractions</a></p></li>
<li><p><a href="http://www.codinghorror.com/blog/archives/000857.html">Jeff Atwood - Javascript the Lingua Franca of the Web</a></p></li>
<li><p><a href="http://ejohn.org/blog/ecmascript-5-objects-and-properties/">John Resig - ECMAScript 5 Objects and Properties</a></p></li>
<li><p><a href="http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/">John Resig - ECMAScript 5 Strict Mode, JSON, and More</a></p></li>
</ul>


<p><strong>Reference</strong></p>

<ul>
<li><p><a href="https://developer.mozilla.org/En">Mozilla Developer Center</a> - Best reference. Beware, it&#8217;s Firefox-oriented.</p></li>
<li><p><a href="http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf">ECMAScript 5th edition</a> - Standard specs of &#8220;next&#8221; javascript</p></li>
</ul>

]]></content>
  </entry>
  
</feed>
