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

<channel>
	<title>Erlang Thoughts</title>
	<atom:link href="http://www.erlangthoughts.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.erlangthoughts.com</link>
	<description>Thoughts and Experiences about Erlang</description>
	<lastBuildDate>Tue, 17 Jan 2012 20:57:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Avoid Race Condition in Unit Tests on Registered Processes</title>
		<link>http://www.erlangthoughts.com/testing/avoid-race-condition-in-unit-tests-on-registered-processes/</link>
		<comments>http://www.erlangthoughts.com/testing/avoid-race-condition-in-unit-tests-on-registered-processes/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 07:12:59 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[eunit]]></category>
		<category><![CDATA[race condition]]></category>
		<category><![CDATA[registered process]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=127</guid>
		<description><![CDATA[While you are writing tests for a process you are registering after the spawn, you might get bitten by a race condition in the test module. But let&#8217;s start from the beginning with some code. A super-simple gen_server: Here is a too simple bank accounting server (the logic of the server is incomplete and really [...]]]></description>
			<content:encoded><![CDATA[<p>While you are writing tests for a process you are registering after the spawn, you might get bitten by a race condition in the test module. But let&#8217;s start from the beginning with some code.</p>
<p><strong>A super-simple gen_server:</strong></p>
<p>Here is a too simple bank accounting server (the logic of the server is incomplete and really easy). I have written it for joke too many times, and here I am using dict, which is not the neat data structure to use, but ehy, we are talking about race conditions in unit testing. <img src='http://www.erlangthoughts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I link you to the <a title="Simple gen_server for bank accounting" href="http://www.erlangthoughts.com/wp-content/uploads/2011/12/bank_server.erl" target="_blank">file</a>, because 96 rows of code pasted here are too many.</p>
<p><strong>The test module:</strong></p>
<p>The tests are stupid tests. I am not focused on them right now, but only on the race condition. Remember?</p>
<pre class="brush: erl;">-module(test_bank_server).

-include_lib("eunit/include/eunit.hrl").

create_account_test_() -&gt;
    {setup,
     fun setup/0,
     fun teardown/1,
     fun(_Pid) -&gt;
	     bank_server:create_account(mirko),
	     [
	      ?_assertEqual(0, bank_server:balance(mirko))
	      ] end}.

deposit_test_() -&gt;
    {setup,
     fun setup/0,
     fun teardown/1,
     fun(_Pid) -&gt;
	     bank_server:create_account(mirko),
	     bank_server:deposit(mirko, 10),
	     bank_server:deposit(mirko, 99),
	     bank_server:create_account(roberta),
	     bank_server:deposit(roberta, 1000),
	     [
	      ?_assertEqual(109, bank_server:balance(mirko)),
	      ?_assertEqual(1000, bank_server:balance(roberta))
	     ] end}.

setup() -&gt;
    {ok, Pid} = bank_server:start_link(),
    Pid.

teardown(_Pid) -&gt;
    bank_server:stop().</pre>
<p><strong>And yep, here we have a race condition:</strong></p>
<p>Ok, as you can see our test is failing, but it is not failing the right way. We have got something wrong inside our test setup. But it seems to be caused by the teardown/1 function.</p>
<p><a href="http://www.erlangthoughts.com/wp-content/uploads/2011/12/race_condition2.jpg"><img class="aligncenter size-full wp-image-134" title="Race Condition" src="http://www.erlangthoughts.com/wp-content/uploads/2011/12/race_condition2.jpg" alt="" width="753" height="289" /></a></p>
<p><strong>Why?</strong></p>
<p>The explanation is very simple. We are issuing an asynchronous call to stop the server. So, Eunit is calling teardown/1 which sends the asynchronous message stop to the gen_server, an then it goes on to the next test, calling setup/0, but after the spawn, it could be that the previous gen_server is still alive, or it is shutting down right in that moment.</p>
<p>We can&#8217;t register a process if there is already that name registered or if the Pid does not exist on the local machine. And here we are in the first case and we get a badarg error on the function register/2 (but in this case I am using OTP, so the error message is even more clear, the bank_server process is already started, yep, because the process registered in the previous test generator is still there).</p>
<p>To tell the truth, I am using an asynchronous call here to shutdown the server. I have tried the same example with a synchronous call and I avoided the race condition returning a 4 element tuple {stop, normal, ok, State} from the gen_server, as <a title="Roberto Aloi Blog" href="http://aloiroberto.wordpress.com/" target="_blank">Roberto Aloi</a> have written in <a title="The Solution" href="http://stackoverflow.com/questions/6490377/erlang-eunit-and-gen-server-context-cleanup-failed" target="_blank">this StackOverflow post</a>. But his mate <a title="Adam Lindberg Blog" href="http://alind.io/" target="_blank">Adam Lindberg</a> still poiting to the fact we are not avoiding race condition even if we are issuing synchronous calls.</p>
<p>And at the end of the day, it could be that you don&#8217;t want to use a synchronous call at all, so let&#8217;s go to the solutions.</p>
<p><strong>How to avoid it (dirty solution):</strong></p>
<p>This is a shitty solutions (please don&#8217;t use this in your code or you will be screwed in this concurrent world). I want to write it here because you can understand that if you give the gen_server some milliseconds to shut down, you are ok, but it is still a bad practice, because you are betting on the time with an hard coded value, and it is not clean but really really dirty.</p>
<pre class="brush: erl;">setup() -&gt;
    timer:sleep(100),
    bank_server:start_link().

teardown(_Pid) -&gt;
    bank_server:stop().</pre>
<p>So, yep, no race conditions here. But it is dangerous. What if the gen_server tooks more time to shutdown? Here comes the Adam way, which is in my opinion the neat one.</p>
<p><strong>How to avoid it (neat solution):</strong></p>
<p>As I have already written above, here is the Adam Lindberg solution. I have found it the the previous mentioned <a title="The Solution" href="http://stackoverflow.com/questions/6490377/erlang-eunit-and-gen-server-context-cleanup-failed" target="_blank">StackOverflow discussion</a>.</p>
<pre class="brush: erl;">teardown(Pid) -&gt;
    bank_server:stop(),
    wait_for_exit(Pid).

wait_for_exit(Pid) -&gt;
    MRef = erlang:monitor(process, Pid),
    receive
	{'DOWN', MRef, _, _, _} -&gt;
	    ok
    end.</pre>
<p>To get to the point Adam says that its way is to monitor the gen_server process, and wait for its {&#8216;DOWN&#8217;, Ref, process, Pid, Reason} message. This is like you are synchronizing the teardown/1 and the next setup/0, and it is not hard coded, but really neat. It works good. And you are get things in sync here in your test module, but you are not forcing your gen_server to issue a synchronous call to shutdown.</p>
<p>And yep, it works:</p>
<p><a href="http://www.erlangthoughts.com/wp-content/uploads/2011/12/passed.jpg"><img class="aligncenter size-full wp-image-136" title="Tests Passed" src="http://www.erlangthoughts.com/wp-content/uploads/2011/12/passed.jpg" alt="" width="754" height="179" /></a><a href="http://www.erlangthoughts.com/wp-content/uploads/2011/12/passed.png"><br />
</a></p>
<p>Adam in the very last message of the discussion says which it is always a good practice to monitor processes that are supposed to die during testing, and I agree.</p>
<p><strong>That&#8217;s it!</strong></p>
<p>Time to wish you a great New Year&#8217;s Eve. See you within 24 hour in 2012, it will be a great year. Lots of things to do, and lots of Erlang code to write. Starting from the Erlang Factory in Brussels, see you there, ping me for beers or dinner and some Erlang discussions.</p>
<p>Bye.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/testing/avoid-race-condition-in-unit-tests-on-registered-processes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erlang Solutions unveils e-learning platform</title>
		<link>http://www.erlangthoughts.com/news/erlang-solutions-unveils-e-learning-platform/</link>
		<comments>http://www.erlangthoughts.com/news/erlang-solutions-unveils-e-learning-platform/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 11:59:47 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[courses]]></category>
		<category><![CDATA[e-learning]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[erlang solutions]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=124</guid>
		<description><![CDATA[After months of development Erlang Solutions unveiled its new product, a complete e-learning platform to provide you the opportunity to learn the language right from your desk, starting from the basics to the advanced topics. In my opinion it is a great product, and I can&#8217;t wait to try it. I have learned Erlang from [...]]]></description>
			<content:encoded><![CDATA[<p>After months of development <strong>Erlang Solutions</strong> unveiled its <a title="Erlang Solutions e-learning" href="http://www.erlang-solutions.com/press-releases/3/entry/1269" target="_blank">new product</a>, a complete e-learning platform to provide you the opportunity to learn the language right from your desk, starting from the basics to the advanced topics.</p>
<p>In my opinion it is a great product, and I can&#8217;t wait to try it. I have learned Erlang from the book <a title="Erlang Programming Book" href="http://www.amazon.com/ERLANG-Programming-Francesco-Cesarini/dp/0596518188/ref=sr_1_1?ie=UTF8&amp;qid=1317815757&amp;sr=8-1" target="_blank">Erlang Programming</a>. It is written by Francesco Cesarini and Simon Thompson and the they are the lecturers of the first course available (<strong>Erlang Express</strong>, available at a <strong>launching price of 180£</strong>), so if the book is really good and pragmatic at the right point, the e-learning will be better because of <a title="Erlang e-learning features" href="http://www.erlang-solutions.com/training/elearning/features" target="_blank">its great features</a>.</p>
<p>Erlang language has known a huge growth during the last years, starting from the advent of the multi-core processors and the consequent requeset of a developing environment which provides heavy scalability and fault tollerance.</p>
<p>Erlang has always faced the problem from the ground and the choices made at the Ericsson during the &#8217;80s have paid a gerat value today, in fact the language hugely simplifies the development of systems which have to scale and be high avalilable.</p>
<p>Until 2007 there was only a book to learn the language. During the last years some books have been published and in the future some others will come out. But it has always been difficult to really learn Erlang from your desk. Some web sites and Blog have helped a lot, and the mailing list is the best in the world, but there was the lack of something official to look when you need it. And today this lack has been filled by <strong>Erlang Solutions</strong>, which after the project <a title="Try Erlang" href="http://www.tryerlang.org/" target="_blank">tryerlang.org</a> has continued to invest on the language and its diffusion.</p>
<p>At the moment <a title="Erlang E-Learning platform" href="http://elearning.erlang-solutions.com/" target="_blank">Erlang Express</a> course is already available, but in the next future we will be able to enroll to more courses. I can&#8217;t wait to increase my skills and try the platform.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/news/erlang-solutions-unveils-e-learning-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>London Erlang Factory 2011</title>
		<link>http://www.erlangthoughts.com/events/london-erlang-factory-2011/</link>
		<comments>http://www.erlangthoughts.com/events/london-erlang-factory-2011/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 07:41:24 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[2011]]></category>
		<category><![CDATA[Conference]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Erlang Factory]]></category>
		<category><![CDATA[London]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=110</guid>
		<description><![CDATA[Last month I have been in London to attend the annual Erlang Factory conference. I haven&#8217;t had any time to write something about it, too much things to study while I was trying to getting ready for a lot of exams between the end of June and the first half of July. But at the [...]]]></description>
			<content:encoded><![CDATA[<p>Last month I have been in London to attend the annual Erlang Factory conference. I haven&#8217;t had any time to write something about it, too much things to study while I was trying to getting ready for a lot of exams between the end of June and the first half of July. But at the end of the day my exams has been great and I don&#8217;t want to waste time any more, so&#8230; Let&#8217;s go <img src='http://www.erlangthoughts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>What is Erlang?</strong></p>
<p>If you are reading this blog, probably you already know the answer to this question. But this blog entry comes from my Italian blog, and in Italy this explanation is very welcome.</p>
<p>At first sight, we could say that Erlang is a functional programming language born during the 80s in the Ericsson research Labs, it is great for build real-time, fault tolerant and concurrent systems. But ehy&#8230; Erlang is much better than this. It is not only a language, but it also has got a great runtime system which is <strong>able to reach linear scalability on multi-core systems</strong> (and this should be enough to make you understand about the bright future of this language), but there is something more.</p>
<p>Writing software in Erlang is not enough to reach fault tolerance or huge concurrency. Erlang is not a silver bullet and is for this reason that there is OTP (Open Telecom Platform), a framework more and more tied to Erlang (we usually say Erlang/OTP for this reason). <a title="OTP on Radio Electronics by Francesco Cesarini" href="http://www.radio-electronics.com/articles/telecoms-networks/open-telecommunications-platform-otp-for-open-17">OTP is a great topic</a> but to sum up its benefits, I can say that it gives you the guidelines to reach in a simple way things that are very difficult to obtain with other languages&#8230; Concurrency (the real one), fault tolerance and quickness. If you are interested in Erlang, take a look at <a title="Erlang" href="http://erlang.org" target="_blank">here</a>.</p>
<p><strong>What is the Erlang Factory?</strong></p>
<p><strong><a title="Erlang Factory" href="http://erlang-factory.com/" target="_blank">Erlang Factory</a></strong> is the most important worldwide Erlang Event. It is organized by <strong><a title="Erlang Solutions" href="http://www.erlang-solutions.com/" target="_blank">Erlang Solutions Ltd</a></strong> and there are 2 Erlang Factory events per year. One in San Francisco and the other one in London. Usually San Francisco is on March, while London is on the end of the spring in the first weeks of June. It is an unbelievable opportunity to meet giant names of the Erlang community, such as <strong>Joe Armstrong, Mike Williams</strong> (with I have had the pleasure to have lunch on the first day of the conference), <strong>Robert Virding</strong>, <strong>Francesco Cesarini</strong> and lots of other bright guys with whom is a pleasure to stop and talk about experiences with Erlang .</p>
<p>Only at the Erlang Factory you are able to dive into this environment which is getting more and more electrifying. Young Erlangers like me could understand how Erlang is used in the industrial ecosystem; it is very useful because after that you are able to make and idea on future working opportunities. On the other side, companies are able to promote their-self, telling success stories, which could be useful for other companies, reaching a knowledge reuse which is very, very useful.</p>
<p>About big companies I can mention <strong><a title="Klarna" href="https://klarna.com" target="_blank">Klarna</a></strong>, which today employs about 500 persons, and <strong>in 3 years of Erlang has only got 30 seconds of downtime on its systems</strong>, a gorgeous reliability. How can I write this post without write about <strong><a title="Basho" href="http://www.basho.com/" target="_blank">Basho</a></strong>, the company behind the <strong><a title="Riak" href="http://www.basho.com/products_riak_overview.php" target="_blank">Riak</a></strong> Database, it is having a huge growth after some difficulties during the start-up period, and this great success story has been brought to us directly by <strong><a title="Anthony Falco" href="http://twitter.com/#!/antonyfalco" target="_blank">Anthony Falco</a></strong>. I could go on with other companies, such as <strong><a title="AOL" href="http://www.aol.com/" target="_blank">AOL</a></strong>, <strong><a title="Trifork" href="http://www.trifork.com/" target="_blank">Trifork</a></strong>, <strong><a title="Wooga" href="http://www.wooga.com/" target="_blank">Wooga</a></strong> (which builds video-games back-ends which have to deal with millions of active users every days), <strong><a title="Demonware" href="http://www.demonware.net/" target="_blank">Demonware</a></strong> (one of the biggest service providers for on-line video-games&#8230; If you want a title, I can say&#8230; &#8220;<strong>Call of Duty Black Ops</strong>&#8220;), and lots of other&#8230; But the post will become unmanageable, so take a look at the <a title="Erlang Factory Talks Page" href="http://erlang-factory.com/conference/London2011/talks" target="_blank">speakers official page</a>, you will be able to find slides and videos (which will be loaded step by step on this <a title="Erlang on Vimeo" href="http://vimeo.com/erlang" target="_blank">Vimeo&#8217;s channel</a>).</p>
<p>Anyway, not only big IT firms at the Conference but even Start-Ups which starts with the right foot, writing their systems in Erlang. For example the Start-Up which is disrupting the way of betting in UK, that is <strong><a title="Smarklets" href="http://smarkets.com/" target="_blank">Smarklets</a></strong> founded by the omnipresent <strong><a title="Hunter Morris" href="http://twitter.com/skarab" target="_blank">Hunter Morris</a> </strong>with <strong><a title="Jason Trost" href="http://twitter.com/jasontrost" target="_blank">Jason Trost</a></strong>.</p>
<p>So, Erlang Factory is from StartUps to Big Firms but there are also enough space for Universities, especially for <strong><a title="Uppsala University" href="http://www.uu.se/" target="_blank">Uppsala University</a></strong>, from which comes great news such as the <strong><a title="PropEr" href="https://github.com/manopapad/proper" target="_blank">PropEr</a></strong> project, introduced by <strong>Kostis Sagonas</strong>. But there also was space for the <strong><a title="University of Kent" href="http://www.kent.ac.uk/" target="_blank">University of Kent</a></strong>, and for <strong>Simon Thompson</strong> (co-author with <strong>Francesco Cesarini</strong> of the <strong><a title="Erlang Programming" href="http://www.amazon.com/ERLANG-Programming-Francesco-Cesarini/dp/0596518188" target="_blank">Erlang Programming</a> </strong>book) who has introduced us to the latest progress done with the <strong><a title="Wrangler" href="http://www.cs.kent.ac.uk/projects/forse/wrangler/doc/overview-summary.html" target="_blank">Wrangler</a> </strong>project, an Erlang re-factoring tool.</p>
<p>At the end there have been some announcements on the future of Erlang, such as some previews on the future features of the next releases, and about this topic I want to say a big thank you to the Development Team. They are doing a great job.</p>
<p>The C-Factor is unbelievable, and for C-Factor I mean the community factor. At the end of every Conference day there is a real third half, and between some beer mugs there is the opportunity to meet each other and do some networking.</p>
<p>The pictures below, for example, depicts some moments after the second day of the Conference, while we were enjoying a beer kindly offered by <strong>Erlang Solutions</strong> in front of the <strong>Old Sessions House</strong> (the conference venue). In the first picture, half of the  &#8221;Team Italy&#8221; or rather me, <strong><a title="Roberto Aloi's Blog" href="http://aloiroberto.wordpress.com/" target="_blank">Roberto Aloi</a></strong> (author of <a title="Erlang Factory 2011 Pics" href="http://www.flickr.com/photos/erlang-consulting/" target="_blank">these gorgeous pics</a>) and <strong>Carlo Bertoldi </strong>(which I have to give thanks for the two pics below) together with <strong>Kostis Sagonas</strong> while in the second one its me with <strong>Bjarne Daker</strong>.</p>

<a href='http://www.erlangthoughts.com/events/london-erlang-factory-2011/attachment/team_italy_kostis/' title='team_italy_kostis'><img width="150" height="150" src="http://www.erlangthoughts.com/wp-content/uploads/2011/07/team_italy_kostis-150x150.jpg" class="attachment-thumbnail" alt="Team Italy with Kostis Sagonas" title="team_italy_kostis" /></a>
<a href='http://www.erlangthoughts.com/events/london-erlang-factory-2011/attachment/me_and_bjarne_daker/' title='me_and_bjarne_daker'><img width="150" height="150" src="http://www.erlangthoughts.com/wp-content/uploads/2011/07/me_and_bjarne_daker-150x150.jpg" class="attachment-thumbnail" alt="Me and Bjarne Daker" title="me_and_bjarne_daker" /></a>

<p>&nbsp;</p>
<p>If you have questions, maybe not only about the Conference, but on Erlang too don&#8217;t hesitate to contact me on <a href="http://twitter.com/#!/mirkobonadei" target="_blank">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/events/london-erlang-factory-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Great Erlangers Interviewed by Paolo</title>
		<link>http://www.erlangthoughts.com/blogosphere/great-erlangers-interviewed-by-paolo/</link>
		<comments>http://www.erlangthoughts.com/blogosphere/great-erlangers-interviewed-by-paolo/#comments</comments>
		<pubDate>Wed, 25 May 2011 10:17:02 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[Blogosphere]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Interviews]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=98</guid>
		<description><![CDATA[During last weeks, on Paolo D&#8217;Incau&#8217;s blog you can find some interesting interviews which Paolo is doing to the best Erlangers in the world. My advice is to don&#8217;t miss them out. Here is a quick list of the interviews Paolo has done so far: Francesco Cesarini Roberto Aloi Simon Thompson And more are yet [...]]]></description>
			<content:encoded><![CDATA[<p>During last weeks, on <a href="http://pdincau.wordpress.com" target="_blank">Paolo D&#8217;Incau&#8217;s blog</a> you can find some interesting interviews which Paolo is doing to the best Erlangers in the world.</p>
<p>My advice is to don&#8217;t miss them out. Here is a quick list of the interviews Paolo has done so far:</p>
<ul>
<li><a href="http://pdincau.wordpress.com/2011/04/25/an-interview-with-francesco-cesarini-francescoc/" target="_blank">Francesco Cesarini</a></li>
<li><a href="http://pdincau.wordpress.com/2011/05/04/an-interview-with-roberto-aloi-robertoaloi/" target="_blank">Roberto Aloi</a></li>
<li><a href="http://pdincau.wordpress.com/2011/05/23/an-interview-with-simon-thompson/" target="_blank">Simon Thompson</a></li>
</ul>
<p>And more are yet to come&#8230;</p>
<p>See you soon, I am so close to end my post about gen_server <img src='http://www.erlangthoughts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/blogosphere/great-erlangers-interviewed-by-paolo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m a busy guy :)</title>
		<link>http://www.erlangthoughts.com/uncategorized/im-a-busy-guy/</link>
		<comments>http://www.erlangthoughts.com/uncategorized/im-a-busy-guy/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 21:37:50 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=87</guid>
		<description><![CDATA[Wow, I haven&#8217;t written anything here since last December. A huge amount of time&#8230; Too much time for my likes. During these last months I have been involved in a lot of stuffs, first of all my university exams and then my work (about 8 hours per day) and an English course. So, I haven&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 250px"><a href="http://farm3.static.flickr.com/2598/3925712473_6254eb50a4_m.jpg"><img title="University Milan-Bicocca" src="http://farm3.static.flickr.com/2598/3925712473_6254eb50a4_m.jpg" alt="" width="240" height="160" /></a><p class="wp-caption-text">My University</p></div>
<p>Wow, I haven&#8217;t written anything here since last December. A huge amount of time&#8230; Too much time for my likes. During these last months I have been involved in a lot of stuffs, first of all my university exams and then my work (about 8 hours per day) and an English course. So, I haven&#8217;t had too much time for my Erlang blog.</p>
<p>I am studying Computer Science at University Milan-Bicocca, and I have just finished my first 4 courses: <strong>Elements of Math</strong>, <strong>Network Architecture</strong>, <strong>Computer Architecture</strong> (mostly based on <strong>MIPS</strong> Architecture) and <strong>Programming</strong> (a little course on OOP, Java and UML). Next week I am starting with <strong>Math Analysis</strong>, <strong>Database</strong>, <strong>Programming</strong> (Java again&#8230;) and <strong>Algorithms and Data Structures</strong>.</p>
<p>I hope to find enough time to deep understanding Erlang and to blog something here. In two weeks I will attend the first NoSQL Event here in Italy, and I am looking forward to be at the London Erlang Factory. I can&#8217;t promise anything because it depends on my June schedule, but I seriously want to be there with the best Erlangers.</p>
<p>Thanks to <a href="http://www.flickr.com/photos/samuel-huron/" target="_blank">Samuel Huron</a> for the photo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/uncategorized/im-a-busy-guy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interesting readings</title>
		<link>http://www.erlangthoughts.com/blogosphere/interesting-readings/</link>
		<comments>http://www.erlangthoughts.com/blogosphere/interesting-readings/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 12:28:00 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[Blogosphere]]></category>
		<category><![CDATA[Erlang]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=84</guid>
		<description><![CDATA[One of the first blogs I read 10 months ago (when I started learning Erlang) was the James Hague&#8217;s one.  Yesterday James published an interesting list of his best posts he has written during the last three years. Don&#8217;t miss it, James is a video games designer since 1980s, and he has been using Erlang [...]]]></description>
			<content:encoded><![CDATA[<p>One of the first blogs I read 10 months ago (when I started learning Erlang) was the James Hague&#8217;s one.  Yesterday James published an <a title="James Hague" href="http://prog21.dadgum.com/88.html" target="_blank">interesting list</a> of his best posts he has written during the last three years. Don&#8217;t miss it, James is a video games designer since 1980s, and he has been using Erlang for 11 years. In his blog you can find some interesting readings from &#8220;Why he started using Erlang&#8221; since some good thoughts about Functional Programming.</p>
<p>Here on my new Blog, I am planning to collect all the best blogs and sites about Erlang in the Community section. James will be surely part of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/blogosphere/interesting-readings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>In difense of Erlang</title>
		<link>http://www.erlangthoughts.com/blogosphere/in-difense-of-erlang/</link>
		<comments>http://www.erlangthoughts.com/blogosphere/in-difense-of-erlang/#comments</comments>
		<pubDate>Sun, 26 Dec 2010 09:34:57 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[Blogosphere]]></category>
		<category><![CDATA[Debate]]></category>
		<category><![CDATA[Erlang]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=78</guid>
		<description><![CDATA[It is Christmas Time (so I give you my best holiday wishes), but the Erlang community never rests and in the last hours JLoius have published a good post answering to Sudarshan Acharya&#8217;s one (this last post was originally written in 2008) that criticizes Erlang on seven disputable points. From time to time, I need [...]]]></description>
			<content:encoded><![CDATA[<p>It is Christmas Time (so I give you my best holiday wishes), but the Erlang community never rests and in the last hours JLoius have published a good post answering to Sudarshan Acharya&#8217;s one (this last post was originally written in 2008) that criticizes Erlang on seven disputable points.</p>
<p>From time to time, I need to explain to people (here in Italy) why I am studying Erlang. For some people it is not a good choice because they think OOP is the unique and global programming paradigm that counts. I disagree with them and I think that religion wars are stupids, so I decide to study Erlang because I think polyglot programming is nice point of view. I can&#8217;t do everything with Java and I can&#8217;t do everything with Erlang. But it is great for a programmer to be able to choose the right tool for the job, understanding when one has advantages on the other.</p>
<p>I am feeling fine with Erlang syntax (if you are a real programmer you can&#8217;t complain only because the syntax is not C like) and I hope to work with this language in my future. At the moment I continue to learn how to use it reading books, blogs and writing here and when I will have enough experience I will like to write my personal response to Sudarshan Acharya&#8217;s blog post.</p>
<p><strong>Links to the debate:</strong></p>
<ul>
<li><a href="http://sacharya.com/erlang-overhyped-or-underestimated/" target="_blank">Sudarshan Acharya&#8217;s &#8211; Erlang over-hyped or underestimated</a></li>
<li><a href="http://jlouisramblings.blogspot.com/2010/12/response-to-erlang-overhyped-or.html" target="_blank">JLoius &#8211; A response to &#8220;Erlang over-hyped or underestimated&#8221;</a></li>
</ul>
<p><strong>Update 1 (26 December):</strong></p>
<p><a href="http://be-seeing-you.com/post/2466506947/christmas-thoughts" target="_blank">Here</a> you can find another good post titled &#8220;Christmas Thoughts&#8221;. Nice to see that the thoughts of this blogger is very close with mine. <img src='http://www.erlangthoughts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/blogosphere/in-difense-of-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pattern matching</title>
		<link>http://www.erlangthoughts.com/beginner/pattern-matching/</link>
		<comments>http://www.erlangthoughts.com/beginner/pattern-matching/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 10:16:26 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Pattern Matching]]></category>
		<category><![CDATA[Syntax]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=41</guid>
		<description><![CDATA[In this post I want to write something about Pattern Matching, because if you have never used a functional programming language before using Erlang you have to deal with it as soon as you can. It is focal point if you want to understand examples written in Erlang or if you want to start write [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I want to write something about <strong>Pattern Matching</strong>, because if you have never used a functional programming language before using Erlang you have to deal with it as soon as you can. It is focal point if you want to understand examples written in Erlang or if you want to start write something in the right way.</p>
<p>You will use Pattern Matching in three (fundamental) cases:</p>
<ul>
<li>Variable Assignement</li>
<li>Controlling the flow</li>
<li>Data filtering from complex structures</li>
</ul>
<p>Let&#8217;s go in order with my bullet point list.</p>
<p><strong>Variable Assignment</strong></p>
<p>This argument could be hard to understand if you come from a classic programming language. Why? Simple, because you have to understand from the beginning that variables can&#8217;t be assigned, they can only be pattern matched. The = operator is not assignment operator, but it is Pattern Matching  operator, and it compares the left side of the expression with the right  side. It could succeed or fail.</p>
<p>For example, if the value in A is 1, and I write A=1 in the Erlang Shell, the Pattern Matching succeeds because the assertion is true. To make an assignment, you have to Pattern Match an unbound variable with the value you want to give to it. In fact, if a variable is unbound, the only way for  succeed in the Pattern Matching is to bound it to the value on the right side of the = operator. It is also important to understand that a Pattern could be composed not only by variables, but by literals too (integer, float, atoms&#8230;).</p>
<p>OK, now you are thinking, &#8220;Oh, so strange, and why I can assign a value to a variable only one time? So they are not variable. I&#8217;m used to do whatever I want with a variable&#8221;.</p>
<p>You are right, they are variables that don&#8217;t vary, because in this way <strong>we can forget about side effects</strong> caused by wrong assignments in some parts of the program.</p>
<p>We also can <strong>detect an error more faster</strong> because we have to search only for one place in order to find the wrong value.</p>
<p><em>As a little resume about this point:</em> When you pattern match a value to a variable, if it is unbound the value will be assigned to the variable and the Pattern Matching is true. If the variable is bound, the value on the right side must be the same of the variable to have success in the evaluation, elsewhere you will get an error at runtime.</p>
<p><strong>Controlling the flow</strong></p>
<p>With this construct you can manage the flow control in a pragmatic way, it is intuitive and it will improve the way you write code.</p>
<p>Instead of using tons of &#8220;if clauses&#8221; you can be more pragmatic, in the <em>case</em> and <em>receive </em>statements (the first is a conditional evaluation and the second is about processes) or in the function definition. In this post, I will cover only functions, because the other two statements involve more knowledge, and these aren&#8217;t in the purposes of the post.</p>
<p>A function in Erlang, is defined as a collection of clauses and when it is called, Erlang chooses the right one by Pattern Matching the parameters list.</p>
<p>That is a very easy example:</p>
<pre class="brush: erl;">greetings({woman, _Name, _Surname}) -&gt;
     "Hello Madame";
greetings({man, _Name, _Surname}) -&gt;
     "Hello Sir";
greetings(_) -&gt;
     "Hello".</pre>
<p>When we call the greeting function we could pass a tagged tuple, and based on the tag element Erlang will choose the right clause (using the Pattern Matching principles). It is a good habit to insert the last clause that matches everything, in this way we could return a default or an error value.</p>
<p><strong>Data filtering from complex structures</strong></p>
<p>In Erlang, you will surely use lists or tuples. Once you have one of them, you will surely need to extract or check the values in the structure.</p>
<p>Let&#8217;s start from the lists:<br />
With lists, you can for example extract or check the value of the Head or the Tail of the list.</p>
<p><strong>Example 1:</strong> The H and the T variables are unbound:</p>
<pre class="brush: erl;">List=[1,2,3,4,5].
[H|T] = List.</pre>
<p>In this case, after the evaluation of the second instruction, H will be 1 and T will be [2,3,4,5]. Because the Pattern Matching assign the value on the right to an unbound variable on the left. Don&#8217;t worry about the |, it is about <em>Lists</em>, I will probably cover it in a future post.<br />
<strong> Example 2:</strong> Suppose that the H value is 1 and the T value is [2,3]:</p>
<pre class="brush: erl;">List=[1,2,3,4,5].
[H|T] = List.</pre>
<p>In this case we get an error at runtime, because if it is true that H matches with the head of the List, the T is not the same, in this case, the tail of the list has got 4 elements and T has got only 2 elements.</p>
<p>With tuples, it is quite the same thing, but we don&#8217;t have to think about the cons construct (|). Let&#8217;s go with a quick example before write some bits about the &#8220;don&#8217;t care&#8221;:</p>
<pre class="brush: erl;">Tuple = {driver, "Lewis", "Hamilton"}.
{driver, Name, Surname} = Tuple.</pre>
<p>In this case we have a F1 driver (my favourite) in the Tuple variable. In the second instruction, we check that the tuple contains a driver, pattern matching the first element with the <em>atom</em> driver, and then, if Name and Surname are unbound we could extract &#8220;Lewis&#8221; and &#8220;Hamilton&#8221; in only one instruction. If they are not unbound, we can instead check if we are dealing with the same driver, in the other case, we get a runtime error.<br />
Something must be said about &#8220;don&#8217;t care&#8221; variables in the Pattern Matching. Erlang compiler is a kind entity, and if it understands that you are not using a bound variable it returns some warning as a reminder to you. But if you really don&#8217;t need them, you could make the variable start with _, so the compiler and others programmers will understand that the variable don&#8217;t care in the execution.</p>
<p>A variable  could be only an _, but in this case it is only a place holder that matches with all the possible values and it will never be assigned.</p>
<p><strong>As Ulf Wiger remind to me in the first comment</strong> to this post, the only real &#8220;don&#8217;t care&#8221; is the _, while a variable that starts with _ (for example _Var) is a real variable, the only difference with the others is that the the linter has been instructed not to warn about them. So if you use for example _Var twice in a function, it will be bound the second time and if don&#8217;t pay enough attention, you could surprisingly obtain a  &#8221;badmatch&#8221; error because the Pattern Matching could fail as for the other variables that doesn&#8217;t start with _.</p>
<p>Here an example:</p>
<pre class="brush: erl;">% Surname is not used in the function so that we use the _ in front of it
get_driver_name({driver, Name, _Surname}) -&gt;
     Name.</pre>
<p>I hope this post could help someone to get in touch with Pattern Matching. It must be understand from the beginning because it is a masterpiece of the language, a lot of things are based on it, so don&#8217;t underestimate this concept.</p>
<p><strong>Other resources:</strong></p>
<ul>
<li><a title="Learn You some Erlang for great good" href="http://learnyousomeerlang.com/syntax-in-functions#pattern-matching" target="_blank">Learn you some Erlang for great good</a></li>
<li><a title="Erlang Programming" href="http://oreilly.com/catalog/9780596518189" target="_blank">Erlang Programming (from page 33 to 38)</a></li>
<li><a title="Programming Erlang: Software for a Concurrent World" href="http://www.pragprog.com/titles/jaerlang/programming-erlang" target="_blank">Programming Erlang &#8211; Software for a concurrent world (page 18-19-20-21-25-26-30-31)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/beginner/pattern-matching/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Back to my training</title>
		<link>http://www.erlangthoughts.com/uncategorized/back-to-my-training/</link>
		<comments>http://www.erlangthoughts.com/uncategorized/back-to-my-training/#comments</comments>
		<pubDate>Sat, 11 Dec 2010 20:03:16 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=39</guid>
		<description><![CDATA[I opened this blog two months ago and since then I wrote only one post. It seems a World Record. But from today I am finally back to my training, and in the next days I&#8217;m going to start to write something here on these pages See you soon, happy Saturday night!]]></description>
			<content:encoded><![CDATA[<p>I opened this blog two months ago and since then I wrote only one post. It seems a World Record. But from today I am finally back to my training, and in the next days I&#8217;m going to start to write something here on these pages <img src='http://www.erlangthoughts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>See you soon, happy Saturday night!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/uncategorized/back-to-my-training/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some bits of Erlang history</title>
		<link>http://www.erlangthoughts.com/history/some-bits-of-erlang-history/</link>
		<comments>http://www.erlangthoughts.com/history/some-bits-of-erlang-history/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 06:34:44 +0000</pubDate>
		<dc:creator>Mirko</dc:creator>
				<category><![CDATA[History]]></category>
		<category><![CDATA[Ericsson Labs]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[TryErlang]]></category>

		<guid isPermaLink="false">http://www.erlangthoughts.com/?p=16</guid>
		<description><![CDATA[Hi everyone, and thank you for being here. As you can see, I decided to start a new blog about Erlang, a programming language that is gaining more and more interest not only in the IT world but in my heart too This is my first post, but instead of writing a long intro, I would like to [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone, and thank you for being here. As you can see, I decided to start a new blog about Erlang, a programming language that is gaining more and more interest not only in the IT world but in my heart too <img src='http://www.erlangthoughts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This is my first post, but instead of writing a long intro, I would like to share with you some bits of history about the language. For the intros you can always read the <a title="Erlang Thoughts About" href="http://www.erlangthoughts.com/about/" target="_self">About page</a>.</p>
<p>Before starting, I invite you to take a look at the following video, in which you can see <strong>Joe Armstrong</strong>, <strong>Mike Williams</strong> and <strong>Robert Virding</strong> (and <strong>Bjarne Dacker</strong> in the first minute of the clip) explaining the reasons why their telecom system is so simple, but reliable and powerful.</p>
<p>[google -5830318882717959520 nolink]</p>
<p>Nice, isn&#8217;t it? As you have just seen, they were using Erlang to implement a telecom system. They was working at Ericsson in those years and during the early 80s they were looking for a great programming language to solve some problems of systems that needed to be distributed, concurrent and fault tolerant. They was thinking about a language with scalability and reliability build inside of the language, but after long searches they understood that there wasn&#8217;t nothing like that. So that they decided to create a new programming language with those key features built inside itself. At the <strong>Ericsson Computer Science Laboratory</strong> they spent about 4 years prototyping and evolving the language that nowadays has been used in a lot of distributed systems across the world.</p>
<p>In my opinion (to be honest, not only mine) the focal point is that Joe and Company at the Ericsson Labs needed to solve a specific problem. That problem was not so common in those years, and they were focused on create something that was able to be different from the past experiences. So that, they got the insight of build those features directly inside of the language instead of build them at the top of it. This was a success for Ericsson but 20 years later it still remain a success for a growing number of developers not only in the telecom domain but in a large range of situations.</p>
<p>Erlang was released as Open Source in December 1998, and from then the community is still growing, the stable release of the language is the <strong><a title="Download Erlang" href="http://www.erlang.org/download.html" target="_blank">R14B</a></strong>. If you are not an &#8220;Erlanger&#8221; and you want to take a look without be forced to install the Erlang System on your machine, my advice is to visit <strong><a title="Try Erlang" href="http://www.tryerlang.org/" target="_blank">TryErlang.org</a></strong>. On the site, you can go through some little but interesting tutorials and you can dive into this great language.</p>
<p>See you soon <img src='http://www.erlangthoughts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.erlangthoughts.com/history/some-bits-of-erlang-history/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

