<?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>desgrange.net &#187; programming</title>
	<atom:link href="http://blog.desgrange.net/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.desgrange.net</link>
	<description></description>
	<lastBuildDate>Mon, 30 Jan 2012 21:00:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>FOSDEM 2011</title>
		<link>http://blog.desgrange.net/2011/01/31/fosdem-2011/</link>
		<comments>http://blog.desgrange.net/2011/01/31/fosdem-2011/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 21:00:35 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Belgium]]></category>
		<category><![CDATA[Brussels]]></category>
		<category><![CDATA[FOSDEM]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=1292</guid>
		<description><![CDATA[FOSDEM (Free and Open Source Software Developers’ European Meeting) 2011 is happening this week-end (5-6 february) in Brussels as usual. I&#8217;m not living there anymore but I&#8217;m going to FOSDEM this year again. This meeting is really open source developer oriented, several communities are meeting there (debian, mozilla, kde, enlightenment…) and I&#8217;m unfortunately not involved [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/FOSDEM" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/FOSDEM?referer=');">FOSDEM</a> (Free and Open Source Software Developers’ European Meeting) 2011 is happening this week-end (5-6 february) in Brussels as usual. I&#8217;m not living there anymore but I&#8217;m going to <a href="http://www.fosdem.org" onclick="pageTracker._trackPageview('/outgoing/www.fosdem.org?referer=');">FOSDEM</a> this year again.</p>
<p>This meeting is really open source developer oriented, several communities are meeting there (<a href="http://www.debian.org/" onclick="pageTracker._trackPageview('/outgoing/www.debian.org/?referer=');">debian</a>, <a href="http://www.mozilla.org/" onclick="pageTracker._trackPageview('/outgoing/www.mozilla.org/?referer=');">mozilla</a>, <a href="http://www.kde.org/" onclick="pageTracker._trackPageview('/outgoing/www.kde.org/?referer=');">kde</a>, <a href="http://www.enlightenment.org/" onclick="pageTracker._trackPageview('/outgoing/www.enlightenment.org/?referer=');">enlightenment</a>…) and I&#8217;m unfortunately not involved in any of this, so lots of tracks are too specific for me. Nonetheless some of them are more &#8220;general&#8221; and sound interesting.</p>
<p><a href="/2010/02/03/fosdem-2010">Last year I was wondering how to contribute</a> a bit to the open source community, the only thing I did was small piece of software (called <a href="http://pwad.desgrange.net/" onclick="pageTracker._trackPageview('/outgoing/pwad.desgrange.net/?referer=');">pwad</a>) to download <a href="http://picasa.google.com/" onclick="pageTracker._trackPageview('/outgoing/picasa.google.com/?referer=');">picasa</a> albums sent by friends. I can do better than that.</p>
<p>Anyway, FOSDEM is a great event, if you are in Brussels at that time, you should definitely go there and at least have a look of what&#8217;s happening. Last year I learned very interesting stuff and ideas that I hope will be nicely integrated in mainstream software/operating systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2011/01/31/fosdem-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do not check email adresses!</title>
		<link>http://blog.desgrange.net/2010/06/21/do-not-check-email-adresses/</link>
		<comments>http://blog.desgrange.net/2010/06/21/do-not-check-email-adresses/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 20:00:46 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=1144</guid>
		<description><![CDATA[You may have noticed that on some rare websites (≈99.999 % of internet websites), you have to provide an email address when you register. And most of the time the application running the website check if the email address you entered is valid. But you know what? Most software developers (you know, the guys staying [...]]]></description>
			<content:encoded><![CDATA[<p>You may have noticed that on some rare websites (≈99.999 % of internet websites), you have to provide an email address when you register. And most of the time the application running the website check if the email address you entered is valid.</p>
<p>But you know what? Most software developers (you know, the guys staying all day long in front of computers, the guys you call when you have a problem with your computer because they have some magical power that allows them to fix your problems) don&#8217;t know what a valid email address is!</p>
<p>Why do I say such things? Because each time I register on a website, it complains that I should enter a valid email address… but my email address is valid actually! What I&#8217;m complaining about is not that they check email addresses of course, I&#8217;m complaining about the fact they are rejecting valid ones. Like for an email spam filter, you don&#8217;t care that some spam emails still reach your inbox, but you hate when a valid email is dropped because it was considered spam.</p>
<p>Unfortunately, most email address filters that have been written are rejecting a lot of valid email addresses. Why? Because checking that an email address has a valid format is very difficult. Have a look at this <a href="http://en.wikipedia.org/wiki/Email_address#RFC_specification" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Email_address_RFC_specification?referer=');">summary of RFC&#8217;s email address format</a>, you will understand what I mean.</p>
<p>So, if you are a software developer and you have to check the validity of email addresses, don&#8217;t bother much checking the email address format (or the strict minimum like &#8220;there is a &#8216;@&#8217; and a &#8216;.&#8217;) because even an email address that have a valid format may be invalid (in the way that the corresponding email account does not exists).</p>
<p>For registration process it&#8217;s easily solved by asking the user to click on a confirmation link you send them to the given email address. Only then you will know that the email address is really valid.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2010/06/21/do-not-check-email-adresses/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Les Cast Codeurs</title>
		<link>http://blog.desgrange.net/2010/06/14/les-cast-codeurs/</link>
		<comments>http://blog.desgrange.net/2010/06/14/les-cast-codeurs/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 20:00:52 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[french]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[podcast]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=1122</guid>
		<description><![CDATA[Si vous êtes développeur Java, vous connaissez certainement le podcast The Java Posse, 4 experts (Tor Norbye, Carl Quinn, Dick Wall et Joe Nuxoll) du monde Java (au sens large) parlant des news concernant Java, la JVM et tout ce qui touche de près ou de loin (voire de très loin) à ça, sur un [...]]]></description>
			<content:encoded><![CDATA[<p>Si vous êtes développeur <a href="http://fr.wikipedia.org/wiki/Java_%28technique%29" onclick="pageTracker._trackPageview('/outgoing/fr.wikipedia.org/wiki/Java_28technique_29?referer=');">Java</a>, vous connaissez certainement le podcast <a href="http://javaposse.com/" onclick="pageTracker._trackPageview('/outgoing/javaposse.com/?referer=');">The Java Posse</a>, 4 experts (<a href="http://blogs.sun.com/tor/" onclick="pageTracker._trackPageview('/outgoing/blogs.sun.com/tor/?referer=');">Tor Norbye</a>, <a href="http://www.linkedin.com/in/carlquinn" onclick="pageTracker._trackPageview('/outgoing/www.linkedin.com/in/carlquinn?referer=');">Carl Quinn</a>, <a href="http://dickwallsblog.blogspot.com/" onclick="pageTracker._trackPageview('/outgoing/dickwallsblog.blogspot.com/?referer=');">Dick Wall</a> et <a href="http://joeracer.blogspot.com/" onclick="pageTracker._trackPageview('/outgoing/joeracer.blogspot.com/?referer=');">Joe Nuxoll</a>) du monde Java (au sens large) parlant des news concernant Java, la <a href="http://fr.wikipedia.org/wiki/JVM_%28informatique%29" onclick="pageTracker._trackPageview('/outgoing/fr.wikipedia.org/wiki/JVM_28informatique_29?referer=');">JVM</a> et tout ce qui touche de près ou de loin (voire de très loin) à ça, sur un ton en général très décontracté et humoristique.</p>
<p>Il y a un peu plus d&#8217;un an maintenant, 4 français (<a href="http://blog.emmanuelbernard.com/" onclick="pageTracker._trackPageview('/outgoing/blog.emmanuelbernard.com/?referer=');">Emmanuel Bernard</a>, <a href="http://glaforge.free.fr/weblog/" onclick="pageTracker._trackPageview('/outgoing/glaforge.free.fr/weblog/?referer=');">Guillaume Laforge</a>, <a href="http://www.antoniogoncalves.org/" onclick="pageTracker._trackPageview('/outgoing/www.antoniogoncalves.org/?referer=');">Antonio Goncalves</a> et <a href="http://massol.myxwiki.org/" onclick="pageTracker._trackPageview('/outgoing/massol.myxwiki.org/?referer=');">Vincent Massol</a>) ont décidé de faire quelque chose de similaire, le podcast <a href="http://lescastcodeurs.com/" onclick="pageTracker._trackPageview('/outgoing/lescastcodeurs.com/?referer=');">Les Cast Codeurs</a>, mais dans la <a href="http://fr.wiktionary.org/wiki/langue_de_Moli%C3%A8re" onclick="pageTracker._trackPageview('/outgoing/fr.wiktionary.org/wiki/langue_de_Moli_C3_A8re?referer=');">langue de Molière</a>. Je dois avouer qu&#8217;au début je ne voyais pas trop l&#8217;intérêt, étant donné que nous travaillons dans un secteur très anglophone, ça me semblait assez redondant avec The Java Posse, à part peut-être pour les quelques irréductibles gaulois qui ne comprennent toujours rien à l&#8217;anglais (et il semblerait qu&#8217;il y en ait encore pas mal en France <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
<p>Récemment je me suis décidé à en écouter quelques épisodes, et c&#8217;est plutôt pas mal, même si dans l&#8217;idée c&#8217;est assez proche du Java Posse, le contenu et l&#8217;approche sont assez différents pour que ce ne soit pas complètement redondant. Sans compter que l&#8217;actualité française et européenne du domaine (si si, il y en a) est un peu plus abordée. C&#8217;est entre autre par Les Cast Codeurs que j&#8217;ai découvert le <a href="http://www.brussels-jug.be/" onclick="pageTracker._trackPageview('/outgoing/www.brussels-jug.be/?referer=');">BruJUG</a>.</p>
<p>Continuez comme ça les gars, ça me fait quelque chose de plus à écouter dans le métro <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2010/06/14/les-cast-codeurs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Power of Abstraction</title>
		<link>http://blog.desgrange.net/2010/06/01/the-power-of-abstraction/</link>
		<comments>http://blog.desgrange.net/2010/06/01/the-power-of-abstraction/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 20:00:34 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=1139</guid>
		<description><![CDATA[During last BruJUG third half-time, Alex Snaps told us about a presentation by Barbara Liskov (also known for the Liskov Substitution Principle) in which she tell us a bit of computer science history, how the data abstraction emerged and so on. It&#8217;s a very interesting presentation, it&#8217;s quite amazing to see that most of programming [...]]]></description>
			<content:encoded><![CDATA[<p>During last <a href="http://www.brussels-jug.be/" onclick="pageTracker._trackPageview('/outgoing/www.brussels-jug.be/?referer=');">BruJUG</a> third half-time, <a href="http://www.jroller.com/greenhorn/" onclick="pageTracker._trackPageview('/outgoing/www.jroller.com/greenhorn/?referer=');">Alex Snaps</a> told us about a presentation by <a href="http://en.wikipedia.org/wiki/Barbara_Liskov" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Barbara_Liskov?referer=');">Barbara Liskov</a> (also known for the <a href="http://en.wikipedia.org/wiki/Liskov_substitution_principle" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Liskov_substitution_principle?referer=');">Liskov Substitution Principle</a>) in which she tell us a bit of computer science history, how the data abstraction emerged and so on.</p>
<p>It&#8217;s a very interesting presentation, it&#8217;s quite amazing to see that most of programming languages principles where designed 30-40 years ago. If you are a developer, I recommend you to watch <a href="http://www.infoq.com/presentations/liskov-power-of-abstraction" onclick="pageTracker._trackPageview('/outgoing/www.infoq.com/presentations/liskov-power-of-abstraction?referer=');">Barbara Liskov&#8217;s presentation: &#8220;The Power of Abstraction&#8221;</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2010/06/01/the-power-of-abstraction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BruJUG</title>
		<link>http://blog.desgrange.net/2010/05/31/brujug/</link>
		<comments>http://blog.desgrange.net/2010/05/31/brujug/#comments</comments>
		<pubDate>Mon, 31 May 2010 20:00:39 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Brussels]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=1130</guid>
		<description><![CDATA[Last wednesday (May 26th) was the first BruJUG session, and I was there . So, what&#8217;s BruJUG? It&#8217;s Brussels&#8217; Java User Group, so if you are a Java developer living/working in Brussels, you might be interested to attend BruJUG sessions in order to learn some stuff, talk with other developers, exchange some ideas, have a [...]]]></description>
			<content:encoded><![CDATA[<p>Last wednesday (May 26th) was the first <a href="http://www.brussels-jug.be/" onclick="pageTracker._trackPageview('/outgoing/www.brussels-jug.be/?referer=');">BruJUG</a> session, and I was there <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>So, what&#8217;s BruJUG? It&#8217;s Brussels&#8217; <a href="http://java.sun.com/community/usergroups/" onclick="pageTracker._trackPageview('/outgoing/java.sun.com/community/usergroups/?referer=');">Java User Group</a>, so if you are a <a href="http://en.wikipedia.org/wiki/Java_(programming_language)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Java_programming_language?referer=');">Java</a> developer living/working in <a href="http://en.wikipedia.org/wiki/Brussels" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Brussels?referer=');">Brussels</a>, you might be interested to attend BruJUG sessions in order to learn some stuff, talk with other developers, exchange some ideas, have a good beer…</p>
<p>When I was in <a href="http://en.wikipedia.org/wiki/Paris" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Paris?referer=');">Paris</a>, I was going quite often to the <a href="http://www.parisjug.org/" onclick="pageTracker._trackPageview('/outgoing/www.parisjug.org/?referer=');">ParisJUG</a>, which was the first JUG in France. BruJUG just started but it&#8217;s not the first one in <a href="http://en.wikipedia.org/wiki/Belgium" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Belgium?referer=');">Belgium</a>, there is also <a href="http://www.bejug.org/" onclick="pageTracker._trackPageview('/outgoing/www.bejug.org/?referer=');">BeJUG</a> which is moving from cities to cities in Belgium.</p>
<p>What happens in Wednesday&#8217;s session? First of all it was in <a href="http://en.wikipedia.org/wiki/Google" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Google?referer=');">Google</a>&#8216;s office, aka GooglePlex,  which is quite a nice one and there was two presentations, a non-technical one on <a href="http://en.wikipedia.org/wiki/Content_strategy" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Content_strategy?referer=');">content strategy</a> and a technical one on <a href="http://ehcache.org/" onclick="pageTracker._trackPageview('/outgoing/ehcache.org/?referer=');">ehcache</a> (and a bit of <a href="http://www.terracotta.org/" onclick="pageTracker._trackPageview('/outgoing/www.terracotta.org/?referer=');">terracotta</a> of course). Both were very interesting, you can read the<a href="http://www.brussels-jug.be/?p=681" onclick="pageTracker._trackPageview('/outgoing/www.brussels-jug.be/?p=681&amp;referer=');"> session post on BruJUG website</a> or <a href="http://www.brussels-jug.be/wiki/doku.php?id=events:2010_05_session1" onclick="pageTracker._trackPageview('/outgoing/www.brussels-jug.be/wiki/doku.php?id=events_2010_05_session1&amp;referer=');">on BruJUG&#8217;s wiki</a> (there are some pictures too!).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2010/05/31/brujug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login/Password autocomplete</title>
		<link>http://blog.desgrange.net/2010/02/22/loginpassword-autocomplete/</link>
		<comments>http://blog.desgrange.net/2010/02/22/loginpassword-autocomplete/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 22:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Greasemonkey]]></category>
		<category><![CDATA[autocompletion]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web browsers]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=708</guid>
		<description><![CDATA[A feature I really like in most web browsers, is the ability they have to “remember” my login and password for a given website. And I like the way Firefox does that, by displaying a non-intrusive notification bar at the top of the page while loading the page: (I don’t like the way Safari does, [...]]]></description>
			<content:encoded><![CDATA[<p>A feature I really like in most <a hreflang="en" href="http://en.wikipedia.org/wiki/Web_browser" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Web_browser?referer=');">web browsers</a>, is the ability they have to “remember” my login and password for a given website. And I like the way <a hreflang="en" href="http://en.wikipedia.org/wiki/Firefox" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Firefox?referer=');">Firefox</a> does that, by displaying a non-intrusive notification bar at the top of the page while loading the page:</p>
<p><a href="http://blog.desgrange.net/wp-content/uploads/2010/02/credentials_save.png"><img class="aligncenter size-medium wp-image-1057" title="credentials_save" src="http://blog.desgrange.net/wp-content/uploads/2010/02/credentials_save-300x14.png" alt="" width="300" height="14" /></a></p>
<p>(I don’t like the way <a hreflang="en" href="http://en.wikipedia.org/wiki/Safari_%28web_browser%29" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Safari_28web_browser_29?referer=');">Safari</a> does, by putting a modal window. So I have to already answer if I want to save my credentials before being sure that I entered the right ones)</p>
<p>I really like this feature for several reasons. I think it’s more secure than having to type my password. Some people may disagree, but to me, having that feature allows me to set a different password on every website I have an account on. Without that feature I will use the same password everywhere which is a very bad idea. If I use the same password everywhere, if somebody finds out what my password is, he will have access to all my accounts. And this is way much more easier than you may think:</p>
<ul>
<li>lots of websites does not do the login procedure on a secure connection so intercepting data is not that difficult, especially with non-secure WiFi / free WiFi access points</li>
<li>lots of websites/companies store your password in plain text in their databases, so mostly anybody working in that company at some point in time may see your password (and I’m not kidding, I’ve seen that myself several times (If I was a bad guy, which I’m not by the way <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> , I would already be the owner of thousands of emails/logins/passwords))</li>
</ul>
<p>An other reason why I think using the web browser’s password manager is more secure is because if at some point a malware installs a key-logger on your computer (which is not unusual on Windows computers), each time you type your password it’s a chance more for the key-logger to record it.</p>
<p>And of course, web browsers save your passwords in a crypted file (and not in a plain text file as some people do, which is also not really secure). To me, the biggest downside of this feature is that I can’t log in a lot of websites if I’m not using my computer because I don’t remember my passwords.</p>
<p>So there is something I really don’t like when surfing the web, is when I use websites where, for some reason, Firefox/Safari does not ask me to remember my password. Until recently I didn’t checked why, I was supposing that the login form was done in a way that web browsers did not recognized it as a login form (maybe because of an intensive use of <a hreflang="en" href="http://en.wikipedia.org/wiki/JavaScript" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/JavaScript?referer=');">javascript</a>). But it looks like I was wrong on that, and that there are people stupid enough to call “feature” the ability of a website to prevent your web browsers to store your credentials.</p>
<p>From what I have seen so far, several web browsers disable the auto completion/password manager when the attribute <code>autocomplete="off"</code> is set on a form or input field. First of all: this attribute IS NOT STANDARD. It’s not part of any <a hreflang="en" href="http://en.wikipedia.org/wiki/HTML" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/HTML?referer=');">HTML</a>/<a hreflang="en" href="http://en.wikipedia.org/wiki/XHTML" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/XHTML?referer=');">XHTML</a> specification. It seems it was invented by <a hreflang="en" href="http://en.wikipedia.org/wiki/Microsoft" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Microsoft?referer=');">Microsoft</a> for <a hreflang="en" href="http://en.wikipedia.org/wiki/Internet_Explorer" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Internet_Explorer?referer=');">Internet Explorer</a> a long time ago (why bad ideas always come from the same guys? <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
<p>There is a page on Mozilla’s developers website explaining <a hreflang="en" href="https://developer.mozilla.org/En/How_to_Turn_Off_Form_Autocompletion" onclick="pageTracker._trackPageview('/outgoing/developer.mozilla.org/En/How_to_Turn_Off_Form_Autocompletion?referer=');">how works the autocompletion and how to turn it off</a>, and the page on <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/ms533486%28VS.85%29.aspx" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/ms533486_28VS.85_29.aspx?referer=');">autocompletion attribute</a> on <a hreflang="en" href="http://en.wikipedia.org/wiki/MSDN" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/MSDN?referer=');">MSDN</a> website.</p>
<p>The second point is: ok, Internet Explorer has this stupid feature, why other web browsers have also implemented it? The final decision has to be done by the user, not some manager of a website who thinks that he knows what you want better than you.</p>
<p>The only point I see where it may be useful, is that it also works for forms other than login forms. For login forms your web browser always ask you if you want it to store your login and passwords in a secure place. For other forms, the web browser remembers everything, in a place that may not be secure, and without asking you anything, which might be quite bad when filling a payment form with your credit card number. At this point, what would be useful, is a way to say to the web browsers that some data in the form are sensitive information (so the web browser may ask you if it should remember those data, and in that case put them in a secure place).</p>
<p>If you have followed until here, my point is: the <code>autocomplete</code> attribute sucks, it does not solve any problem and annoys me.</p>
<h5>How to make those broken websites behave correctly again?</h5>
<p>Several possibilities:</p>
<ul>
<li>use a web browser that does not understand the <code>autocomplete</code> attribute (I don’t know which ones)</li>
<li>if you are using an open source web browser that supports that attribute, remove the support from the sources, compile, enjoy (that’s one of the freedoms of open source)</li>
<li>if you use Firefox, use <a hreflang="en" href="http://en.wikipedia.org/wiki/Greasemonkey" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Greasemonkey?referer=');">Greasemonkey</a></li>
</ul>
<p>First time I heard about Greasemonkey was several years ago, but for some reasons my neurons did not connect together at that time and I did not realized the power of this Firefox plugin, until I saw <a href="http://blog.mozbox.org/" onclick="pageTracker._trackPageview('/outgoing/blog.mozbox.org/?referer=');">Paul</a>’s demo at <a hreflang="en" href="http://en.wikipedia.org/wiki/FOSDEM" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/FOSDEM?referer=');">FOSDEM</a>. Since then, I love that plugin. Simply said, this plugin allows you to fix websites <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . First thing I did after installing it was to fix my bank website, which was forbidding me to go straight to the login page and was also forcing me to open the login page in an other tab/window. Greasemonkey allowed me to fix that with one line of code (really only one line, and a simple one in that case). Greasemonkey also has a lot of <a hreflang="en" href="http://userscripts.org/" onclick="pageTracker._trackPageview('/outgoing/userscripts.org/?referer=');">user contributed scripts</a> for several websites (from that I found one fixing the download links on <a href="http://www.jamendo.com" onclick="pageTracker._trackPageview('/outgoing/www.jamendo.com?referer=');">Jamendo</a> (in order to download directly the <a hreflang="en" href="http://en.wikipedia.org/wiki/OGG_Vorbis" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/OGG_Vorbis?referer=');">OGG Vorbis</a> version of an album (which is not possible from the website) and without opening a stupid download window)).</p>
<p>Something I love, on the scripts website, is the following sentence, at the bottom of the website: “Because it’s your web”.</p>
<p>How to fix the <code>autocomplete</code> attribute with Greasemonkey? My first try, was with my company’s Outlook Web Access (yes, unfortunately there are some people/companies actually paying for that), and guess what? Somebody already did a script for that: <a hreflang="en" href="http://userscripts.org/scripts/show/42508" onclick="pageTracker._trackPageview('/outgoing/userscripts.org/scripts/show/42508?referer=');">Allow Browser To Save Outlook Web Access Password</a>.</p>
<p>So I was wondering: “do I have to do a script on every website that use <code>autocomplete="off"</code>”? I ended up, a few minutes after, with that script (note: I don’t know javascript at all, any comments to improve this script is welcomed):</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="javascript" style="font-family:monospace;"><span class="co1">// ==UserScript==</span>
<span class="co1">// @name           Turn ON autocompletion</span>
<span class="co1">// @namespace      http://desgrange.net</span>
<span class="co1">// @include        *</span>
<span class="co1">// ==/UserScript==</span>
<span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="kw2">function</span> turnAutocompleteOn<span class="br0">&#40;</span>element<span class="br0">&#41;</span> <span class="br0">&#123;</span>
		<span class="kw1">if</span><span class="br0">&#40;</span>element.<span class="me1">hasAttribute</span><span class="br0">&#40;</span><span class="st0">'autocomplete'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
			element.<span class="me1">setAttribute</span><span class="br0">&#40;</span><span class="st0">'autocomplete'</span><span class="sy0">,</span> <span class="st0">'on'</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="br0">&#125;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="kw1">for</span><span class="br0">&#40;</span>formKey <span class="kw1">in</span> document.<span class="me1">forms</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		turnAutocompleteOn<span class="br0">&#40;</span>document.<span class="me1">forms</span><span class="br0">&#91;</span>formKey<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="kw2">var</span> inputs <span class="sy0">=</span> document.<span class="me1">getElementsByTagName</span><span class="br0">&#40;</span><span class="st0">'input'</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i<span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0">&lt;</span>inputs.<span class="me1">length</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		turnAutocompleteOn<span class="br0">&#40;</span>inputs.<span class="kw1">item</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>It’s a bit brutal, on every pages you visit, it looks for all forms and all <code>input</code> tags having the <code>autocomplete</code> attribute and set it to “on”. I don’t know how often this <code>autocomplete</code> attribute is used, so I don’t know yet the side effects of doing that on every pages (that’s why I have not put this script on <a href="http://userscripts.org" onclick="pageTracker._trackPageview('/outgoing/userscripts.org?referer=');">http://userscripts.org</a> yet).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2010/02/22/loginpassword-autocomplete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging in Weblogic console with Log4J</title>
		<link>http://blog.desgrange.net/2010/02/15/logging-in-weblogic-console-with-log4j/</link>
		<comments>http://blog.desgrange.net/2010/02/15/logging-in-weblogic-console-with-log4j/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 22:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[weblogic]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=702</guid>
		<description><![CDATA[If you have developed a JEE web application using Log4J for logging and have it deployed on a WebLogic application server, you may wonder how to display the logs in WebLogic console: Preparation You simply need to create and add a Log4J appender. This appender will redirect Log4J events to WebLogic by using the NonCatalogLogger [...]]]></description>
			<content:encoded><![CDATA[<p>If you have developed a JEE web application using Log4J for logging and have it deployed on a WebLogic application server, you may wonder how to display the logs in WebLogic console:</p>
<p><a href="http://blog.desgrange.net/wp-content/uploads/2010/02/weblogic_01.png"><img class="aligncenter size-full wp-image-1052" title="weblogic_01" src="http://blog.desgrange.net/wp-content/uploads/2010/02/weblogic_01.png" alt="" width="379" height="211" /></a></p>
<h5>Preparation</h5>
<p>You simply need to create and add a Log4J appender. This appender will redirect Log4J events to WebLogic by using the NonCatalogLogger class. You can found this class in <code>wls-api.jar</code> or <code>wlclient.jar</code> (depending on your WebLogic version) from your WebLogic’s lib directory. For instance if you are using maven, you need to add one the following dependencies in your maven’s <code>pom.xml</code> (enter the version corresponding to your WebLogic installation):</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="xml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;dependency<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;groupId<span class="re2">&gt;</span></span></span>weblogic<span class="sc3"><span class="re1">&lt;/groupId<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;artifactId<span class="re2">&gt;</span></span></span>wlclient<span class="sc3"><span class="re1">&lt;/artifactId<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;version<span class="re2">&gt;</span></span></span>10.3<span class="sc3"><span class="re1">&lt;/version<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;scope<span class="re2">&gt;</span></span></span>provided<span class="sc3"><span class="re1">&lt;/scope<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/dependency<span class="re2">&gt;</span></span></span></pre></div></div>
<p>or</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="xml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;dependency<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;groupId<span class="re2">&gt;</span></span></span>weblogic<span class="sc3"><span class="re1">&lt;/groupId<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;artifactId<span class="re2">&gt;</span></span></span>wls-api<span class="sc3"><span class="re1">&lt;/artifactId<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;version<span class="re2">&gt;</span></span></span>10.0<span class="sc3"><span class="re1">&lt;/version<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;scope<span class="re2">&gt;</span></span></span>provided<span class="sc3"><span class="re1">&lt;/scope<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/dependency<span class="re2">&gt;</span></span></span></pre></div></div>
<p>Obviously WebLogic JARs are not in official Maven repositories (due to license/distribution restrictions, proprietary softwares always here to hassle you). So type the following command in your shell to add the API in your local maven repository:</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;">mvn <span class="kw2">install</span>:install-file <span class="re5">-DgroupId</span>=weblogic <span class="re5">-DartifactId</span>=wlclient <span class="re5">-Dversion</span>=10.3 <span class="re5">-Dpackaging</span>=jar <span class="re5">-Dfile</span>=wlclient.jar</pre></div></div>
<p>or</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;">mvn <span class="kw2">install</span>:install-file <span class="re5">-DgroupId</span>=weblogic <span class="re5">-DartifactId</span>=wls-api <span class="re5">-Dversion</span>=10.0 <span class="re5">-Dpackaging</span>=jar <span class="re5">-Dfile</span>=wls-api.jar</pre></div></div>
<h5>Creating the appender</h5>
<p>The appender needs to implement Log4J’s <code>Appender</code> interface, but it’s more convenient to extends <code>AppenderSkeleton</code>. WebLogic’s <code>NonCatalogLogger</code> class has some “debug”, “info”… methods like Log4J so the appender is just going to map one to the other.</p>
<p>Since you may deploy your application on something else than WebLogic (for instance I usually use Tomcat and/or Jetty for development/testing) you don’t want have it crashing your application because WebLogic classes are not here. The appender can check if the class is in the classpath (using <code>Class.forName()</code>) and do nothing if the <code>NonCatalogLogger</code> is not here.</p>
<p>In WebLogic’s console, there is a “Subsystem” column, we can set it in the appender to display the application name.</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="java" style="font-family:monospace;"><span class="kw1">package</span> <span class="co2">sample.project</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">import</span> <span class="co2">org.apache.log4j.AppenderSkeleton</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.apache.log4j.Level</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.apache.log4j.spi.LoggingEvent</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">import</span> <span class="co2">weblogic.logging.NonCatalogLogger</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">public</span> <span class="kw1">class</span> WeblogicAppender <span class="kw1">extends</span> AppenderSkeleton <span class="br0">&#123;</span>
    <span class="kw1">private</span> <span class="kw1">static</span> <span class="kw1">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Astring+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">String</span></a> SUBSYSTEM <span class="sy0">=</span> <span class="st0">&quot;SampleProject&quot;</span><span class="sy0">;</span>
    <span class="kw1">private</span> NonCatalogLogger logger<span class="sy0">;</span>
&nbsp;
    <span class="kw1">public</span> WeblogicAppender<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">try</span> <span class="br0">&#123;</span>
            <span class="kw1">Class</span>.<span class="me1">forName</span><span class="br0">&#40;</span><span class="st0">&quot;weblogic.logging.NonCatalogLogger&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            logger <span class="sy0">=</span> <span class="kw1">new</span> NonCatalogLogger<span class="br0">&#40;</span>SUBSYSTEM<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span> <span class="kw1">catch</span> <span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aclassnotfoundexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Aclassnotfoundexception+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">ClassNotFoundException</span></a> e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="co1">// Not running on WebLogic server.</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
&nbsp;
    @Override
    <span class="kw1">protected</span> <span class="kw4">void</span> append<span class="br0">&#40;</span>LoggingEvent event<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span>logger <span class="sy0">==</span> <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw1">return</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span>Level.<span class="me1">TRACE</span>.<span class="me1">equals</span><span class="br0">&#40;</span>event.<span class="me1">getLevel</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            logger.<span class="me1">trace</span><span class="br0">&#40;</span>getMessage<span class="br0">&#40;</span>event<span class="br0">&#41;</span>, getThrowable<span class="br0">&#40;</span>event<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>Level.<span class="me1">DEBUG</span>.<span class="me1">equals</span><span class="br0">&#40;</span>event.<span class="me1">getLevel</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            logger.<span class="me1">debug</span><span class="br0">&#40;</span>getMessage<span class="br0">&#40;</span>event<span class="br0">&#41;</span>, getThrowable<span class="br0">&#40;</span>event<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>Level.<span class="me1">INFO</span>.<span class="me1">equals</span><span class="br0">&#40;</span>event.<span class="me1">getLevel</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            logger.<span class="me1">info</span><span class="br0">&#40;</span>getMessage<span class="br0">&#40;</span>event<span class="br0">&#41;</span>, getThrowable<span class="br0">&#40;</span>event<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>Level.<span class="me1">WARN</span>.<span class="me1">equals</span><span class="br0">&#40;</span>event.<span class="me1">getLevel</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            logger.<span class="me1">warning</span><span class="br0">&#40;</span>getMessage<span class="br0">&#40;</span>event<span class="br0">&#41;</span>, getThrowable<span class="br0">&#40;</span>event<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>Level.<span class="me1">ERROR</span>.<span class="me1">equals</span><span class="br0">&#40;</span>event.<span class="me1">getLevel</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            logger.<span class="me1">error</span><span class="br0">&#40;</span>getMessage<span class="br0">&#40;</span>event<span class="br0">&#41;</span>, getThrowable<span class="br0">&#40;</span>event<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>Level.<span class="me1">FATAL</span>.<span class="me1">equals</span><span class="br0">&#40;</span>event.<span class="me1">getLevel</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            logger.<span class="me1">critical</span><span class="br0">&#40;</span>getMessage<span class="br0">&#40;</span>event<span class="br0">&#41;</span>, getThrowable<span class="br0">&#40;</span>event<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
&nbsp;
    @Override
    <span class="kw1">public</span> <span class="kw4">void</span> close<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">// Nothing to do here.</span>
    <span class="br0">&#125;</span>
&nbsp;
    @Override
    <span class="kw1">public</span> <span class="kw4">boolean</span> requiresLayout<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">return</span> <span class="kw2">false</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="kw1">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Astring+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">String</span></a> getMessage<span class="br0">&#40;</span>LoggingEvent event<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">return</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Astring+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">String</span></a>.<span class="me1">valueOf</span><span class="br0">&#40;</span>event.<span class="me1">getMessage</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="kw1">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3Athrowable+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">Throwable</span></a> getThrowable<span class="br0">&#40;</span>LoggingEvent event<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span>event.<span class="me1">getThrowableInformation</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">!=</span> <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw1">return</span> event.<span class="me1">getThrowableInformation</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getThrowable</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
            <span class="kw1">return</span> <span class="kw2">null</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>
<h5>Log4J configuration</h5>
<p>In your <code>log4j.xml</code> just define a new appender using the above class and add it to the root logger. Here is an example:</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="xml" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span> <span class="re2">?&gt;</span></span>
<span class="sc0">&lt;!DOCTYPE log4j:configuration SYSTEM &quot;log4j.dtd&quot;&gt;</span>
<span class="sc3"><span class="re1">&lt;log4j:configuration</span> <span class="re0">xmlns:log4j</span>=<span class="st0">&quot;http://jakarta.apache.org/log4j/&quot;</span><span class="re2">&gt;</span></span>
	<span class="sc3"><span class="re1">&lt;appender</span> <span class="re0">name</span>=<span class="st0">&quot;console&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;org.apache.log4j.ConsoleAppender&quot;</span><span class="re2">&gt;</span></span>
		<span class="sc3"><span class="re1">&lt;param</span> <span class="re0">name</span>=<span class="st0">&quot;Target&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;System.out&quot;</span> <span class="re2">/&gt;</span></span>
		<span class="sc3"><span class="re1">&lt;layout</span> <span class="re0">class</span>=<span class="st0">&quot;org.apache.log4j.PatternLayout&quot;</span><span class="re2">&gt;</span></span>
			<span class="sc3"><span class="re1">&lt;param</span> <span class="re0">name</span>=<span class="st0">&quot;ConversionPattern&quot;</span> <span class="re0">value</span>=<span class="st0">&quot;%-5p %c{1} - %m%n&quot;</span> <span class="re2">/&gt;</span></span>
		<span class="sc3"><span class="re1">&lt;/layout<span class="re2">&gt;</span></span></span>
	<span class="sc3"><span class="re1">&lt;/appender<span class="re2">&gt;</span></span></span>
&nbsp;
	<span class="sc3"><span class="re1">&lt;appender</span> <span class="re0">name</span>=<span class="st0">&quot;weblogic&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;sample.project.WeblogicAppender&quot;</span> <span class="re2">/&gt;</span></span>
&nbsp;
	<span class="sc3"><span class="re1">&lt;root<span class="re2">&gt;</span></span></span>
		<span class="sc3"><span class="re1">&lt;priority</span> <span class="re0">value</span>=<span class="st0">&quot;debug&quot;</span> <span class="re2">/&gt;</span></span>
		<span class="sc3"><span class="re1">&lt;appender-ref</span> <span class="re0">ref</span>=<span class="st0">&quot;console&quot;</span> <span class="re2">/&gt;</span></span>
		<span class="sc3"><span class="re1">&lt;appender-ref</span> <span class="re0">ref</span>=<span class="st0">&quot;weblogic&quot;</span> <span class="re2">/&gt;</span></span>
	<span class="sc3"><span class="re1">&lt;/root<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/log4j:configuration<span class="re2">&gt;</span></span></span></pre></div></div>
<h5>Check</h5>
<p>I have created a simple servlet logging some messages in debug, info and warn levels, let’s call it and see what happens:</p>
<p><a href="http://blog.desgrange.net/wp-content/uploads/2010/02/weblogic_02.png"><img class="aligncenter size-full wp-image-1053" title="weblogic_02" src="http://blog.desgrange.net/wp-content/uploads/2010/02/weblogic_02.png" alt="" width="612" height="399" /></a></p>
<p>It works! (OK, I was not going to write all that just to show something that does not work <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ). But be careful, as you can see, the debug message is not displayed even after setting Log4J’s level to debug. My WebLogic console is configured to display higher level messages. Don’t forget to check that it’s logging at the right level for you.</p>
<h5>Notes</h5>
<p>All source code in this post is in public domain, do what ever you want with it. I did it quickly so it may not work as you want, you are strongly advised to adapt it to your needs. I’m not mastering WebLogic at all (in fact I don’t really like that application server) so it may not be the best way to do it (and usually you should not need to do such things), and it is not at all certified in any way to be “production ready”.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2010/02/15/logging-in-weblogic-console-with-log4j/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Post FOSDEM 2010</title>
		<link>http://blog.desgrange.net/2010/02/08/post-fosdem-2010/</link>
		<comments>http://blog.desgrange.net/2010/02/08/post-fosdem-2010/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 22:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Belgium]]></category>
		<category><![CDATA[Brussels]]></category>
		<category><![CDATA[FOSDEM]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=707</guid>
		<description><![CDATA[So last week-end I was at FOSDEM. First, it’s quite huge. Several thousand geeks in one location (if somebody hates open source, it’s the place to drop a bomb, lots of projects might also die afterward (I’m just saying that it’s not so cool on a risk management point of view, I’m not encouraging anybody [...]]]></description>
			<content:encoded><![CDATA[<p>So last week-end I was at <a hreflang="en" href="http://en.wikipedia.org/wiki/FOSDEM" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/FOSDEM?referer=');">FOSDEM</a>. First, it’s quite huge. Several thousand <a hreflang="en" href="http://en.wikipedia.org/wiki/Geek" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Geek?referer=');">geeks</a> in one location (if somebody hates <a hreflang="en" href="http://en.wikipedia.org/wiki/Open_source" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Open_source?referer=');">open source</a>, it’s the place to drop a bomb, lots of projects might also die afterward (I’m just saying that it’s not so cool on a risk management point of view, I’m not encouraging anybody to do such a bad thing <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> )). A lot of smart people, good ideas, interesting stuff to see, to hear and free <a hreflang="en" href="http://en.wikipedia.org/wiki/WiFi" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/WiFi?referer=');">WiFi</a> everywhere (such thing would be illegal in France nowadays :-\).</p>
<p>As usual with conferences, goodies review. What do we get: &#8211; conference program (on paper) &#8211; a bag (made from <a hreflang="en" href="http://en.wikipedia.org/wiki/Biodegradation" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Biodegradation?referer=');">biodegradable</a> material)</p>
<p>That’s all good to me. Quite eco-friendy and nothing is unnecessary.</p>
<p>Here is the list of sessions I attended:</p>
<h5>Welcome (<a href="http://fosdem.org/2010/about/fosdem#team" onclick="pageTracker._trackPageview('/outgoing/fosdem.org/2010/about/fosdem_team?referer=');">FOSDEM Staff</a>)</h5>
<p>Quick <a hreflang="en" href="http://archive.fosdem.org/" onclick="pageTracker._trackPageview('/outgoing/archive.fosdem.org/?referer=');">history of the FOSDEM</a> and of course the <a href="http://www.0xdeadbeef.com/weblog/2010/02/the-fosdem-dance/" onclick="pageTracker._trackPageview('/outgoing/www.0xdeadbeef.com/weblog/2010/02/the-fosdem-dance/?referer=');">FOSDEM dance</a>.</p>
<h5>Promoting Open Source Methods at a Large Company (Brooks Davis)</h5>
<p>Brooks Davis told us how they managed to bring some of the open source way of working in a big aerospace company. I find incredible that in a company working for aerospace (and even any company doing software) some developers are still not using any <a hreflang="en" href="http://en.wikipedia.org/wiki/Revision_control" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Revision_control?referer=');">version control system</a>.</p>
<h5>Evil on the Internet (<a hreflang="en" href="http://www.cl.cam.ac.uk/~rnc1/" onclick="pageTracker._trackPageview('/outgoing/www.cl.cam.ac.uk/_rnc1/?referer=');">Richard Clayton</a>)</h5>
<p>Quick presentation of what “bad people” are doing on the internet and how it works, with live examples of <a hreflang="en" href="http://en.wikipedia.org/wiki/Phishing" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Phishing?referer=');">phishing</a>/fake banks/fake escrow websites.</p>
<p>Visit the <a hreflang="en" href="http://wiki.aa419.org/index.php/Main_Page" onclick="pageTracker._trackPageview('/outgoing/wiki.aa419.org/index.php/Main_Page?referer=');">AA419 website</a> for more information.</p>
<h5>Mozilla Europe/Mozilla Foundation (<a href="http://standblog.org/blog/" onclick="pageTracker._trackPageview('/outgoing/standblog.org/blog/?referer=');">Tristan Nitot</a>/<a hreflang="en" href="http://weblogs.mozillazine.org/gerv/" onclick="pageTracker._trackPageview('/outgoing/weblogs.mozillazine.org/gerv/?referer=');">Gervase Markham</a>)</h5>
<p>Some info on current status and future stuff at <a hreflang="en" href="http://en.wikipedia.org/wiki/Mozilla_Foundation" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Mozilla_Foundation?referer=');">Mozilla</a>. Some discussion about the <a hreflang="en" href="http://www.computerworld.com/s/article/9142416/FAQ_How_the_IE_ballot_screen_works" onclick="pageTracker._trackPageview('/outgoing/www.computerworld.com/s/article/9142416/FAQ_How_the_IE_ballot_screen_works?referer=');">ballot screen</a>.</p>
<p>Personal note: the ballot screen will appear for every Windows XP/Vista/7 users how do not have installed any other web browser. This is a decision of the <a hreflang="en" href="http://en.wikipedia.org/wiki/European_Commission" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/European_Commission?referer=');">European Commission</a> imposed to <a hreflang="en" href="http://en.wikipedia.org/wiki/Microsoft" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Microsoft?referer=');">Microsoft</a>. But what about people working at the European Commission? Are they going to see the ballot screen on their computers? Obviously, like in any company managing their computers, this is going to be blocked in order to keep the “homogeneity” and ease of system administration. Guess what? I am working at the EC (as external contractor). Since I’m a developer, I can install whatever I want^H^H^H^Hneed on my work computer so I don’t have the problem (and in fact since I’m doing a bit of web development I’ve all major web browsers installed). Anyway, I will see if my colleagues get some choice for their web browser.</p>
<h5><a hreflang="en" href="http://en.wikipedia.org/wiki/FLOSS" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/FLOSS?referer=');">FLOSS</a>: a key to self-determination in Internet life (<a hreflang="en" href="http://blog.lizardwrangler.com/" onclick="pageTracker._trackPageview('/outgoing/blog.lizardwrangler.com/?referer=');">Mitchell Baker</a>)</h5>
<p>OK, I can’t really summarize but it was interesting. Free and open source software have values, freedom related ones (at least). To some extent we can see those values in how the internet has been built and we need to be sure that those values are still going to drive the future of the internet and even take a more predominant place.</p>
<h5>Hackability (<a hreflang="en" href="http://en.wikipedia.org/wiki/Tristan_Nitot" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Tristan_Nitot?referer=');">Tristan Nitot</a>/<a href="http://blog.mozbox.org/" onclick="pageTracker._trackPageview('/outgoing/blog.mozbox.org/?referer=');">Paul Rouget</a>)</h5>
<p>Do you want the internet to be a place only for for-profit companies to sell you their products? I hope not (if you do, what the hell are you doing here?). An important thing that will prevent that is to be sure that the internet is hackable. That mean we can do what we want with it, event if it was not designed for.</p>
<p>I would like to give an example of a hackable product by design: a <a hreflang="en" href="http://en.wikipedia.org/wiki/Lego" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Lego?referer=');">Lego</a> box. When you buy a <a href="http://www.lego.com" onclick="pageTracker._trackPageview('/outgoing/www.lego.com?referer=');">Lego</a> box, it’s shipped with a manual with one or two (sometimes more) patterns to build what Lego thinks you might want to build with. But obviously, it’s for fun, and Lego does not forbid you to do anything else with it, on the contrary, they encourage you to do stuff they didn’t think you could do with it… and it’s quite normal since Lego bricks are done to <a hreflang="en" href="http://www.toxel.com/inspiration/2008/10/11/collection-of-incredible-lego-creations/" onclick="pageTracker._trackPageview('/outgoing/www.toxel.com/inspiration/2008/10/11/collection-of-incredible-lego-creations/?referer=');">build whatever you want</a>.</p>
<p>On the internet it’s quite the same. You have bricks. Different kind of bricks, versatile ones (<a hreflang="en" href="http://en.wikipedia.org/wiki/Bit" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Bit?referer=');">bits</a> and <a hreflang="en" href="http://en.wikipedia.org/wiki/Byte" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Byte?referer=');">bytes</a>) on top of which people have created more complex bricks (<a hreflang="en" href="http://en.wikipedia.org/wiki/HTML" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/HTML?referer=');">HTML</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/HTTP" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/HTTP?referer=');">HTTP</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/SMTP" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/SMTP?referer=');">SMTP</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/IMAP" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/IMAP?referer=');">IMAP</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/XMPP" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/XMPP?referer=');">XMPP</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/XML" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/XML?referer=');">XML</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/CSS" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/CSS?referer=');">CSS</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/JavaScript" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/JavaScript?referer=');">JavaScript</a>…) allowing you to do any kind of things. But there are some stuff that are not following that concept. Take <a hreflang="en" href="http://en.wikipedia.org/wiki/Adobe_Flash" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Adobe_Flash?referer=');">Flash</a> for instance, here you have the Logo box already mounted and you can’t unmount it, you can play a bit with it but not that much.</p>
<p>Paul did a demo showing that the web is hackable (changing the <a hreflang="en" href="http://en.wikipedia.org/wiki/User_interface" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/User_interface?referer=');">UI</a> of a website and with the help of <a hreflang="en" href="http://en.wikipedia.org/wiki/Firefox" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Firefox?referer=');">Firefox</a>/<a hreflang="en" href="http://en.wikipedia.org/wiki/Greasemonkey" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Greasemonkey?referer=');">Greasemonkey</a> change how to interact with the website), that <a href="http://www.mozilla.com/firefox" onclick="pageTracker._trackPageview('/outgoing/www.mozilla.com/firefox?referer=');">Firefox</a> is hackable (switching from a tab to an other by shaking his <a hreflang="en" href="http://en.wikipedia.org/wiki/Wiimote" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Wiimote?referer=');">wiimote</a>!).</p>
<h5>HTML 5 (Paul Rouget)</h5>
<p>The “theorical” part of the presentation was done by someone else but I don’t have his name (sorry). Anyway, since most of the stuff I developed so far were web applications, I was quite interested in this presentation (and of course because I have been too lazy to check by myself what’s new in <a hreflang="en" href="http://en.wikipedia.org/wiki/HTML5" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/HTML5?referer=');">HTML 5</a>).</p>
<p><a hreflang="en" href="http://dev.w3.org/html5/spec/spec.html" onclick="pageTracker._trackPageview('/outgoing/dev.w3.org/html5/spec/spec.html?referer=');">HTML 5</a> syntax, very pragmatic. HTML has been slaughtered on so many web pages that web browsers are now very good at understanding the understandable. So of course, instead of imposing a drastic syntax (like XML based stuff requires usually) that nobody is going to apply, HTML 5 is quite “user friendly” (in  the way that you can type whatever you want, it’s going to work (uppercase, lowercase, it doesn’t care, you don’t close your tags? not a problem…)). I think web browsers (except IE of course <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) are the perfect example of “be strict in what you send, but generous in what you receive”.</p>
<p>Anyway, lots of new tags like <code>header</code>, <code>footer</code>, <code>aside</code>, of course <code>video</code>, <code>canvas</code>…</p>
<p>Paul did an amazing demo with a “simple webpage” turning out to be an interactive presentation with CSS transitions, video playing, 2D transformations, 3D ones… impressive.</p>
<h5>Amarok 2.2 Rocking (<a hreflang="en" href="http://www.krohlas.de/blog/" onclick="pageTracker._trackPageview('/outgoing/www.krohlas.de/blog/?referer=');">Sven Krohlas</a>)</h5>
<p>I was an <a hreflang="en" href="http://en.wikipedia.org/wiki/Amarok_%28software%29" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Amarok_28software_29?referer=');">Amarok</a> user for a long time but since I switched to the <a hreflang="en" href="http://en.wikipedia.org/wiki/Macintosh" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Macintosh?referer=');">Mac</a> it’s not the case anymore (even though <a href="http://amarok.kde.org/" onclick="pageTracker._trackPageview('/outgoing/amarok.kde.org/?referer=');">Amarok</a> runs on Mac). Anyway, the moodbar is back!</p>
<p>I haven’t played a lot with Amarok 2.x, but I don’t feel very comfortable with the UI. In 2.2 it’s a bit better. Maybe a part of the problem is that I don’t like KDE’s default theme.</p>
<p>It was a conference on free (as in free speech) softwares, but there are not only softwares that are free, there is also music. Go to <a href="http://www.jamendo.com" onclick="pageTracker._trackPageview('/outgoing/www.jamendo.com?referer=');">Jamendo</a> and listen/download a bit of music, you might discover good music under <a hreflang="en" href="http://en.wikipedia.org/wiki/Creative_Commons" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Creative_Commons?referer=');">Creative Commons</a> licenses (I recommend: <a href="http://www.jamendo.com/en/artist/Diablo_Swing_Orchestra_%282%29" onclick="pageTracker._trackPageview('/outgoing/www.jamendo.com/en/artist/Diablo_Swing_Orchestra_282_29?referer=');">Diablo Swing Orchestra</a> and <a hreflang="en" href="http://www.jamendo.com/en/artist/david.tmx" onclick="pageTracker._trackPageview('/outgoing/www.jamendo.com/en/artist/david.tmx?referer=');">David TMX</a>)</p>
<h5>NoSQL for Fun &amp; Profit (Tim Anglade)</h5>
<p>A quick overview of what is <a hreflang="en" href="http://en.wikipedia.org/wiki/NoSQL" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/NoSQL?referer=');">NoSQL</a>, no technical details, more a presentation for managers. Anyway, like lots of people I have suffered of <a hreflang="en" href="http://en.wikipedia.org/wiki/SQL" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/SQL?referer=');">SQL</a>. For several reasons, first, it’s hard to find a project where a relational database is not badly used, a <a hreflang="en" href="http://en.wikipedia.org/wiki/RDBMS" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/RDBMS?referer=');">RDBMS</a> can be very good at what it does (like <a hreflang="en" href="http://en.wikipedia.org/wiki/PostgreSQL" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/PostgreSQL?referer=');">PostgreSQL</a>), it still needs to be used correctly, and secondly, because it was almost the only way “managers” did know about storing data. Who have never seen that kind of situation:</p>
<p>The manager: “On our new software we are going to use this programming language and that relational database.”</p>
<p>The developer: “I can understand that we need a programming language since we are going to write a software, but we don’t need a relational database for it.”</p>
<p>The manager: “Of course we need a relational database, every software use a relational database.”</p>
<p>The developer: “Well… no.”</p>
<p>The manager: “I’m the one deciding, you are only the mindless developer coding the stuff I ask so shut up.” (OK, maybe not that part)</p>
<p>Well anyway, <a hreflang="en" href="http://nosql-database.org/" onclick="pageTracker._trackPageview('/outgoing/nosql-database.org/?referer=');">NoSQL</a> is a good idea to make sure that people know that we have choices on how we store data and that there are some ways better for some kind of tasks and others ways better for other kind of tasks.</p>
<h5>Mozmill (<a hreflang="en" href="http://www.hskupin.info/" onclick="pageTracker._trackPageview('/outgoing/www.hskupin.info/?referer=');">Henrik Skupin</a>)</h5>
<p>A quick presentation of <a hreflang="en" href="http://quality.mozilla.org/projects/mozmill" onclick="pageTracker._trackPageview('/outgoing/quality.mozilla.org/projects/mozmill?referer=');">Mozmill</a>, a tool used to do automated functional tests on Mozilla products (Firefox, <a hreflang="en" href="http://en.wikipedia.org/wiki/Mozilla_Thunderbird" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Mozilla_Thunderbird?referer=');">Thunderbird</a>). Each version of Firefox in fact 225 versions of Firefox (75 languages on 3 platforms) and all of them should/need to be tested. It looks like at Mozilla they are not really in the <a hreflang="en" href="http://en.wikipedia.org/wiki/Test-driven_development" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Test-driven_development?referer=');">test driven</a> mindset (yet), and they are lacking of tests. Wait sorry, when I say tests, I always think “automated tests”, it’s inhuman to make a person run a test suite manually, unfortunately to many people are paid for that. From what I understood they have some manual test suites for Firefox and fortunately they are trying to automate them.</p>
<p>You can see the mozmill generated reports for Firefox here: <a href="http://brasstacks.mozilla.com/couchdb/mozmill/_design/reports/_list/summary/summary" onclick="pageTracker._trackPageview('/outgoing/brasstacks.mozilla.com/couchdb/mozmill/_design/reports/_list/summary/summary?referer=');">http://brasstacks.mozilla.com/couchdb/mozmill/_design/reports/_list/summary/summary</a></p>
<h5>Towards GNUstep GUI 1.0 (Fred Kiefer)</h5>
<p><a hreflang="en" href="http://en.wikipedia.org/wiki/GNUstep" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/GNUstep?referer=');">GNUstep</a> has been in development for ages and there is still no 1.0 version. So the question was “do we need to do one and if yes, what needs to be in”. Obviously, the answer for the first part is “yes” (so it will attract more developers, <a hreflang="en" href="http://en.wikipedia.org/wiki/*BSD" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/_BSD?referer=');">*BSD</a> and <a hreflang="en" href="http://en.wikipedia.org/wiki/Linux_distribution" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Linux_distribution?referer=');">Linux distributions</a> will update their packages…). The second part of the question was not really solved. One proposition was to name the version 10.2 and has complete support of <a hreflang="en" href="http://en.wikipedia.org/wiki/Cocoa_%28API%29" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Cocoa_28API_29?referer=');">Cocoa</a> 10.2.</p>
<h5>L20n (<a hreflang="en" href="http://blog.mozilla.com/axel/" onclick="pageTracker._trackPageview('/outgoing/blog.mozilla.com/axel/?referer=');">Axel Hecht</a>)</h5>
<p>I’m not a specialist of <a hreflang="en" href="http://en.wikipedia.org/wiki/I18n" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/I18n?referer=');">internationalization (i18n) and localization (l10n)</a>, I know some issues regarding that but quite frankly, I didn’t really understood the presentation. It’s a bit more clear after a look on the <a hreflang="en" href="https://wiki.mozilla.org/L20n" onclick="pageTracker._trackPageview('/outgoing/wiki.mozilla.org/L20n?referer=');">l20n wiki</a>. Sounds interesting to me since I think that the current way of doing (key/value) sucks a lot as soon as you have some non ultra-trivial stuff to do.</p>
<h5><a hreflang="en" href="http://etoileos.com/" onclick="pageTracker._trackPageview('/outgoing/etoileos.com/?referer=');">Étoilé</a>: Where it is, where it’s going, why it isn’t there yet (Quentin Mathé/David Chisnall)</h5>
<p>What have they done since the beginning in 2004? This is a project with few people but lots of ideas. One thing I find interesting is the CoreObject framework. Well in fact not the framework, but the ideas behind. From a user point of view, having to save your documents sucks. Why the default state is “in case of problem you are going to lose all your unsaved work” and not “in case of problem all your work is saved”? So here the idea is everything you change on your document is recorded, so you can do/undo/redo modification, close your document, open it again, ask to undo stuff you have done before the history of your changes on the document have been saved all along.</p>
<p>Such ideas are not new, we have been talking about that for decades (well, not me, I’m talking about it only for years, I’m not that old <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ), but mainstream <a hreflang="en" href="http://en.wikipedia.org/wiki/Operating_system" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Operating_system?referer=');">operating system</a>s are still not implementing it.</p>
<h5>Women and Mozilla (<a href="http://blog.lebedel.net/" onclick="pageTracker._trackPageview('/outgoing/blog.lebedel.net/?referer=');">Delphine Lebédel</a>)</h5>
<p>Quick presentation of <a hreflang="en" href="http://www.womoz.org/blog/" onclick="pageTracker._trackPageview('/outgoing/www.womoz.org/blog/?referer=');">WoMoz</a>.</p>
<h5><a hreflang="en" href="http://en.wikipedia.org/wiki/NEPOMUK_%28framework%29" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/NEPOMUK_28framework_29?referer=');">Nepomuk</a> (<a hreflang="en" href="http://trueg.wordpress.com/" onclick="pageTracker._trackPageview('/outgoing/trueg.wordpress.com/?referer=');">Sebastian Trüg</a>)</h5>
<p>Recent operating systems are now indexing datas so it’s fast and easy to search for stuff on your computer. <a hreflang="en" href="http://nepomuk.semanticdesktop.org/" onclick="pageTracker._trackPageview('/outgoing/nepomuk.semanticdesktop.org/?referer=');">Nepomuk</a> is a “semantic” way of doing so (using RDF and so on).</p>
<p>Several functionalities are similar between Nepomuk and what I think Étoilé’s CoreObject do. But Nepomuk is based on “standards” like <a hreflang="en" href="http://en.wikipedia.org/wiki/Resource_Description_Framework" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Resource_Description_Framework?referer=');">RDF</a> and <a hreflang="en" href="http://en.wikipedia.org/wiki/SPARQL" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/SPARQL?referer=');">SPARQL</a>.</p>
<h5>Mozilla Panel Discussion (Mitchell Baker/Tristan Nitot/<a hreflang="en" href="http://commonspace.wordpress.com/" onclick="pageTracker._trackPageview('/outgoing/commonspace.wordpress.com/?referer=');">Mark Surman</a>)</h5>
<p>A discussion on Mozilla’s mission. Lots of questions about privacy. I confirm, Mozilla’s people have the right mindset (at least the mindset I like) and I’m glad that they are caring about the Internet.</p>
<h5>Write and Submit your first <a hreflang="en" href="http://en.wikipedia.org/wiki/Linux_kernel" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Linux_kernel?referer=');">Linux kernel</a> Patch (<a hreflang="en" href="http://en.wikipedia.org/wiki/Greg_Kroah-Hartman" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Greg_Kroah-Hartman?referer=');">Greg Kroah-Hartman</a>)</h5>
<p>A live example on what you need to do and how to do a patch for the Linux kernel.</p>
<h5>That’s all</h5>
<p>There are several presentations I would like to went to but we still have not invented a device giving us ubiquity.</p>
<p>I now have a lot more thinks to thing about, I may write down some of my thoughts here soon.</p>
<p>Anyway, a big thank you to the FOSDEM staff for organizing all that, to all the speakers and finally to all the people attending the event.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2010/02/08/post-fosdem-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FOSDEM 2010</title>
		<link>http://blog.desgrange.net/2010/02/03/fosdem-2010/</link>
		<comments>http://blog.desgrange.net/2010/02/03/fosdem-2010/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 07:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Belgium]]></category>
		<category><![CDATA[Brussels]]></category>
		<category><![CDATA[FOSDEM]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=706</guid>
		<description><![CDATA[FOSDEM (Free and Open Source Software Developers’ European Meeting) 2010 is happening this week-end (6-7 february) in… Brussels! At ULB, about 10 minutes by foot from home. So guess what? I never had the opportunity to assist FOSDEM before, so this time I’m not going to miss it. I haven’t look at the planning seriously [...]]]></description>
			<content:encoded><![CDATA[<p>FOSDEM (Free and Open Source Software Developers’ European Meeting) 2010 is happening this week-end (6-7 february) in… Brussels! At ULB, about 10 minutes by foot from home. So guess what?</p>
<p><a href="http://blog.desgrange.net/wp-content/uploads/2010/02/fosdem-2010-going-to.png"><img class="aligncenter size-full wp-image-1047" title="fosdem-2010-going-to" src="http://blog.desgrange.net/wp-content/uploads/2010/02/fosdem-2010-going-to.png" alt="" width="150" height="89" /></a></p>
<p>I never had the opportunity to assist FOSDEM before, so this time I’m not going to miss it.</p>
<p>I haven’t look at the planning seriously yet, there is a huge amount of stuff going on there, it’s going hard to make choices. At least I have seen that <a hreflang="en" href="http://en.wikipedia.org/wiki/Mozilla_Foundation" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Mozilla_Foundation?referer=');">Mozilla</a> is presenting some stuff, I hope I will be able to see <a href="http://standblog.org/blog/" onclick="pageTracker._trackPageview('/outgoing/standblog.org/blog/?referer=');">Tristan</a> at last (though I’m not sure it’s really fulfilling to listen to someone I always agree with (well, I’ve been reading his blog for several years now and I don’t really remember not agreeing on something)).</p>
<p>This reminds me I should find a way to start sharing with the community. I have been using open source softwares for years, on my day to day work, what frustrates me the most is each time I’m struggling with proprietary softwares (which I tend to avoid) while I know that the same problem with an open source software would have been solved much more easier (because of the help of the community and the availability of the source code).</p>
<p>So, are you coming?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2010/02/03/fosdem-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CITCON Paris 2009: Mock objects</title>
		<link>http://blog.desgrange.net/2009/10/12/citcon-paris-2009-mock-objects/</link>
		<comments>http://blog.desgrange.net/2009/10/12/citcon-paris-2009-mock-objects/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 22:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CITCON]]></category>
		<category><![CDATA[Paris]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=689</guid>
		<description><![CDATA[Interfaces During the session on mock objects there was a digression about interfaces. I have seen too often interfaces in a way that I don’t like. I will use the same example as Eric: Let’s say that you have a FileManager, providing some services to manage files I suppose , you may have an interface [...]]]></description>
			<content:encoded><![CDATA[<h5>Interfaces</h5>
<p>During the session on mock objects there was a digression about <a hreflang="en" href="http://en.wikipedia.org/wiki/Interface_%28computer_science%29" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Interface_28computer_science_29?referer=');">interfaces</a>. I have seen too often interfaces in a way that I don’t like. I will use the <a hreflang="en" href="http://ericlefevre.net/wordpress/2009/09/21/mock-objects-at-citcon-paris-2009/" onclick="pageTracker._trackPageview('/outgoing/ericlefevre.net/wordpress/2009/09/21/mock-objects-at-citcon-paris-2009/?referer=');">same example as Eric</a>:</p>
<p>Let’s say that you have a <code>FileManager</code>, providing some services to manage files I suppose <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> , you may have an interface called <code>IFileManager</code>. And usually there is only one implementation of <code>IFileManager</code> which is <code>FileManager</code>.</p>
<p>I think this is wrong for at least two reasons:</p>
<ul>
<li>Usefulness. If there is only one implementation, why do you need an interface?</li>
<li>Naming. The interface name should represent the “role”, so <code>FileManager</code> is suitable for the interface name, <code>IFileManager</code> has no meaning. Then the implementation should reflect what kind of implementation you have, like <code>LocalFileManager</code>, <code>DistributedFileManager</code> or a <code>DummyFileManager</code> for your tests (but not an ugly <code>FileManagerImpl</code>).</li>
</ul>
<p>So usually, when I see a software with that kind one 1 to 1 relationship between interface and implementation and using bad names, it raises a warning light in my head, telling me that the person who wrote that code did not really now what he was doing (only applying some old and bad coding rules without trying to understand why it was useful for). As <a hreflang="en" href="http://ericlefevre.net/wordpress/2009/09/21/mock-objects-at-citcon-paris-2009/#comments" onclick="pageTracker._trackPageview('/outgoing/ericlefevre.net/wordpress/2009/09/21/mock-objects-at-citcon-paris-2009/_comments?referer=');">Antonio says</a>, prefix ‘I’ for interface and suffix ‘Impl’ for implementations are signs of code smell.</p>
<p>I even have seen some interfaces with only one or two methods, the implementation had a lot more methods… and the concrete class was directly used in other classes… so yes, very useful interface :-/.</p>
<p>Sometimes, when writing tests, I need to mock some classes that I haven’t defined any interface for… and since several mock libraries are able to mock concrete classes I still not extract any interface.</p>
<p>I like simple classes, with simple roles, so mostly all public methods (except constructor and setters) are the “implied” interface.</p>
<p>So my point on interfaces is “use an interface only when you really need it” (that reminds me <a hreflang="en" href="http://en.wikipedia.org/wiki/YAGNI" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/YAGNI?referer=');">YAGNI</a>):</p>
<ul>
<li>when you need several implementations of a given “role”,</li>
<li>when defining some “ability” (sorry I don’t find the right term) like <code>Clonable</code>, <code>Closable</code>, <code>Comprable</code>, <code>Serializable</code>, <code>Anything-able</code> (if you can add “able” at the end, it’s a good sign that you might be able to extract an interface for that <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).</li>
</ul>
<h5>Mock objects</h5>
<p>So yes, we also spoke about <a hreflang="en" href="http://en.wikipedia.org/wiki/Mock_object" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Mock_object?referer=');">mock objects</a>. <a hreflang="en" href="http://www.m3p.co.uk/blog/" onclick="pageTracker._trackPageview('/outgoing/www.m3p.co.uk/blog/?referer=');">Steve Freeman</a> was trying to explain us some stuff, I have the feeling that there was something in his speech that was enlightening but I didn’t really get it (that’s why it’s only a feeling for the moment).</p>
<p>What I remember is that, when writing tests:</p>
<ul>
<li>mock the collaborating classes that change the outside world,</li>
<li>use stubs, dummy implementations, etc. otherwise.</li>
</ul>
<p>I don’t fully understand the reason yet. But something I learn recently and that was says during the session: mock only the code you own, don’t mock external resources.</p>
<p>So for instance, if you have a <code>Customer</code> object, a table full of customers in your database, don’t try to mock JDBC classes like <code>Connection</code>, <code>ResultSet</code> and so on. Create a class accessing the data, let say <code>CustomerDAO</code> (I don’t like the name, but hey, it’s only an example), and then you can mock your <code>CustomerDAO</code> in your software.</p>
<p>I imagine that CustomerDAO will then be tested in integration tests (it’s a class using external software/server/stuff right? Can’t really unit test it (except maybe some data storage specific logic I may have to write in it)).</p>
<p>Anyway, it was an interesting session.</p>
<h5>Misc</h5>
<p>Books recommended during the session:</p>
<ul>
<li><a hreflang="en" href="http://www.growing-object-oriented-software.com/" onclick="pageTracker._trackPageview('/outgoing/www.growing-object-oriented-software.com/?referer=');">Growing object-oriented software guided by tests</a> by Steve Freeman and Nat Pryce.</li>
<li><a hreflang="en" href="http://www.amazon.fr/exec/obidos/ASIN/0201379430" onclick="pageTracker._trackPageview('/outgoing/www.amazon.fr/exec/obidos/ASIN/0201379430?referer=');">Object design</a> by Rebecca Wirfs-Brock and Alan McKean.</li>
<li><a hreflang="en" href="http://www.amazon.fr/exec/obidos/ASIN/0131495054" onclick="pageTracker._trackPageview('/outgoing/www.amazon.fr/exec/obidos/ASIN/0131495054?referer=');">xUnit test patterns</a> by Gerard Meszaros.</li>
</ul>
<p>Frameworks:</p>
<ul>
<li><a hreflang="en" href="http://www.jmock.org" onclick="pageTracker._trackPageview('/outgoing/www.jmock.org?referer=');">jMock</a> (the framework I usually use)</li>
<li><a hreflang="en" href="http://easymock.org/" onclick="pageTracker._trackPageview('/outgoing/easymock.org/?referer=');">EasyMock</a></li>
<li><a hreflang="en" href="http://mockito.org/" onclick="pageTracker._trackPageview('/outgoing/mockito.org/?referer=');">Mockito</a> (more recent, I started using it a bit at work a week ago, looks quite nice)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2009/10/12/citcon-paris-2009-mock-objects/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java Black Belt</title>
		<link>http://blog.desgrange.net/2009/05/18/java-black-belt/</link>
		<comments>http://blog.desgrange.net/2009/05/18/java-black-belt/#comments</comments>
		<pubDate>Mon, 18 May 2009 22:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=668</guid>
		<description><![CDATA[Java Black Belt is a community website aiming at &#8220;building better developers&#8220;. Given the name, it&#8217;s targeting mainly Java developers but some exams cover Ruby, .NET C#… Every user has a belt like in karate, the color (from white to black) represents user&#8217;s knowledge of Java, common frameworks, tools To get next belt you need [...]]]></description>
			<content:encoded><![CDATA[<p><a hreflang="en" href="http://www.javablackbelt.com" onclick="pageTracker._trackPageview('/outgoing/www.javablackbelt.com?referer=');">Java Black Belt</a> is a community website aiming at &#8220;building better <a hreflang="en" href="http://en.wikipedia.org/wiki/Software_developer" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Software_developer?referer=');">developers</a>&#8220;. Given the name, it&#8217;s targeting mainly <a hreflang="en" href="http://en.wikipedia.org/wiki/Java_(programming_language)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Java_programming_language?referer=');">Java</a> developers but some exams cover <a hreflang="en" href="http://en.wikipedia.org/wiki/Ruby_(programming_language)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Ruby_programming_language?referer=');">Ruby</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/C_Sharp_programming_language?referer=');">.NET C#</a>…</p>
<p>Every user has a <a hreflang="en" href="http://en.wikipedia.org/wiki/Black_belt_(martial_arts)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Black_belt_martial_arts?referer=');">belt</a> like in <a hreflang="en" href="http://en.wikipedia.org/wiki/Karate" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Karate?referer=');">karate</a>, the color (from white to black) represents user&#8217;s knowledge of <a hreflang="en" href="http://java.sun.com/" onclick="pageTracker._trackPageview('/outgoing/java.sun.com/?referer=');">Java</a>, common <a hreflang="en" href="http://en.wikipedia.org/wiki/Software_framework" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Software_framework?referer=');">frameworks</a>, tools To get next belt you need to pass some specific exams and have a certain amount of knowledge points.</p>
<p>You get knowledge points by passing exams. An exam is usually a list of multiple choices questions, you need a certain amount of good answers to pass the test (around 80 % successful answers). If you fail an exam you need to wait some time before trying it again (around 15 days).</p>
<p>To get an exam you need some contribution points (except if you decide to follow the &#8220;Belt Track&#8221;, doing the exams in a predefined order). Contribution points are obtained when writing a question, reporting problems on a question, etc. So all the questions are created by the community, voted by the users (to have them accepted or rejected).</p>
<p>Since I mostly didn&#8217;t write anything in Java for a year and a half, I need to train myself a bit before taking an exam (I don&#8217;t really want to be forced to wait 15 days before trying an exam again).</p>
<p>So basically the website (until the black belt) is just checking your knowledge of Java and does not check if you are really able to write good code. In order to check that, the exam to get the black belt IS a programming task, but it&#8217;s not yet released (so nobody as a black belt yet).</p>
<p>One drawback I see is that several questions are useless. Since there is no point using Java without a proper <a hreflang="en" href="http://en.wikipedia.org/wiki/Integrated_development_environment" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Integrated_development_environment?referer=');">IDE</a> (as one of my colleagues says: &#8220;The power of Java is <a hreflang="en" href="http://en.wikipedia.org/wiki/IntelliJ" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/IntelliJ?referer=');">IntelliJ</a>.&#8221;), questions about knowing by heart all the details of Java <a hreflang="en" href="http://en.wikipedia.org/wiki/API" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/API?referer=');">APIs</a>, questions like &#8220;Does the following program compile?&#8221; are meaningless.</p>
<p>During my (short) career, I was interviewed several times and I interviewed several people. Quite often there are some technical questions to be sure that the interviewee knows a bit of Java, so sometimes I was asking questions like the ones found on Java Black Belt. Seeing the belt somebody obtained on this website will reduce the number of technical questions I have to ask, Java Black Belt already did it.</p>
<p>But in fact, if I need somebody in the team I&#8217;m working in, Java Black Belt is not enough. Of course it&#8217;s a hint about is knowledge, but it does not tell me how the guy works. But at least I have more time in the interview to ask those questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2009/05/18/java-black-belt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do developers need to work on fast or slow computers?</title>
		<link>http://blog.desgrange.net/2009/01/19/do-developers-need-to-work-on-fast-or-slow-computers/</link>
		<comments>http://blog.desgrange.net/2009/01/19/do-developers-need-to-work-on-fast-or-slow-computers/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 22:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=639</guid>
		<description><![CDATA[From time to time I see this question happening. When a developer is writing a software, does he need a fast or a slow computer? Why working on a slow computer? If a developer works on a slow computer, he tends to be careful about how fast is running the code he is writing. So [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time I see this question happening. When a developer is writing a software, does he need a fast or a slow computer?</p>
<p>Why working on a slow computer?</p>
<ul>
<li>If a developer works on a slow computer, he tends to be careful about how fast is running the code he is writing. So the produced software is fast and is more testable on the developers computer.</li>
</ul>
<p>Why working on a fast computer?</p>
<ul>
<li>The developer can open all resources he needs without having to care about closing some softwares because the computer does not handle the load (I remember a colleague having 2 internet explorer opened, 3 firefox with 15 tabs opened in each of them, 3 intellij, a webserver and a database running all together on his computer).</li>
<li>A slow computer may not be the same as having the product working under heavy load.</li>
<li>The tools the developer is using may not be &#8220;optimized&#8221; and are running slowly on slow computer or computer without much memory. In general, everything is slow and increase the waiting time of the developer.</li>
<li>In case of failure/delay the developer can&#8217;t use the argument of having a slow computer <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</li>
</ul>
<p>When writing a software, what&#8217;s important for a lot of developers is the time for compile/run/test cycle. Shorter is it, faster the developer can see the result of its work and have feedback on it. On a slow computer, this cycle is longer, the developer tends to write more code before seeing if it works, in case of test failure, the modifications may be too important to easily find out what&#8217;s wrong, leading to a big loss of time.</p>
<p>Depending on the technologies you are working on, tools may exist to distribute some computation like compiling on computers available on your network (hoping that other developers are not compiling at the same time too). But compiling may not be the longest task. I work on a project where compile time was mostly nonexistent (everything was compiled on the fly), running 700 unit tests took around 5 seconds, running 200 functional tests took around 5 minutes. We didn&#8217;t have the fastest computers but they where fast enough. Here the functional tests were taking most of the time, I think writing them so they could be distributed on other available computers would have been a bit more complicated and may have taken too much effort (the environment was not designed to be distributed). And distributing the functional tests would have completely remove the point of seeing how well worked the system under load.</p>
<p>So to me, giving a powerful computer to developers is not a big cost and may make their job easier. If you need to check how your software behave under load or in restricted environment (slow CPU, small memory), make appropriate tests (if this is a requirement, tests must have been written to check it).</p>
<p>I think the real problem about writing a fat and slow software is because having a small fast one is quite often not a requirement (you are still doing the same things with the last version of Microsoft Word on Windows Vista than what you were doing with your old Word on Windows 95, you just need a far more powerful computer now). Most of us works for companies where the goal is selling products/licensees and they need more and more features to be sold. Selling a new version having only &#8220;faster and smaller footprint&#8221; is not enough for the marketing guys, even more, it&#8217;s recognizing that the previous version were fat and slow (I know it&#8217;s dumb, but that&#8217;s what I have seen sometimes (depending in what kind of industries you are working in)).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2009/01/19/do-developers-need-to-work-on-fast-or-slow-computers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exceptions in Erlang</title>
		<link>http://blog.desgrange.net/2009/01/05/exceptions-in-erlang/</link>
		<comments>http://blog.desgrange.net/2009/01/05/exceptions-in-erlang/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 22:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=640</guid>
		<description><![CDATA[Exception In a programming language, an exception is something that could be generated when the system is behaving outside the normal execution path. An exception is mostly an error. In lots of programming languages, developers use exceptions as a meaningful information to do something or not. For example, while reading a file, an exception can [...]]]></description>
			<content:encoded><![CDATA[<h4>Exception</h4>
<p>In a <a hreflang="en" href="http://en.wikipedia.org/wiki/Programming_language" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Programming_language?referer=');">programming language</a>, an <a hreflang="en" href="http://en.wikipedia.org/wiki/Exception_handling" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Exception_handling?referer=');">exception</a> is something that could be generated when the system is behaving outside the normal execution path. An exception is mostly an error. In lots of programming languages, developers use exceptions as a meaningful information to do something or not.</p>
<p>For example, while reading a file, an exception can be generated because the file does not exists. The developer may choose to catch the exception and display a popup to ask the user to choose an other file, or the developer may not catch the exception because the file must have been there and if it&#8217;s not there it&#8217;s because something wrong is happening but the developer has no clue about what to do, so the best solution is to let the system crash (as opposed to try to do something and maybe enter in an inconsistent state).</p>
<h4>Exceptions in Erlang</h4>
<p>In <a hreflang="en" href="http://en.wikipedia.org/wiki/Erlang_(programming_language)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Erlang_programming_language?referer=');">Erlang</a> there are exceptions too.</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">exceptions.erl</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="erlang" style="font-family:monospace;"><span class="sy3">-</span><span class="re2">module</span><span class="br0">&#40;</span>exceptions<span class="br0">&#41;</span><span class="sy1">.</span>
<span class="sy3">-</span><span class="re2">compile</span><span class="br0">&#40;</span><span class="br0">&#91;</span>export_all<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">.</span>
&nbsp;
<span class="re3">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Test exception 1 starting...~n&quot;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re3">exception1</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Test exception 1 finished.~n&quot;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    ok<span class="sy1">.</span>
&nbsp;
<span class="re3">exception1</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
  <a href="http://erlang.org/doc/man/erlang.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/erlang.html?referer=');"><span class="kw5">erlang</span></a>:<span class="re3">foo</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy1">.</span></pre></div></div>
<p>Running the <a hreflang="en" href="http://en.wikipedia.org/wiki/Function_(computer_science)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Function_computer_science?referer=');">function</a> <code>run</code> will run <code>exception1</code> which throws an exception (the function <code>foo</code> does not exist in module <code>erlang</code>) and is not catched by <code>run</code> (so the second <code>fwrite</code> is not displayed):</p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">$ erl -s exceptions run
Erlang (BEAM) emulator version 5.6.2 [source] [smp:2] [async-threads:0] [kernel-poll:false]
&nbsp;
Test exception 1 starting...
{&quot;init terminating in do_boot&quot;,{undef,[{erlang,foo,[]},{exceptions,run,0},{init,start_it,1},{init,start_em,1}]}}
&nbsp;
Crash dump was written to: erl_crash.dump
init terminating in do_boot ()</pre></div></div>
<h5>Types of exceptions</h5>
<p>In <a hreflang="en" href="http://www.erlang.org/" onclick="pageTracker._trackPageview('/outgoing/www.erlang.org/?referer=');">Erlang</a> there are 3 kinds of exceptions that can be generated:</p>
<ul>
<li>normal exceptions, user generated (<code>throw(Reason)</code>)</li>
<li>errors, something is going really wrong, should not be catched (<code>erlang:error(Reason)</code>)</li>
<li>exit, used to terminate current process (<code>exit(Reason)</code>)</li>
</ul>
<h5>Catching an exception</h5>
<ul>
<li>Catching an exception with <code>catch</code>:</li>
</ul>
<div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="erlang" style="font-family:monospace;"><span class="re3">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Test exception 1 starting...~n&quot;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re5">Result</span> <span class="sy3">=</span> <span class="br0">&#40;</span><span class="kw1">catch</span> <a href="http://erlang.org/doc/man/erlang.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/erlang.html?referer=');"><span class="kw5">erlang</span></a>:<span class="re3">foo</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Test exception 1 finished: ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Result</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    ok<span class="sy1">.</span></pre></div></div>
<p>Calling <code>run</code> displays:</p>
<div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">Erlang (BEAM) emulator version 5.6.2 [source] [smp:2] [async-threads:0] [kernel-poll:false]
&nbsp;
Test exception 1 starting...
Test exception 1 finished: {'EXIT',
                               {undef,
                                   [{erlang,foo,[]},
                                    {exceptions,run,0},
                                    {init,start_it,1},
                                    {init,start_em,1}]}}</pre></div></div>
<p>and the process is still alive.</p>
<ul>
<li>Catching an exception with <code>try  catch</code>. The full syntax is something like this:</li>
</ul>
<div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;"><pre class="erlang" style="font-family:monospace;"><span class="kw1">try</span> <a href="http://erlang.org/doc/man/erlang.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/erlang.html?referer=');"><span class="kw5">erlang</span></a>:<span class="re3">foo</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">of</span>
	<span class="re5">Any</span> <span class="sy1">-&gt;</span>
	    <span class="re5">Any</span>
    <span class="kw1">catch</span>
	error:<span class="me2">Reason</span> <span class="sy1">-&gt;</span>
	    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Error reason: ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Reason</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">;</span>
	throw:<span class="me2">Reason</span> <span class="sy1">-&gt;</span>
	    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Throw reason: ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Reason</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">;</span>
	exit:<span class="me2">Reason</span> <span class="sy1">-&gt;</span>
	    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Exit reason: ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Reason</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
    <span class="kw1">after</span>
	<a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Doing some stuff no matter what happened.~n&quot;</span><span class="br0">&#41;</span>
    <span class="kw1">end</span><span class="sy1">.</span></pre></div></div>
<p><code>try</code> executes the given function and return it&#8217;s value (which can be pattern matched) if everything&#8217;s OK, if an exception is generated it goes in the the matching <code>catch</code> clause. In any case, it then goes inside the <code>after</code> block (similar to <code>finally</code> in <a hreflang="en" href="http://en.wikipedia.org/wiki/Java_(programming_language)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Java_programming_language?referer=');">Java</a>).</p>
<p>Running the previous code output:</p>
<div id="wpshdo_13" class="wp-synhighlighter-outer"><div id="wpshdt_13" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_13"></a><a id="wpshat_13" class="wp-synhighlighter-title" href="#codesyntax_13"  onClick="javascript:wpsh_toggleBlock(13)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_13" onClick="javascript:wpsh_code(13)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_13" onClick="javascript:wpsh_print(13)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_13" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">Error reason: undef
Doing some stuff no matter what happened.</pre></div></div>
<p>(Calling a function that does not exists throws an <code>error</code>)</p>
<p>As everything in Erlang, <code>try  catch</code> returns a value (the executed function, the return the matching clause or the return of the matching exception clause).</p>
<h5>Examples</h5>
<p>Let see more examples.</p>
<div id="wpshdo_14" class="wp-synhighlighter-outer"><div id="wpshdt_14" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_14"></a><a id="wpshat_14" class="wp-synhighlighter-title" href="#codesyntax_14"  onClick="javascript:wpsh_toggleBlock(14)" title="Click to show/hide code block">exceptions.erl</a></td><td align="right"><a href="#codesyntax_14" onClick="javascript:wpsh_code(14)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_14" onClick="javascript:wpsh_print(14)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_14" class="wp-synhighlighter-inner" style="display: block;"><pre class="erlang" style="font-family:monospace;"><span class="sy3">-</span><span class="re2">module</span><span class="br0">&#40;</span>exceptions<span class="br0">&#41;</span><span class="sy1">.</span>
<span class="sy3">-</span><span class="re2">compile</span><span class="br0">&#40;</span><span class="br0">&#91;</span>export_all<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">.</span>
&nbsp;
<span class="re3">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="re3">run</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="sy1">,</span> no_exception<span class="sy1">,</span> <span class="st_h">'catch'</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re3">run</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="sy1">,</span> no_exception<span class="sy1">,</span> <span class="st_h">'try'</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re3">run</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="sy1">,</span> <span class="st_h">'throw'</span><span class="sy1">,</span> <span class="st_h">'catch'</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re3">run</span><span class="br0">&#40;</span><span class="nu0">4</span><span class="sy1">,</span> <span class="st_h">'throw'</span><span class="sy1">,</span> <span class="st_h">'try'</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re3">run</span><span class="br0">&#40;</span><span class="nu0">5</span><span class="sy1">,</span> <span class="st_h">'exit'</span><span class="sy1">,</span> <span class="st_h">'catch'</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re3">run</span><span class="br0">&#40;</span><span class="nu0">6</span><span class="sy1">,</span> <span class="st_h">'exit'</span><span class="sy1">,</span> <span class="st_h">'try'</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re3">run</span><span class="br0">&#40;</span><span class="nu0">7</span><span class="sy1">,</span> <span class="st_h">'error'</span><span class="sy1">,</span> <span class="st_h">'catch'</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re3">run</span><span class="br0">&#40;</span><span class="nu0">8</span><span class="sy1">,</span> <span class="st_h">'error'</span><span class="sy1">,</span> <span class="st_h">'try'</span><span class="br0">&#41;</span><span class="sy1">,</span>
    ok<span class="sy1">.</span>
&nbsp;
<span class="re3">run</span><span class="br0">&#40;</span><span class="re5">ID</span><span class="sy1">,</span> <span class="re5">Exception_type</span><span class="sy1">,</span> <span class="re5">Handling_type</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;~p) Generating ~p, handled with ~p.~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">ID</span><span class="sy1">,</span> <span class="re5">Exception_type</span><span class="sy1">,</span> <span class="re5">Handling_type</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re5">Fun</span> <span class="sy3">=</span> <span class="kw1">fun</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span> <span class="re3">exception</span><span class="br0">&#40;</span><span class="re5">Exception_type</span><span class="br0">&#41;</span> <span class="kw1">end</span><span class="sy1">,</span>
    <span class="re5">Result</span> <span class="sy3">=</span> <span class="re3">execute</span><span class="br0">&#40;</span><span class="re5">Handling_type</span><span class="sy1">,</span> <span class="re5">Fun</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;~p) Result: ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">ID</span><span class="sy1">,</span> <span class="re5">Result</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">.</span>
&nbsp;
<span class="re3">exception</span><span class="br0">&#40;</span>no_exception<span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="me1">ok</span><span class="sy1">;</span>
<span class="re3">exception</span><span class="br0">&#40;</span><span class="st_h">'throw'</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="kw3">throw</span><span class="br0">&#40;</span><span class="st0">&quot;Throwed exception&quot;</span><span class="br0">&#41;</span><span class="sy1">;</span>
<span class="re3">exception</span><span class="br0">&#40;</span><span class="st_h">'exit'</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="kw3">exit</span><span class="br0">&#40;</span><span class="st0">&quot;Exited&quot;</span><span class="br0">&#41;</span><span class="sy1">;</span>
<span class="re3">exception</span><span class="br0">&#40;</span><span class="st_h">'error'</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <a href="http://erlang.org/doc/man/erlang.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/erlang.html?referer=');"><span class="kw5">erlang</span></a>:<span class="re3">error</span><span class="br0">&#40;</span><span class="st0">&quot;Error generated&quot;</span><span class="br0">&#41;</span><span class="sy1">.</span>
&nbsp;
<span class="re3">execute</span><span class="br0">&#40;</span><span class="st_h">'catch'</span><span class="sy1">,</span> <span class="re5">Fun</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="br0">&#40;</span><span class="kw1">catch</span> <span class="re5">F</span><span class="re3">un</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy1">;</span>
<span class="re3">execute</span><span class="br0">&#40;</span><span class="st_h">'try'</span><span class="sy1">,</span> <span class="re5">Fun</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="kw1">try</span> <span class="re5">F</span><span class="re3">un</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="kw1">catch</span>
	<span class="re5">Error</span>:<span class="me2">Reason</span> <span class="sy1">-&gt;</span>
	    <span class="br0">&#123;</span><span class="re5">Error</span><span class="sy1">,</span> <span class="re5">Reason</span><span class="br0">&#125;</span>
    <span class="kw1">end</span><span class="sy1">.</span></pre></div></div>
<p>Output:</p>
<div id="wpshdo_15" class="wp-synhighlighter-outer"><div id="wpshdt_15" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_15"></a><a id="wpshat_15" class="wp-synhighlighter-title" href="#codesyntax_15"  onClick="javascript:wpsh_toggleBlock(15)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_15" onClick="javascript:wpsh_code(15)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_15" onClick="javascript:wpsh_print(15)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_15" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">1) Generating no_exception, handled with 'catch'.
1) Result: ok
2) Generating no_exception, handled with 'try'.
2) Result: ok
3) Generating throw, handled with 'catch'.
3) Result: &quot;Throwed exception&quot;
4) Generating throw, handled with 'try'.
4) Result: {throw,&quot;Throwed exception&quot;}
5) Generating exit, handled with 'catch'.
5) Result: {'EXIT',&quot;Exited&quot;}
6) Generating exit, handled with 'try'.
6) Result: {exit,&quot;Exited&quot;}
7) Generating error, handled with 'catch'.
7) Result: {'EXIT',{&quot;Error generated&quot;,
                    [{exceptions,exception,1},
                     {exceptions,execute,2},
                     {exceptions,run,3},
                     {exceptions,run,0},
                     {init,start_it,1},
                     {init,start_em,1}]}}
8​) Generating error, handled with 'try'.
8​) Result: {error,&quot;Error generated&quot;}</pre></div></div>
<p>An interesting thing we can see here is that, in case of an <code>error</code>, <code>catch</code> get a stack trace which can be very useful for debugging but <code>try  catch</code> does not get it.</p>
<p>I prefer <code>try  catch</code> syntax (and it&#8217;s the recommended way to catch exceptions because you can choose what kind of exceptions you want to catch, <code>catch</code> catches everything) but it&#8217;s regrettable that it does not return the stack trace.</p>
<p>You can use <code>erlang:get_stacktrace</code> but it returns the stack trace from where you are calling it. If the exception is generated deep inside the function you are calling, <code>get_stacktrace</code> does not gives the root cause of the exception.</p>
<p>Having a stack trace is very useful but it make things a bit slower. I made a simple benchmark:</p>
<div id="wpshdo_16" class="wp-synhighlighter-outer"><div id="wpshdt_16" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_16"></a><a id="wpshat_16" class="wp-synhighlighter-title" href="#codesyntax_16"  onClick="javascript:wpsh_toggleBlock(16)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_16" onClick="javascript:wpsh_code(16)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_16" onClick="javascript:wpsh_print(16)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_16" class="wp-synhighlighter-inner" style="display: block;"><pre class="erlang" style="font-family:monospace;"><span class="re3">bench</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="re5">Throw_fun1</span> <span class="sy3">=</span> <span class="kw1">fun</span><span class="br0">&#40;</span><span class="re5">_</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span> <span class="br0">&#40;</span><span class="kw1">catch</span> <span class="re3">exception</span><span class="br0">&#40;</span><span class="st_h">'throw'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">end</span><span class="sy1">,</span>
    <span class="re5">Error_fun1</span> <span class="sy3">=</span> <span class="kw1">fun</span><span class="br0">&#40;</span><span class="re5">_</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span> <span class="br0">&#40;</span><span class="kw1">catch</span> <span class="re3">exception</span><span class="br0">&#40;</span><span class="st_h">'error'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">end</span><span class="sy1">,</span>
    <span class="re5">Throw_fun2</span> <span class="sy3">=</span> <span class="kw1">fun</span><span class="br0">&#40;</span><span class="re5">_</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span> <span class="kw1">try</span> <span class="re3">exception</span><span class="br0">&#40;</span><span class="st_h">'throw'</span><span class="br0">&#41;</span> <span class="kw1">catch</span> <span class="re5">Error</span>:<span class="me2">Reason</span> <span class="sy1">-&gt;</span> <span class="br0">&#123;</span><span class="re5">Error</span><span class="sy1">,</span> <span class="re5">Reason</span><span class="br0">&#125;</span> <span class="kw1">end</span> <span class="kw1">end</span><span class="sy1">,</span>
    <span class="re5">Error_fun2</span> <span class="sy3">=</span> <span class="kw1">fun</span><span class="br0">&#40;</span><span class="re5">_</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span> <span class="kw1">try</span> <span class="re3">exception</span><span class="br0">&#40;</span><span class="st_h">'error'</span><span class="br0">&#41;</span> <span class="kw1">catch</span> <span class="re5">Error</span>:<span class="me2">Reason</span> <span class="sy1">-&gt;</span> <span class="br0">&#123;</span><span class="re5">Error</span><span class="sy1">,</span> <span class="re5">Reason</span><span class="br0">&#125;</span> <span class="kw1">end</span> <span class="kw1">end</span><span class="sy1">,</span>
    <span class="re5">Seq</span> <span class="sy3">=</span> <a href="http://erlang.org/doc/man/lists.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/lists.html?referer=');"><span class="kw5">lists</span></a>:<span class="re3">seq</span><span class="br0">&#40;</span>1<span class="sy1">,</span> 100000<span class="br0">&#41;</span><span class="sy1">,</span>
    <a href="http://erlang.org/doc/man/timer.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/timer.html?referer=');"><span class="kw5">timer</span></a>:<span class="re3">sleep</span><span class="br0">&#40;</span>1000<span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="br0">&#123;</span><span class="re5">Time_throw1</span><span class="sy1">,</span> <span class="re5">_</span><span class="br0">&#125;</span> <span class="sy3">=</span> <a href="http://erlang.org/doc/man/timer.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/timer.html?referer=');"><span class="kw5">timer</span></a>:<span class="re3">tc</span><span class="br0">&#40;</span>lists<span class="sy1">,</span> foreach<span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Throw_fun1</span><span class="sy1">,</span> <span class="re5">Seq</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="br0">&#123;</span><span class="re5">Time_error1</span><span class="sy1">,</span> <span class="re5">_</span><span class="br0">&#125;</span> <span class="sy3">=</span> <a href="http://erlang.org/doc/man/timer.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/timer.html?referer=');"><span class="kw5">timer</span></a>:<span class="re3">tc</span><span class="br0">&#40;</span>lists<span class="sy1">,</span> foreach<span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Error_fun1</span><span class="sy1">,</span> <span class="re5">Seq</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="br0">&#123;</span><span class="re5">Time_throw2</span><span class="sy1">,</span> <span class="re5">_</span><span class="br0">&#125;</span> <span class="sy3">=</span> <a href="http://erlang.org/doc/man/timer.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/timer.html?referer=');"><span class="kw5">timer</span></a>:<span class="re3">tc</span><span class="br0">&#40;</span>lists<span class="sy1">,</span> foreach<span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Throw_fun2</span><span class="sy1">,</span> <span class="re5">Seq</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="br0">&#123;</span><span class="re5">Time_error2</span><span class="sy1">,</span> <span class="re5">_</span><span class="br0">&#125;</span> <span class="sy3">=</span> <a href="http://erlang.org/doc/man/timer.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/timer.html?referer=');"><span class="kw5">timer</span></a>:<span class="re3">tc</span><span class="br0">&#40;</span>lists<span class="sy1">,</span> foreach<span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Error_fun2</span><span class="sy1">,</span> <span class="re5">Seq</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Throw (catch): ~p micro seconds~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Time_throw1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Error (catch): ~p micro seconds~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Time_error1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Throw (try): ~p micro seconds~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Time_throw2</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Error (try): ~p micro seconds~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Time_error2</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
    ok<span class="sy1">.</span></pre></div></div>
<p>Results (for 100 000 calls):</p>
<div id="wpshdo_17" class="wp-synhighlighter-outer"><div id="wpshdt_17" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_17"></a><a id="wpshat_17" class="wp-synhighlighter-title" href="#codesyntax_17"  onClick="javascript:wpsh_toggleBlock(17)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_17" onClick="javascript:wpsh_code(17)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_17" onClick="javascript:wpsh_print(17)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_17" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">Throw (catch): 73920 micro seconds
Error (catch): 169576 micro seconds
Throw (try): 64118 micro seconds
Error (try): 63125 micro seconds</pre></div></div>
<p>Throwing an error or an exception take the same amount of time but using <code>catch</code> on an error is 2.5 times slower than using <code>try  catch</code> (my quick conclusion on that is because <code>catch</code> generates a stack trace).</p>
<p>I would like having only one way of catching exceptions (no <code>catch</code>, only <code>try  catch</code>) and a way to specify if I want a stack trace or not in case of error. Maybe something like this:</p>
<div id="wpshdo_18" class="wp-synhighlighter-outer"><div id="wpshdt_18" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_18"></a><a id="wpshat_18" class="wp-synhighlighter-title" href="#codesyntax_18"  onClick="javascript:wpsh_toggleBlock(18)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_18" onClick="javascript:wpsh_code(18)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_18" onClick="javascript:wpsh_print(18)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_18" class="wp-synhighlighter-inner" style="display: block;"><pre class="erlang" style="font-family:monospace;"><span class="kw1">try</span> <span class="re5">F</span><span class="re3">un</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="kw1">catch</span>
    <span class="re5">Error</span>:<span class="me2">Reason</span>:<span class="me2">Stack</span> <span class="sy1">-&gt;</span>
        <span class="br0">&#123;</span><span class="re5">Error</span>:<span class="me2">Reason</span>:<span class="me2">Stack</span><span class="br0">&#125;</span>
<span class="kw1">end</span><span class="sy1">.</span></pre></div></div>
<p>If a catch clause is waiting for 3 elements (<code>Error</code>, <code>Reason</code>, <code>Stack</code>), the compiler add the necessary stuff to call the <code>Fun</code> with a stack trace. If there are only 2 elements (<code>Error</code>, <code>Reason</code>), keep the actual behavior.</p>
<h5>Do we really need exceptions in Erlang?</h5>
<p>Exceptions may be useful but we can achieve the same goal in Erlang in other ways. Lots of functions have a signature like: <code>{ok, Value} | {error, Reason}</code>.</p>
<p>Those functions have different outputs between the normal case and the exceptional case. Combined with <code>case</code> we get the same behavior as catching an exception. If we don&#8217;t use <code>case</code>, we get a <code>badmatch</code> error.</p>
<div id="wpshdo_19" class="wp-synhighlighter-outer"><div id="wpshdt_19" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_19"></a><a id="wpshat_19" class="wp-synhighlighter-title" href="#codesyntax_19"  onClick="javascript:wpsh_toggleBlock(19)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_19" onClick="javascript:wpsh_code(19)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_19" onClick="javascript:wpsh_print(19)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_19" class="wp-synhighlighter-inner" style="display: block;"><pre class="erlang" style="font-family:monospace;"><span class="re3">case_way</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="re5">Fun</span> <span class="sy3">=</span> <span class="kw1">fun</span><span class="br0">&#40;</span>ok<span class="br0">&#41;</span> <span class="sy1">-&gt;</span> <span class="br0">&#123;</span>ok<span class="sy1">,</span> <span class="st0">&quot;It works&quot;</span><span class="br0">&#125;</span><span class="sy1">;</span>
	     <span class="br0">&#40;</span>nok<span class="br0">&#41;</span> <span class="sy1">-&gt;</span> <span class="br0">&#123;</span>error<span class="sy1">,</span> <span class="st0">&quot;It does not work&quot;</span><span class="br0">&#125;</span>
	  <span class="kw1">end</span><span class="sy1">,</span>
    <span class="re3">run_case</span><span class="br0">&#40;</span>1<span class="sy1">,</span> <span class="re5">Fun</span><span class="sy1">,</span> ok<span class="br0">&#41;</span><span class="sy1">,</span>
    <span class="re3">run_case</span><span class="br0">&#40;</span>2<span class="sy1">,</span> <span class="re5">Fun</span><span class="sy1">,</span> nok<span class="br0">&#41;</span><span class="sy1">,</span>
    ok<span class="sy1">.</span>
&nbsp;
<span class="re3">run_case</span><span class="br0">&#40;</span><span class="re5">ID</span><span class="sy1">,</span> <span class="re5">Fun</span><span class="sy1">,</span> <span class="re5">Arg</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="kw1">case</span> <span class="re5">F</span><span class="re3">un</span><span class="br0">&#40;</span><span class="re5">Arg</span><span class="br0">&#41;</span> <span class="kw1">of</span>
	<span class="br0">&#123;</span>error<span class="sy1">,</span> <span class="re5">Reason</span><span class="br0">&#125;</span> <span class="sy1">-&gt;</span>
	    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;~p) Error: ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">ID</span><span class="sy1">,</span> <span class="re5">Reason</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">;</span>
	<span class="br0">&#123;</span>ok<span class="sy1">,</span> <span class="re5">Value</span><span class="br0">&#125;</span> <span class="sy1">-&gt;</span>
	    <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;~p) Value: ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">ID</span><span class="sy1">,</span> <span class="re5">Value</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
    <span class="kw1">end</span><span class="sy1">.</span></pre></div></div>
<p>Running <code>case_way</code>:</p>
<div id="wpshdo_20" class="wp-synhighlighter-outer"><div id="wpshdt_20" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_20"></a><a id="wpshat_20" class="wp-synhighlighter-title" href="#codesyntax_20"  onClick="javascript:wpsh_toggleBlock(20)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_20" onClick="javascript:wpsh_code(20)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_20" onClick="javascript:wpsh_print(20)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_20" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">1) Value: &quot;It works&quot;
2) Error: &quot;It does not work&quot;</pre></div></div>
<p>Boons:</p>
<ul>
<li>Way much faster than exceptions (around 4 times faster according to my quick bench)</li>
<li>No specific syntax</li>
</ul>
<p>Banes:</p>
<ul>
<li>Normal case needs some encapsulation like <code>{ok, Value}</code> instead or returning <code>Value</code> directly (not doing so may lead to unknown states if the return is not pattern matched for errors)</li>
<li>No convention (you can return {exit, Type, Reason} if you want, or anything you want, developer needs to read carefully documentation of each function before using it)</li>
</ul>
<p>In <a hreflang="en" href="http://www.amazon.com/exec/obidos/ASIN/193435600X" onclick="pageTracker._trackPageview('/outgoing/www.amazon.com/exec/obidos/ASIN/193435600X?referer=');">Joe Armstrong&#8217;s book</a>, he says that usually people use <code>{error, Reason}</code> when an error occurs quite often and exceptions for less frequent errors. It makes sense, but I do not completely agree with <a hreflang="en" href="http://armstrongonsoftware.blogspot.com/" onclick="pageTracker._trackPageview('/outgoing/armstrongonsoftware.blogspot.com/?referer=');">Joe</a> on that matter. When you are developing a software for yourself (or you firm), you may know how your code is used so you know if an error occurs often or not. But when you are developing software for other developers, you don&#8217;t know how they are going to use it, it&#8217;s more difficult to &#8220;predict&#8221; if the error is going to be thrown often or not.</p>
<p>So I tend to prefer throwing exceptions (maybe I have used Java for too long). I think the added syntax is necessary in order to keep thing clear, homogeneous and easy to use. I would love seeing a version of Erlang without functions having a <code>{error, Reason}</code> thing in their return signature (but something like <code>throw(Reason)</code>).</p>
<p>Complete source code associated with this post (you can do whatever you want with it): <a href="http://blog.desgrange.net/wp-content/uploads/2009/01/exceptions.erl">exceptions.erl</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2009/01/05/exceptions-in-erlang/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Object Oriented Programming</title>
		<link>http://blog.desgrange.net/2008/12/22/object-oriented-programming/</link>
		<comments>http://blog.desgrange.net/2008/12/22/object-oriented-programming/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 22:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=637</guid>
		<description><![CDATA[Programming languages use different paradigms, nowadays the most used is the Object Oriented paradigm. Object Oriented Programming was an attempt to simplify the creation of softwares because they were more and more complex. The idea was to model the software with objects (a car for example) with some attributes (it has wheels, a motor, etc.) [...]]]></description>
			<content:encoded><![CDATA[<p><a hreflang="en" href="http://en.wikipedia.org/wiki/Programming_language" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Programming_language?referer=');">Programming languages</a> use different <a hreflang="en" href="http://en.wikipedia.org/wiki/Programming_paradigm" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Programming_paradigm?referer=');">paradigms</a>, nowadays the most used is the <a hreflang="en" href="http://en.wikipedia.org/wiki/Object-oriented_programming" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Object-oriented_programming?referer=');">Object Oriented paradigm</a>. Object Oriented Programming was an attempt to simplify the creation of <a hreflang="en" href="http://en.wikipedia.org/wiki/Software" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Software?referer=');">softwares</a> because they were more and more complex.</p>
<p>The idea was to model the software with objects (a car for example) with some attributes (it has wheels, a motor, etc.) and some methods (start, move forward, etc.). Objects alone are not enough, they need to be able to communicate with each other by sending messages.</p>
<p>I have worked for several years with <a hreflang="en" href="http://en.wikipedia.org/wiki/Java_(programming_language)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Java_programming_language?referer=');">Java</a>, a well known OOP language, and I&#8217;m now working with <a hreflang="en" href="http://en.wikipedia.org/wiki/Erlang_(programming_language)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Erlang_programming_language?referer=');">Erlang</a>, a <a hreflang="en" href="http://en.wikipedia.org/wiki/Functional_programming" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Functional_programming?referer=');">functional language</a>.</p>
<p>A functional language has functions as first class citizens. Functions should be stateless, they get some parameters and return a deterministic result. Seems not enough to design complex softwares.</p>
<p>An other feature of Erlang is the <a hreflang="en" href="http://en.wikipedia.org/wiki/Concurrent_computing" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Concurrent_computing?referer=');">concurrent paradigm</a>. It allows the language to do a lot of tasks in parallel. At first, most people think about this feature has a great tool to distribute calculation and/or use all the <a hreflang="en" href="http://en.wikipedia.org/wiki/Multi-core" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Multi-core?referer=');">cores</a> of a modern <a hreflang="en" href="http://en.wikipedia.org/wiki/CPU" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/CPU?referer=');">CPU</a> with no burden. I thought the same thing. But this is not the aim of Erlang. Concurrent processes are used for software design. A process is a system, mostly representing a real life system, sending and receiving messages from other processes.</p>
<p>After using Erlang for a while (I&#8217;m not a very fast thinker, or maybe I just don&#8217;t think too often <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ), I realized that Erlang is the most Object Oriented Language I have ever seen.</p>
<p>It matches the definition of OOP more than any other language. Objects are processes (with an internal state) talking to each others by sending messages.</p>
<p>Why? Because Erlang allows you to have several thousands threads (objects) running simultaneously, where other languages allows you to have several thousand objects running in few concurrent threads (so if you have X threads, only X objects are running simultaneously). In Erlang objects are really independent from each others, while in languages like C++, C# or Java, objects are executed sequentially.</p>
<p>Interestingly, if they share the same base idea, those languages need a completely different approach. One of the big differences is that talking between objects in Erlang is done by passing messages while it&#8217;s done by methods calls in traditional OOP languages.</p>
<p>In those languages we do not deal very often with multiple threads and we tend to not have threads talking with each others because it needs locks and synchronization. Erlang deals with that very easily.</p>
<p>So in an OOP language like Java, when a thread dies, a lot of objects dies, maybe the whole software, that&#8217;s may be not so bad (kind of <a hreflang="en" href="http://en.wikipedia.org/wiki/Fail_Fast" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Fail_Fast?referer=');">fail fast</a> approach). In Erlang, when a process dies, it&#8217;s just an object, everything else is still running (when a car crash, the neighborhood does not disappear), but this can lead to some unknown state (imagine a firm where the boss dies and nobodies notice it (and are glad to not receive orders anymore <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> )). Erlang provides some tools to manage that. Processes can be linked together, when a process dies, it sends a death note (sorry <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) to processes it was linked to. When a process receives such a message, if it does not know how to handle it, it dies too (my wife is dead, I&#8217;m lost, I must commit suicide), but of course it may know what to do with the message, like restarting a process like the dead one (let&#8217;s find a new wife). In Erlang&#8217;s libraries there are such modules, called supervisors, specialized in re-spawning a process when it dies. It may looks like overhead, but I think it&#8217;s very useful to create robust and fault-tolerant applications.</p>
<p>Anyway, I have the feeling that in the Erlang&#8217;s community, there is a strong opinion against OOP. I think I will have understood how to design softwares in Erlang faster if people told me first that Erlang is true OOP and why and how. Moreover, it may bring more people to Erlang to develop the language and reduce the number of people asking for such and such OOP feature that are already in Erlang but not the way they are thinking about it.</p>
<p><a hreflang="en" href="http://en.wikipedia.org/wiki/Ralph_Johnson" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Ralph_Johnson?referer=');">Ralph Johnson</a> has an interesting (and short enough) article about <a hreflang="en" href="http://www.cincomsmalltalk.com/userblogs/ralph/blogView?entry=3364027251" onclick="pageTracker._trackPageview('/outgoing/www.cincomsmalltalk.com/userblogs/ralph/blogView?entry=3364027251&amp;referer=');">Erlang being the next Java</a>.</p>
<p><a hreflang="en" href="http://www.planeterlang.org/story.php?title=Thinking_About_Concurrency_Oriented_Programming" onclick="pageTracker._trackPageview('/outgoing/www.planeterlang.org/story.php?title=Thinking_About_Concurrency_Oriented_Programming&amp;referer=');">Same thing was discussed on PlanetErlang</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2008/12/22/object-oriented-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erlang hot swapping</title>
		<link>http://blog.desgrange.net/2008/12/01/erlang-hot-swapping/</link>
		<comments>http://blog.desgrange.net/2008/12/01/erlang-hot-swapping/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 22:00:00 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.desgrange.net/?p=634</guid>
		<description><![CDATA[I started using the erlang programming language few months ago. Erlang is a wonderful language if you want to do reliable, distributed, highly concurrent, fault-tolerant, soft-real-time, highly available, hot swapping applications . So, today I will give you a glimpse on one cool functionality of Erlang: the ability to update your code without stopping your [...]]]></description>
			<content:encoded><![CDATA[<p>I started using the <a hreflang="en" href="http://en.wikipedia.org/wiki/Erlang_(programming_language)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Erlang_programming_language?referer=');">erlang</a> <a hreflang="en" href="http://en.wikipedia.org/wiki/Programming_language" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Programming_language?referer=');">programming language</a> few months ago. <a hreflang="en" href="http://www.erlang.org/" onclick="pageTracker._trackPageview('/outgoing/www.erlang.org/?referer=');">Erlang</a> is a wonderful language if you want to do reliable, <a hreflang="en" href="http://en.wikipedia.org/wiki/Distributed_computing" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Distributed_computing?referer=');">distributed</a>, highly <a hreflang="en" href="http://en.wikipedia.org/wiki/Concurrent_computing" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Concurrent_computing?referer=');">concurrent</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/Fault_tolerance" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Fault_tolerance?referer=');">fault-tolerant</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/Soft_real-time" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Soft_real-time?referer=');">soft-real-time</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/High_availability" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/High_availability?referer=');">highly available</a>, <a hreflang="en" href="http://en.wikipedia.org/wiki/Hot_swapping" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Hot_swapping?referer=');">hot swapping</a> applications <img src='http://blog.desgrange.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p>So, today I will give you a glimpse on one cool functionality of Erlang: the ability to update your code without stopping your application. Here it&#8217;s just about how it works for a process (the principle is the same for an application except that you have much more things to take into account when you have several thousands process talking to each other).</p>
<h5>THE CODE</h5>
<p>We are going to use a simple piece of code. We want a server thread listening for messages (each message is printed on the console with a sequence number), and a client thread, sending a message to the server every second. Here is the code (I usually don&#8217;t use comments but I put some here because you may not understand erlang code):</p>
<div id="wpshdo_21" class="wp-synhighlighter-outer"><div id="wpshdt_21" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_21"></a><a id="wpshat_21" class="wp-synhighlighter-title" href="#codesyntax_21"  onClick="javascript:wpsh_toggleBlock(21)" title="Click to show/hide code block">code_reload.erl</a></td><td align="right"><a href="#codesyntax_21" onClick="javascript:wpsh_code(21)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_21" onClick="javascript:wpsh_print(21)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_21" class="wp-synhighlighter-inner" style="display: block;"><pre class="erlang" style="font-family:monospace;"><span class="sy3">-</span><span class="re2">module</span><span class="br0">&#40;</span>code_reload<span class="br0">&#41;</span><span class="sy1">.</span> <span class="co1">% This is the module declaration.</span>
<span class="sy3">-</span><span class="re2">export</span><span class="br0">&#40;</span><span class="br0">&#91;</span>start_server<span class="sy3">/</span><span class="nu0">0</span><span class="sy1">,</span> start_client<span class="sy3">/</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">.</span> <span class="co1">% Exporting functions allow them to be called from outside the module.</span>
<span class="sy3">-</span><span class="re2">export</span><span class="br0">&#40;</span><span class="br0">&#91;</span>server_loop<span class="sy3">/</span>1<span class="sy1">,</span> client_loop<span class="sy3">/</span>1<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">.</span>
&nbsp;
<span class="re3">start_server</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="kw3">spawn</span><span class="br0">&#40;</span>?<span class="re4">MODULE</span><span class="sy1">,</span> server_loop<span class="sy1">,</span> <span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">.</span> <span class="co1">% This function calls the server_loop function in a new thread.</span>
&nbsp;
<span class="re3">server_loop</span><span class="br0">&#40;</span><span class="re5">Count</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="kw1">receive</span> <span class="co1">% Wait for messages</span>
        <span class="br0">&#123;</span><span class="re5">From</span><span class="sy1">,</span> quit<span class="br0">&#125;</span> <span class="sy1">-&gt;</span>
            <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Received quit command from ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">From</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
            ok<span class="sy1">;</span>
        <span class="br0">&#123;</span><span class="re5">From</span><span class="sy1">,</span> <span class="re5">Message</span><span class="br0">&#125;</span> <span class="sy1">-&gt;</span>
            <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;~p: Server received message ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">Count</span><span class="sy1">,</span> <span class="kw3">self</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy1">,</span> <span class="re5">Message</span><span class="sy1">,</span> <span class="re5">From</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span> <span class="co1">% Display the message we received.</span>
            ?<span class="re4">MODULE</span>:<span class="re3">server_loop</span><span class="br0">&#40;</span><span class="re5">Count</span><span class="br0">&#41;</span><span class="sy1">;</span> <span class="co1">% Call the same function again to wait for an other message.</span>
    	<span class="re5">_</span> <span class="sy1">-&gt;</span>
            <span class="kw3">throw</span><span class="br0">&#40;</span>unexpected_message<span class="br0">&#41;</span>
    <span class="kw1">end</span><span class="sy1">.</span>
&nbsp;
<span class="re3">start_client</span><span class="br0">&#40;</span><span class="re5">ServerPid</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="kw3">spawn</span><span class="br0">&#40;</span>?<span class="re4">MODULE</span><span class="sy1">,</span> client_loop<span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">ServerPid</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">.</span>
&nbsp;
<span class="re3">client_loop</span><span class="br0">&#40;</span><span class="re5">ServerPid</span><span class="br0">&#41;</span> <span class="sy1">-&gt;</span>
    <span class="kw1">receive</span>
        <span class="br0">&#123;</span><span class="re5">From</span><span class="sy1">,</span> quit<span class="br0">&#125;</span> <span class="sy1">-&gt;</span>
            <a href="http://erlang.org/doc/man/io.html" onclick="pageTracker._trackPageview('/outgoing/erlang.org/doc/man/io.html?referer=');"><span class="kw5">io</span></a>:<span class="re3">fwrite</span><span class="br0">&#40;</span><span class="st0">&quot;Received quit command from ~p~n&quot;</span><span class="sy1">,</span> <span class="br0">&#91;</span><span class="re5">From</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy1">,</span>
            ok
    <span class="kw1">after</span> <span class="nu0">1000</span> <span class="sy1">-&gt;</span> <span class="co1">% If no messages were received after 1 second, send a message to the server.</span>
            <span class="re5">ServerPid</span> <span class="sy3">!</span> <span class="br0">&#123;</span><span class="kw3">self</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy1">,</span> <span class="kw3">now</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#125;</span><span class="sy1">,</span>
            ?<span class="re4">MODULE</span>:<span class="re3">client_loop</span><span class="br0">&#40;</span><span class="re5">ServerPid</span><span class="br0">&#41;</span>
    <span class="kw1">end</span><span class="sy1">.</span></pre></div></div>
<p>Let&#8217;s start an erlang shell:</p>
<div id="wpshdo_22" class="wp-synhighlighter-outer"><div id="wpshdt_22" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_22"></a><a id="wpshat_22" class="wp-synhighlighter-title" href="#codesyntax_22"  onClick="javascript:wpsh_toggleBlock(22)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_22" onClick="javascript:wpsh_code(22)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_22" onClick="javascript:wpsh_print(22)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_22" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">$ erl
Erlang (BEAM) emulator version 5.6.2 [source] [smp:2] [async-threads:0] [kernel-poll:false]
&nbsp;
Eshell V5.6.2  (abort with ^G)
1&gt; c(code_reload). % This compile the module code_reload.
{ok,code_reload}
2&gt; ServerPid = code_reload:start_server(). % Start the server and assign the server process id to the variable ServerPid.
&lt;0.37.0&gt;
3&gt; ClientPid = code_reload:start_client(ServerPid).
&lt;0.39.0&gt;
0: Server &lt;0.65.0&gt; received message {1211,11183,231032} from &lt;0.67.0&gt;
0: Server &lt;0.65.0&gt; received message {1211,11184,232031} from &lt;0.67.0&gt;
0: Server &lt;0.65.0&gt; received message {1211,11185,233029} from &lt;0.67.0&gt;
0: Server &lt;0.65.0&gt; received message {1211,11186,234031} from &lt;0.67.0&gt;
0: Server &lt;0.65.0&gt; received message {1211,11187,235030} from &lt;0.67.0&gt;</pre></div></div>
<p>We can see the server printing the messages. But oups, there is a bug! I forgot to increment the counter so each line start with &#8220;0&#8243; instead of an incrementing number.</p>
<p>Let&#8217;s change the following line in the code:</p>
<div id="wpshdo_23" class="wp-synhighlighter-outer"><div id="wpshdt_23" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_23"></a><a id="wpshat_23" class="wp-synhighlighter-title" href="#codesyntax_23"  onClick="javascript:wpsh_toggleBlock(23)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_23" onClick="javascript:wpsh_code(23)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_23" onClick="javascript:wpsh_print(23)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_23" class="wp-synhighlighter-inner" style="display: block;"><pre class="erlang" style="font-family:monospace;">?<span class="re4">MODULE</span>:<span class="re3">server_loop</span><span class="br0">&#40;</span><span class="re5">Count</span> <span class="sy3">+</span> 1<span class="br0">&#41;</span><span class="sy1">;</span></pre></div></div>
<p>We need to go back to the shell and compile the new code:</p>
<div id="wpshdo_24" class="wp-synhighlighter-outer"><div id="wpshdt_24" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_24"></a><a id="wpshat_24" class="wp-synhighlighter-title" href="#codesyntax_24"  onClick="javascript:wpsh_toggleBlock(24)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_24" onClick="javascript:wpsh_code(24)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_24" onClick="javascript:wpsh_print(24)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_24" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">4&gt; c(code_reload).
{ok,code_reload}
0: Server &lt;0.65.0&gt; received message {1211,11188,236023} from &lt;0.67.0&gt;
0: Server &lt;0.65.0&gt; received message {1211,11189,237031} from &lt;0.67.0&gt;
1: Server &lt;0.65.0&gt; received message {1211,11190,238021} from &lt;0.67.0&gt;
2: Server &lt;0.65.0&gt; received message {1211,11191,239031} from &lt;0.67.0&gt;
3: Server &lt;0.65.0&gt; received message {1211,11192,240018} from &lt;0.67.0&gt;
4: Server &lt;0.65.0&gt; received message {1211,11193,241022} from &lt;0.67.0&gt;
5: Server &lt;0.65.0&gt; received message {1211,11194,242021} from &lt;0.67.0&gt;
6: Server &lt;0.65.0&gt; received message {1211,11195,243031} from &lt;0.67.0&gt;</pre></div></div>
<p>Ah! It&#8217;s better, the message number is growing as expected. Notice that the threads are still the same (<code>&lt;0.65.0&gt;</code> for the server and <code>&lt;0.67.0&gt;</code> for the client).</p>
<p>There is no black magic here. The main part of the code is a loop. The server function is <code>server_loop</code> and it calls itself with <code>?MODULE:server_loop(…)</code>. The process is running inside the old version of the code, and when we call <code>server_loop</code> again, the new call is send to the new version of the code.</p>
<p>Be careful, this happens only because we call the function that way <code>?MODULE:server_loop</code> (<code>code_reload:server_loop</code> also works). Hot upgrade does not work if we call <code>server_loop</code> directly with going through the module again. This allows you to control where and when code reloading is done.</p>
<p>Now we can send a quit message to the client and the server:</p>
<div id="wpshdo_25" class="wp-synhighlighter-outer"><div id="wpshdt_25" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_25"></a><a id="wpshat_25" class="wp-synhighlighter-title" href="#codesyntax_25"  onClick="javascript:wpsh_toggleBlock(25)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_25" onClick="javascript:wpsh_code(25)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_25" onClick="javascript:wpsh_print(25)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.desgrange.net/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_25" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">5&gt; ClientPid ! {self(), quit}.
Received quit command from &lt;0.30.0&gt;
{&lt;0.30.0&gt;,quit}
6&gt; ServerPid ! {self(), quit}.
Received quit command from &lt;0.76.0&gt;
{&lt;0.76.0&gt;,quit}</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.desgrange.net/2008/12/01/erlang-hot-swapping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

