<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>blog.tornkvist.org</title>
    <link>http://blog.tornkvist.org/rss.yaws</link>
    <description>
     Contains the blog.tornkvist.org blog. Ramblings about Erlang,Yaws,jQuery and Ajax.
    </description>
    <language>en</language><item>
<title>The OTP docs.</title>
<link>http://blog.tornkvist.org/blog.yaws?id=1236468753170759</link>
<guid>http://blog.tornkvist.org/blog.yaws?id=1236468753170759</guid>
<description>&lt;p&gt;I played around with Xmerl today and came up with yet another approach to parse the simple example in an earlier &lt;a href=&quot;http://blog.tornkvist.org/blog.yaws?id=1193209275268448&quot;&gt;post&lt;/a&gt; of mine.&lt;/p&gt;

&lt;p&gt;The OTP docs are good but unfortunately often a bit too terse. How many times haven't I been tearing my hair trying to understand some aspects of the documentation. In most cases, a simple example would have been enough. I think the OTP team really should consider adding more examples to the docs. I mean, what's the point with docs that you don't understand?&lt;/p&gt;

&lt;p&gt;--Tobbe&lt;/p&gt;
</description>
<dc:creator>tobbe</dc:creator>
<dc:date>2009-03-08T00:32:33+01:00</dc:date>
</item>
<item>
<title>RFC 4226 - HMAC-Based One-Time Password Algorithm</title>
<link>http://blog.tornkvist.org/blog.yaws?id=1237597025803904</link>
<guid>http://blog.tornkvist.org/blog.yaws?id=1237597025803904</guid>
<description>&lt;p&gt;I have recently implemented RFC 4226 and put it on &lt;a href=&quot;http://github.com/etnt/ehotp/tree/master&quot;&gt;github&lt;/a&gt;. The idea is to explore ways of providing One-Time passwords in for example an OpenID setting, or for mobile applications. An old technique where comercial solutions have been around for years. Here is the beginning of an Open Source solution. &lt;/p&gt;

&lt;p&gt;Next I'm thinking of writing a j2me app. (what?, this is unheard of, programming in Java at my age...) to run on my mobile. I've started to read up on the topic, written a Hello World program using the SUN WTK (the example program actually dies in the emulator because of a nullpointer exception...). I need to get a hold on the signing part of the MIDLet though.&lt;/p&gt;

&lt;p&gt;--Tobbe&lt;/p&gt;
</description>
<dc:creator>tobbe</dc:creator>
<dc:date>2009-03-21T01:57:05+01:00</dc:date>
</item>
<item>
<title>Seethrough and NItrogen</title>
<link>http://blog.tornkvist.org/blog.yaws?id=123971846244334</link>
<guid>http://blog.tornkvist.org/blog.yaws?id=123971846244334</guid>
<description>&lt;p&gt;I’ve made a little &lt;a href=&quot;http://www.tornkvist.org:8002/web/seethrough&quot;&gt;proof of concept&lt;/a&gt; of how &lt;a href=&quot;http://github.com/etnt/seethrough_erl/tree/master&quot;&gt;Seethrough&lt;/a&gt; could be used as an alternative/complement to the current record-based way of constructing the HTML. The generated HTML source can be compared to the &lt;a href=&quot;http://www.tornkvist.org:8002/web/nitrogen&quot;&gt;original&lt;/a&gt;. The postback work, but not the actual flash update. This is because I didn’t get the &lt;em&gt;dom_state&lt;/em&gt; pickle stuff correct. &lt;/p&gt;

&lt;p&gt;As little background to &lt;a href=&quot;http://github.com/etnt/seethrough_erl/tree/master&quot;&gt;Seethrough&lt;/a&gt; I recommend the &lt;a href=&quot;http://docs.zope.org/zope2/zope2book/source/ZPT.html&quot;&gt;ZPT&lt;/a&gt; docs. A very nice read IMHO.&lt;/p&gt;

&lt;p&gt;Currently, Nitrogen do lots of its magic with the help of the process dictionary. This makes it &lt;em&gt;magical&lt;/em&gt; indeed but it also makes it hard to understand what exactly is going on. It would be better to, either pass around a ADT with a well defined API, or have an erlang process maintaining the magic. I would prefer the former since it minimies the side effects and makes debugging a lot easier. For example, in this little &lt;a href=&quot;http://www.tornkvist.org:8002/web/seethrough&quot;&gt;proof of concept&lt;/a&gt;, it would have been very easy to plug in the generation of Javascript, DomState, etc. But I guess it isn't too late to fix this, Nitrogen is still in its infancy.&lt;/p&gt;

&lt;p&gt;--Tobbe&lt;/p&gt;
</description>
<dc:creator>tobbe</dc:creator>
<dc:date>2009-04-07T04:37:26+02:00</dc:date>
</item>
<item>
<title>The importance of side-effect free coding</title>
<link>http://blog.tornkvist.org/blog.yaws?id=1239107937892262</link>
<guid>http://blog.tornkvist.org/blog.yaws?id=1239107937892262</guid>
<description>&lt;p&gt;There has recently been some discussions about ugly coding patterns like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;State1 = foo(State, ...
State2 = bar(State1, ...
State3 = baz(State2, ...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;People have argued that they want destructive assignment, variable rebinding and what not.&lt;/p&gt;

&lt;p&gt;But the thing is, doing it this way have very nice properties.
For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It is easy to create Unit testcases, an effect of not relying on side-effects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is easy to debug, for example using a tool such as 'redbug' we can easily trace what data that enters a particular function (and leaves it), and we can do this in our production system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A side-effect free function is like a lego block, i.e. it can easily be reused. Also, its internals is of no concern for anybody else and can safely be modified as long as the Input/Output interface doesn't change.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The example above shows the use of: State1...State2... etc.
It is a case which seldom occurs, at least for me. As a thumb-of
rule, I always try to make my function clauses short, constantly breaking down the code into smaller pieces of functions. This way, I seldom need to write code like the above example. If I need to perform multiple updates of a datastructure, I often write code like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;foldf([in(Key,Val2), in(Key2,Val),....], DB).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;where foldf/2 and in/2 looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;foldf(Fs,Db) -&amp;gt; lists:foldl(fun(F, Acc) -&amp;gt; F(Acc) end, Db, Fs).
in(K,V) -&amp;gt; fun(Db) -&amp;gt; in(K,V,Db) end.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But I think that regardless of what style of programming you choose, the benefits of side-effect free code that I've described, clearly outweigh the problems of the ugly looking code example. During my ~18 years of daily Erlang
programming, I've come to notice that whenever I end up with really hard bugs, they often has to do with side-effects, either caused by the use of Mnesia, by some message-passing gone a stray or by timing issues. Confining your side-effects as much as possible makes it possible to build the rest of you system in a rock-solid lego fashion. &lt;/p&gt;

&lt;p&gt;--Tobbe&lt;/p&gt;
</description>
<dc:creator>tobbe</dc:creator>
<dc:date>2009-04-07T14:38:57+02:00</dc:date>
</item>
<item>
<title>QLC power</title>
<link>http://blog.tornkvist.org/blog.yaws?id=1246622911254198</link>
<guid>http://blog.tornkvist.org/blog.yaws?id=1246622911254198</guid>
<description>&lt;p&gt;I've been doing some more work on my query DSL (described in an earlier &lt;a href=&quot;http://blog.tornkvist.org/blog.yaws?id=120596928596173&quot;&gt;post&lt;/a&gt;) for an internal project at my work. &lt;/p&gt;

&lt;p&gt;I had a number of 2GB sized Mnesia disk_only tables that I wanted to traverse in a QLC query as one single table. Writing a QLC handler solved that very nicely:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;tables() -&amp;gt;
    Tables = all_tables(),
    TF = fun() -&amp;gt; next(Tables) end,
    InfoFun = fun(keypos) -&amp;gt; 2;
             (_)      -&amp;gt; undefined
          end,
    qlc:table(TF, [{info_fun, InfoFun}]).


next([T|_] = Tables) -&amp;gt;
    next(Tables, mnesia:dirty_first(T));
next([]) -&amp;gt;
    [].

next([_|Ts], '$end_of_table') -&amp;gt;
    next(Ts);
next([T|_] = Tables, Key) -&amp;gt;
    [hd(mnesia:dirty_read(T, Key)) |
     fun() -&amp;gt; next(Tables, mnesia:dirty_next(T,Key)) end];
next([], '$end_of_table') -&amp;gt;
    [].
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So now I can make QLC queries like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[T#tab.name || T &amp;lt;- my:tables(), T#tab.age &amp;gt; 42]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hurray for QLC!&lt;/p&gt;

&lt;p&gt;--Tobbe&lt;/p&gt;
</description>
<dc:creator>tobbe</dc:creator>
<dc:date>2009-07-03T14:08:31+02:00</dc:date>
</item>
   <atom:link href="http://blog.tornkvist.org/rss.yaws" rel="self" type="application/rss+xml" /> 
  </channel>
</rss>
