<?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>Sadek Drobi's Blog &#187; Agile Programming</title>
	<atom:link href="http://sadekdrobi.com/category/agile-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://sadekdrobi.com</link>
	<description>Sadek Drobi</description>
	<lastBuildDate>Tue, 08 Mar 2011 22:56:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DCI in Real World: Domain Context and Interaction with Scala in a Real World Project</title>
		<link>http://sadekdrobi.com/2009/06/10/dci-in-real-world-domain-context-and-interaction-with-scala-in-a-real-world-project/</link>
		<comments>http://sadekdrobi.com/2009/06/10/dci-in-real-world-domain-context-and-interaction-with-scala-in-a-real-world-project/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 22:40:09 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Coplien]]></category>
		<category><![CDATA[DCI]]></category>
		<category><![CDATA[Delivering Value]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Domain-Context-Interaction]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JVM]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Multi-Paradigm Design]]></category>
		<category><![CDATA[Multi-languages projects]]></category>
		<category><![CDATA[Polyglot Programming]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[back-to-oop]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/06/10/dci-in-real-world-domain-context-and-interaction-with-scala-in-a-real-world-project/</guid>
		<description><![CDATA[Those that follow my twitter @sadache , me @infoQ or my blog have certainly already noticed that I am quite interested in Scala on languages&#8217; axis and in Domain Context Interaction DCI pattern on architecture axis. I always search new ways for delivering quality code which is modular and concise. Modularity offers the opportunity to [...]]]></description>
			<content:encoded><![CDATA[<p>Those that follow <a href="http://twitter.com/sadache">my twitter @sadache</a> , <a href="http://www.infoq.com/author/sadek-drobi">me @infoQ</a> or my blog have certainly already noticed that I am quite interested in Scala on languages&#8217; axis and in <a href="http://www.artima.com/articles/dci_vision.html">Domain Context Interaction DCI</a> pattern on architecture axis. I always search new ways for delivering quality code which is modular and concise. Modularity offers the opportunity to think about the problem in parts, which is typical of the way brains work, whereas conciseness makes use of imaginary system (reading code blocks like images). </p>
<p>Recently, I&#8217;ve been working on a Web Api system where, thanks to support of <a href="http://twitter.com/morlhon">@jeanlaurent</a> <a href="http://morlhon.net/blog/">http://morlhon.net/blog/</a>, I used Scala applying DCI architecture in a real world project. This post is about reporting benefits of using this approach. Other posts will follow that will be more focused on the use of Scala and Functional Programming in that project. Code included is a bit simplified and parts of the system that are not of interest are omitted.</p>
<p><span id="more-638"></span>
<p>The concerned part of the system is an API for logging a Web API usage and using it for showing interesting statistics to users and for implementing a Web 2.0 business model authorization.</p>
<p>The story starts with an API key passed as a parameter in the requested URI something like <em>product/1234?api_key=AFFSEFFVFE2344</em></p>
<p>I create an object that represents the API user containing the key: (did I tell I like one liners?)</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb.png" width="260" height="40"></a>&nbsp; </p>
<p>This is a class of an object that holds the apiKey, now I need a method that I will call to log the use of product/123 for user represented by the apiKey AFFSEFFVFE2344. What could be quite convenient and OOP-iesh is to call a <em>record</em> method on the apiKey instance, something like <em>apiUser.record(&#8230;) .</em> The problem with this, as explained in the original DCI article, is that adding these methods to the domain objects adds noise in other contexts for which recording is not relevant such as authorization and statistics, as we will see later. I would rather use here the DCI&#8217;s <em>role</em> concept (or <em>context</em>). Doing so I would say <em>(apiUser in recording role).record(&#8230;) . </em>This pseudo code tends to be very close to mixins implemented in Scala language and will look like following in real world Scala code:</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image1.png"></a><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image2.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb1.png" width="617" height="57"></a>&nbsp; </p>
<p>Here the ApiUser object doesn&#8217;t contain a record method by default and so it can be shared in different contexts. In other words we kept our domain objects pure yet not scarifying OOP convenience. Now the <em>Recorder</em> is a trait that minds only business in the context of recording. The definition looks like the following:</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image3.png"></a><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image4.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb2.png" width="281" height="108"></a>&nbsp; </p>
<p>Another view of the system is the end user&#8217;s statistics. Statistics should be represented in a meaningful way to the user and the user can&#8217;t care less about how the recording is done. So, it is quite desirable not to have the noise of recording when talking about the statistics view context. Here is how the call looks like in our example in Scala:</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image5.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb3.png" width="667" height="63"></a> </p>
<p>Again what we are doing here looks merely like saying: I want to use the ApiUser in a statistics context and I choose to call method getRequestsPerMonthForLast12Months. I guess the convenience brought by using this approach is obvious. This is how the Statistics trait looks like:</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image6.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb4.png" width="647" height="150"></a> </p>
<p>Note that as in the Recording trait, the <em>ApiUser</em> object is not passed as an explicit parameter but rather as an implicit receiver parameter (something like <em>this</em> for an object). To access it we use <em>Self</em> that refers to it<em>.</em></p>
<p>The third view of the system is what allows us to provide an authorization mechanism based on user&#8217;s activities for a business plan they choose (be it a quota per day, per month or other interesting combinations). It could be quite convenient to have the call looking like <em>apiUser.isAuthorized . </em>We get pretty close with DCI without polluting our domain object with a specific context logic:</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image7.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb5.png" width="540" height="66"></a> </p>
<p>Like the previous, the Authorizer trait looks straightforward :</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image8.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb6.png" width="454" height="207"></a> </p>
<p>Now that we looked at the three views of our system introducing three examples of &#8220;<em>Context</em>&#8221; from DCI pattern we can go beyond that to discover how we use nested <em>contexts</em> (or <em>roles</em>). </p>
<p>Looking at the Authorizer trait, the ApiUser referred to by <em>Self,</em> doesn&#8217;t tell us much about<em> </em>how many requests the user did today or this month. And for authorizing user one needs a richer ApiUser that can give the necessary information that live themselves in a file or a database. But once again, we don&#8217;t want to pollute our domain object with Data Access code that varies on a different axis than the domain object itself.&nbsp; Introducing a nested context/role that adds the Data Access logic would pretty convenient here:</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image9.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb7.png" width="473" height="56"></a> </p>
<p>Here <em>Self </em>is a richer ApiUser that carries Requests Data Access logic defined in the RequestsDataAccessor trait:</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image10.png"></a><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image11.png"></a><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image12.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb8.png" width="848" height="193"></a>&nbsp;&nbsp; </p>
<p>And the implementation of the Authorizer trait defined in terms of <em>ApiUser with RequestsDataAccessor</em>:</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image13.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb9.png" width="468" height="373"></a> </p>
<p>In the same way we implement the <em>Statistics</em> and <em>Recorder</em> traits using <em>ApiUser with RequestsDataAccessor:</em></p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image14.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb10.png" width="451" height="148"></a> </p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/06/image15.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://sadekdrobi.com/wp-content/uploads/2009/06/image-thumb11.png" width="581" height="295"></a> </p>
<p>If you are not familiar with generics ( getRequestsPer[Day] ) you can ignore them since they are not central to the subject of this post and simply use their readability to understand the purpose of the method. The use of generics in this project will be the subject of a future post.</p>
<h3>Encapsulation Test!</h3>
<p>Now in the first version of the system, the ApiKey was passed in clear in the service URI. This is not very secured as it is quite easy to get the key and use it for using the API. We might prefer to encrypt the key in some way. This fortunately changes nothing for any of our traits implementations since the decryption of the key is the responsiblity of the ApiUSer object and all what our traits need is to get the concerned ApiKey from that object which can be easily done with pattern matching. Same thing if we want to replace database logging with file system in RequestsDataAccessor. Modularity and separation of concerns are apparent in this DCI architecture implementation.</p>
<p>&nbsp;</p>
<h3>Conclusion</h3>
<p>This is a refreshing approach to OOP. The <strong>Domain Context Interaction</strong> pattern allowed us to restore interesting properties of real OOP approach yet not sacrificing modularity and separation of concerns. This simple view of &#8220;an object in several contexts&#8221; helps quite much in thinking explicitly about and understanding context boundaries. Note that an object(instance) is not defined by a single class but each instance curries the necessary context. This is essential to OOP which is NOT COP (for Class Oriented Programming ;) )</p>
<p>&nbsp;</p>
<p>Feel free to ask questions and/or comment about this implementation. Refer to original papers for more in-depth explanation of the pattern. </p>
<p>Thanks to JetBrains&#8217; IDEA and the Scala plug-in that helped me programming in Scala.</p>
<p>&nbsp;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7cedd753-901b-4d50-b76a-a7c30a681f4e" class="wlWriterSmartContent">Mots clés Technorati : <a href="http://technorati.com/tags/DCI" rel="tag">DCI</a>,<a href="http://technorati.com/tags/Coplien" rel="tag">Coplien</a>,<a href="http://technorati.com/tags/OOP" rel="tag">OOP</a>,<a href="http://technorati.com/tags/Scala" rel="tag">Scala</a>,<a href="http://technorati.com/tags/J2EE" rel="tag">J2EE</a>,<a href="http://technorati.com/tags/Domain-Context-Interaction" rel="tag">Domain-Context-Interaction</a>,<a href="http://technorati.com/tags/Architecture" rel="tag">Architecture</a>,<a href="http://technorati.com/tags/Multi-Paradigm-Design" rel="tag">Multi-Paradigm-Design</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/06/10/dci-in-real-world-domain-context-and-interaction-with-scala-in-a-real-world-project/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Data, Context and Interaction : a new architectural approach by James O. Coplien and Trygve Reenskaug</title>
		<link>http://sadekdrobi.com/2009/05/08/data-context-and-interaction-a-new-architectural-approach-by-james-o-coplien-and-trygve-reenskaug/</link>
		<comments>http://sadekdrobi.com/2009/05/08/data-context-and-interaction-a-new-architectural-approach-by-james-o-coplien-and-trygve-reenskaug/#comments</comments>
		<pubDate>Fri, 08 May 2009 14:48:01 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Model Mismatch]]></category>
		<category><![CDATA[Multi-Paradigm Design]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/05/08/data-context-and-interaction-a-new-architectural-approach-by-james-o-coplien-and-trygve-reenskaug/</guid>
		<description><![CDATA[James O. Coplien and Trygve Reenskaug have recently introduced a new architectural approach to OOP based on Data, Context and Interaction pattern. It should allow capturing user mental model in terms of behavioral requirements, something that classic OOP fails to do. The article, that triggered many reactions and critics, provides insights into DCI using concrete [...]]]></description>
			<content:encoded><![CDATA[<p>James O. Coplien and Trygve Reenskaug have recently introduced a new architectural approach to OOP based on Data, Context and Interaction pattern. It should allow capturing user mental model in terms of behavioral requirements, something that classic OOP fails to do. The article, that triggered many reactions and critics, provides insights into DCI using concrete examples to show its advantages.</p>
<p><span id="more-606"></span>
<p><a href="http://www.infoq.com/news/2009/05/dci-coplien-reenskau">http://www.infoq.com/news/2009/05/dci-coplien-reenskau</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/05/08/data-context-and-interaction-a-new-architectural-approach-by-james-o-coplien-and-trygve-reenskaug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quiz:: SharpLight &#124;&gt; What does this do?</title>
		<link>http://sadekdrobi.com/2009/02/03/quiz-sharplight-what-does-this-do/</link>
		<comments>http://sadekdrobi.com/2009/02/03/quiz-sharplight-what-does-this-do/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 14:02:09 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DOTNET]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[sharplight]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/02/03/quiz-sharplight-what-does-this-do/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/02/combination1.jpg"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="combination" src="http://sadekdrobi.com/wp-content/uploads/2009/02/combination-thumb1.jpg" width="627" height="105" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/02/03/quiz-sharplight-what-does-this-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Makes Haskell Worth Learning for Real World Applications</title>
		<link>http://sadekdrobi.com/2009/01/25/what-makes-haskell-worth-learning-for-real-world-applications/</link>
		<comments>http://sadekdrobi.com/2009/01/25/what-makes-haskell-worth-learning-for-real-world-applications/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 22:23:02 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[InfoQ]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/01/25/what-makes-haskell-worth-learning-for-real-world-applications/</guid>
		<description><![CDATA[Around 750 people commented on the online preview of the Real World Haskell book. As described by one of its co-authors, John Goerzen, in a recent interview to Oâ€™Reilly, the book introduces Haskell with real code, real examples and tips to exploit in a business environment. In his interview, Goerzen explains why, in his opinion, [...]]]></description>
			<content:encoded><![CDATA[<p>Around 750 people commented on the online preview of the Real World Haskell book. As described by one of its co-authors, John Goerzen, in a recent interview to Oâ€™Reilly, the book introduces Haskell with real code, real examples and tips to exploit in a business environment. In his interview, Goerzen explains why, in his opinion, this language is worth learning; he provides insights into its specificities and addresses some issues that may be a source of reluctance.</p>
<p><span id="more-583"></span></p>
<p><a href="http://www.infoq.com/news/2009/01/rwh-book-interview">http://www.infoq.com/news/2009/01/rwh-book-interview</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/01/25/what-makes-haskell-worth-learning-for-real-world-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My tinny presentation in VTDays 2008</title>
		<link>http://sadekdrobi.com/2009/01/22/my-tinny-presentation-in-vtdays-2008/</link>
		<comments>http://sadekdrobi.com/2009/01/22/my-tinny-presentation-in-vtdays-2008/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 23:13:37 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[LinQ]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/01/22/my-tinny-presentation-in-vtdays-2008/</guid>
		<description><![CDATA[
&#160;
For those that didn&#8217;t happen to be there, here is a link to my tinny presentation I did in VTDays last year. There is a huge room for improvement, yet funny :)

http://storage02.brainsonic.com/customers/valtech/20081021/AR7/files/index_popup.html
]]></description>
			<content:encoded><![CDATA[<p><img height="332" src="http://www.willamette.edu/~fruehr/logos/PNGs/Dysfunctional.png" width="417"></p>
<p>&nbsp;</p>
<p>For those that didn&#8217;t happen to be there, here is a link to my tinny presentation I did in VTDays last year. There is a huge room for improvement, yet funny :)</p>
<p><span id="more-582"></span></p>
<p><a title="http://storage02.brainsonic.com/customers/valtech/20081021/AR7/files/index_popup.html" href="http://storage02.brainsonic.com/customers/valtech/20081021/AR7/files/index_popup.html">http://storage02.brainsonic.com/customers/valtech/20081021/AR7/files/index_popup.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/01/22/my-tinny-presentation-in-vtdays-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You&#8217;ve got 100 pages to convince me of your shiny language!</title>
		<link>http://sadekdrobi.com/2009/01/05/youve-got-100-pages-to-convince-me-in-your-shiny-language/</link>
		<comments>http://sadekdrobi.com/2009/01/05/youve-got-100-pages-to-convince-me-in-your-shiny-language/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 20:42:37 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Delivering Value]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Methodologies]]></category>
		<category><![CDATA[Multi-Paradigm Design]]></category>
		<category><![CDATA[Multi-languages projects]]></category>
		<category><![CDATA[Paradigm Oriented Programming Language]]></category>
		<category><![CDATA[Polyglot Programming]]></category>
		<category><![CDATA[Useability]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/01/05/youve-got-100-pages-to-convince-me-in-your-shiny-language/</guid>
		<description><![CDATA[ In the rapidly spanning world of programming languages, I find myself buying and reading a lot of books about new and old programming languages. There are a few interesting concepts in each language, and if you think about employing more than one language in your projects then you better know about the existence of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/01/dsc-01501.jpg"><img style="border-right: 0px; border-top: 0px; margin: 0px 10px 5px 0px; border-left: 0px; border-bottom: 0px" height="322" alt="DSC_0150-" src="http://sadekdrobi.com/wp-content/uploads/2009/01/dsc-0150-thumb1.jpg" width="470" align="left" border="0"></a> In the rapidly spanning world of programming languages, I find myself buying and reading a lot of books about new and old programming languages. There are a few interesting concepts in each language, and if you think about employing more than one language in your projects then you better know about the existence of these concepts (see <a href="http://www.infoq.com/articles/paradigm-based-polyglot-prog">Paradigm based Polyglot Programming</a>).
<p>One thing that annoys me though about most programming language books is how raw they often are.</p>
<p><span id="more-575"></span></p>
<p>&nbsp; Probably constrained by time, authors and book teams seem to invest less on editorial stuff and teaching methodology and more on explaining details of technical and behind the scenes stuff. This often results in more manual-like books where you have a great wealth of material that you are not able to exploit anyway because of, well, lack of time. I am not sure I can invest time in reading 500+ manual of a new, or at least non mainstream, language that I might decide not to use by the end.&nbsp;
<p>I am not saying here that technical and behind the scene stuff does not matter, quite the opposite. I just think that manual, important it is, should not be the introduction to the programming language. A rather 100 to 200 pages brief book that is carefully edited to introduce paradigm, concepts, and strengths of the programming language is a more attractive choice , accompanied with a wordy but well organized reference book with examples and more in-depth explanation of language features. I guess this is a more pragmatic approach to programming language learning in the presence of WWW and Google search.
<p>PS: I personally find <a href="http://www.amazon.com/Haskell-School-Expression-Functional-Programming/dp/0521644089/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1231187744&amp;sr=8-1">Paul Hudak&#8217;s Haskell book</a> a very good example of an enjoyable, brief, nicely and carefully edited programming language book. Also <a href="http://www.amazon.com/Programming-Lua-Second-Roberto-Ierusalimschy/dp/8590379825/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1231187997&amp;sr=1-1">LUA&#8217;s programming book</a> is nicely done.</p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/01/05/youve-got-100-pages-to-convince-me-in-your-shiny-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RefX:: ORMs, Relational Data, Mismatch, LinQ and DSLs</title>
		<link>http://sadekdrobi.com/2008/11/10/refx-orms-relational-data-mismatch-linq-and-dsls/</link>
		<comments>http://sadekdrobi.com/2008/11/10/refx-orms-relational-data-mismatch-linq-and-dsls/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 02:42:22 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile in the Enterprise]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[D90]]></category>
		<category><![CDATA[DOTNET]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[LinQ]]></category>
		<category><![CDATA[Mapping]]></category>
		<category><![CDATA[Model Mismatch]]></category>
		<category><![CDATA[Multi-Paradigm Design]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Polyglot Programming]]></category>
		<category><![CDATA[Productivity]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2008/11/10/refx-orms-relational-data-mismatch-linq-and-dsls/</guid>
		<description><![CDATA[   
Having worked with several Object-Relational mapping frameworks in the last few years, I got to a point where I couldn&#8217;t justify their complexity in my project. We often talk about the mismatch between the database and the object worlds, and that is where ORMs are often stated and referenced for &#8220;bridging the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sadekdrobi.com/wp-content/uploads/2008/11/raw000781.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="361" alt="Raw00078" src="http://sadekdrobi.com/wp-content/uploads/2008/11/raw00078-thumb1.jpg" width="534" border="0"></a> <a href="http://sadekdrobi.com/wp-content/uploads/2008/11/raw001701.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="379" alt="Raw00170" src="http://sadekdrobi.com/wp-content/uploads/2008/11/raw00170-thumb1.jpg" width="258" border="0"></a> <a href="http://sadekdrobi.com/wp-content/uploads/2008/11/dsc-01911.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="378" alt="DSC_0191" src="http://sadekdrobi.com/wp-content/uploads/2008/11/dsc-0191-thumb1.jpg" width="257" border="0"></a> </p>
<p>Having worked with several Object-Relational mapping frameworks in the last few years, I got to a point where I couldn&#8217;t justify their complexity in my project. We often talk about the mismatch between the database and the object worlds, and that is where ORMs are often stated and referenced for &#8220;bridging the gap&#8221;!</p>
<p>Well I prefer to call it lifting the gap, or highering the gap, to have it now between DAOs and the rest of the code than having it between database and code.But I wouldn&#8217;t call this in any way reducing the gap.</p>
<p><span id="more-538"></span></p>
<p>First thing to mention here, is that data structures are not evil. We often deal with XML data structure but we absolutely refuse to deal with relational data structures. The problem might be related to time, XML came with a whole arsenal of managed APIs that represent its model in a way that makes it more comfortable for you to manipulate these documents. All together with transformation APIs that made it a lot easier to fill your object model out of an XML. Relational data structure on the other hand did not have the luxury of standard APIs and representation models in mainstream languages, and that made dealing with a database request result so arbitrary (Datasets existed in .Net but they have been cursed heavily and has been forced out of the cool toolbox, do not know yet why!) .&nbsp; </p>
<p>In some way, I guess that the &#8220;mismatch&#8221; between Relational data structures and objects exists much similarly between XML and objects, however we didn&#8217;t think for so long of a doing a mapping between XML and object OXM? (no we are starting to do so, writing some XML to map XML to objects!).</p>
<p>With the experience I had with mapping technologies, I can say that they do not solve the problem for me. They merely add yet another useless level of abstraction where your domain types look nothing like relational data structures, but yet nothing like your target domain model! They have gone a half way, and now its your turn to poison your application with a lot of absurd ORM code trying to stretch this bridge to reduce the gap&#8230; </p>
<p>Geeks love talking about intrusivty of an ORMs and compare level of intrusivty in different terms. Intrusivty is much more than the lack of an interface or methods to implement in your domain objects. I guess I am ok to deal with that kind of intrusivity. However all ORMs I tried do not give me the opportunity to express my domain model in the way I would like to. I have to deal with notions of Lazy Loading, Attached/Detached entities, Entity sets, ids, back fields and a lot of other things that I don&#8217;t want to appear in my model and that make the resulting code so ugly and complex that I don&#8217;t wish to visit soon.</p>
<p>As Bob Martin said before, we are missing the opportunity to do oop, I would enforce and say we are missing the opportunity to model at all. And I guess we have gone too far with ORMs and it is time to go back to the basics, in the same way we have done after the EJB great abstraction.</p>
<p>It is very contradictory, while we are so excited about DSLs and the goodness they can potentially bring to enterprise development that results in a declarative semanticful style of programming, we can&#8217;t help but to engage all of our means in trying to bury SQL (and effective, semanticful, declarative powerful domain specific language) behind a dumb API to &#8220;abstract database access&#8221;! I guess we got to chose one strategy, either we keep SQL and we&nbsp; keep marketing DSLs or we hope for a new advanced GPL compiler that will hide all of this in the same way modern languages did with garbage collection, concurrency and synchronization.</p>
<p>Since I am not yet a compiler writer, and I aint got around an effective way of integrating database in mainstream languages (there is actually a very productive in memory database on Haskell that worth trying), I decide to keep the DSL, and to work with them without the need to hide them, but rather to get a better tooling to help converting between difference data structures.</p>
<p>I guess you&#8217;ve guessed it by now. For me LinQ is the mid-term solution for the data structure mismatch. No not LinQ to sql, nor Ado.Net entities (they are helpful and we might use them but lets focus on the solution). LinQ is a very productive tool that halps effectively transform anything to anything in few lines of code. I mean that I can still use powerful SQL to get data effeciently and then convert them with one line of LinQ into the destination data structure. No abstraction leak, less complexity: Use the right tool where it applies. </p>
<p>So what I would actually do is to use a framework that will execute my SQL or SQL like query on the database and get me the records in much the same way they are in the database,Much in the same way Active Record gets you records as they are in the database. No useless efforts from the framework to bend the data to make it look untruthfully like the destination model.&nbsp; I guess I know better my domain model, and with this better tooling I can get it done with no problem.</p>
<p>&nbsp;</p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f663d4e1-de43-4d9c-9f89-7b45ec5b5a86" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Mots clÃ©s Technorati : <a href="http://technorati.com/tags/mapping" rel="tag">mapping</a>,<a href="http://technorati.com/tags/orm" rel="tag">orm</a>,<a href="http://technorati.com/tags/linq" rel="tag">linq</a>,<a href="http://technorati.com/tags/mismatch" rel="tag">mismatch</a>,<a href="http://technorati.com/tags/relational.%20data%20structure" rel="tag">relational. data structure</a>,<a href="http://technorati.com/tags/abstraction" rel="tag">abstraction</a>,<a href="http://technorati.com/tags/domain%20model" rel="tag">domain model</a>,<a href="http://technorati.com/tags/deseign" rel="tag">deseign</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2008/11/10/refx-orms-relational-data-mismatch-linq-and-dsls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Safety and Correctness is a matter of Mindset Cultured by the Language</title>
		<link>http://sadekdrobi.com/2008/11/02/code-safety-and-correctness-is-a-matter-of-mindset-cultured-by-the-language/</link>
		<comments>http://sadekdrobi.com/2008/11/02/code-safety-and-correctness-is-a-matter-of-mindset-cultured-by-the-language/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 22:27:22 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[D90]]></category>
		<category><![CDATA[Decipline]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[video-portrait]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2008/11/02/code-safety-and-correctness-is-a-matter-of-mindset-cultured-by-the-language/</guid>
		<description><![CDATA[ 
In my trip through Haskell programming I keep discovering how clean and enjoyable the language is. By the end I am someone that loves doing abstractions and I guess I&#8217;ve found my world.
I discussed with some colleagues lately how a programming language creates a whole culture around it. This culture inherits from language properties [...]]]></description>
			<content:encoded><![CDATA[<p><embed src="http://www.youtube.com/v/JAZZpi68C0g" width="425" height="350" type="application/x-shockwave-flash"> </embed>
<p>In my trip through Haskell programming I keep discovering how clean and enjoyable the language is. By the end I am someone that loves doing abstractions and I guess I&#8217;ve found my world.</p>
<p>I discussed with some colleagues lately how a programming language creates a whole culture around it. This culture inherits from language properties and shapes the language programming style.</p>
<p><span id="more-531"></span></p>
<p>Take for example Java; there are a lot of different ways to program in java. The java syntax does not force you to program OOP. It is just more convenient to do so. Same thing goes with other programming languages. However it is not only about paradigm, it is really about a whole mindset.</p>
<p>While programming a web site with Haskell, I was searching for a function that parses a string to return me an int. As I&#8217;ve been for a long time a C#/Java programmer I expected to find a simple function like what I used to use in these language. A function that simply takes a string and produces and int. After a fair search I didn&#8217;t find such a &#8220;simple&#8221; function. I&#8217;ve rather found a function with slightly more complicated/richer signature (type). This function takes a string and returns a list of int-string pairs. This got me thinking, there should be a reason for not offering the simple function I was searching for&#8230;</p>
<p>I quickly started understanding why libraries implementers chose to offer this function with this signature and I did so simply by imagining its use. Imagine that I pass a string that is not the expected type (in our case int) to this <em>reads (stands for read string) </em>function, what would happen? Well in the simple version of C# and Java, the parsing function well throw an <em>exception</em> when passed a string that can not be parsed. In some way, the signature of the function promises me to get always the expected type (in our case an int) as a return of using it but it actually lies! Throwing an unexpected <em>exception</em> comes as a surprise as the signature (the function type) looked extremely kind but behaved irresponsibly unexpectedly when I trusted it. But what about the Haskell version?</p>
<p>Well the type of the Haskell function tells me &#8220;I will try to parse the string passed, and each time I find a fit with your expected type I will return a pair with the value in the expected type and a remaining string that represents what remains&#8221;. So here the function type tells me that it will try to parse and that it will might face several possibilities. There is no lie here, no magic, no false promise, parsing strings can produce several possibilities depending on the parsing method, and that what the function tells me.</p>
<p>I like the no surprise / safe&nbsp; programming culture in Haskell. I guess there are a lot of lessons to be learnt from this style of programming.</p>
<p>PS: Some might call this safe style &#8220;defensive programming&#8221; to make it look rigid, I guess there is no point in calling it so, and I would rather call it communicative programming, no surprise programming, or intention revealing programming. I like DbC!</p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2008/11/02/code-safety-and-correctness-is-a-matter-of-mindset-cultured-by-the-language/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Paradigm based Polyglot Programming</title>
		<link>http://sadekdrobi.com/2008/09/25/paradigm-based-polyglot-programming/</link>
		<comments>http://sadekdrobi.com/2008/09/25/paradigm-based-polyglot-programming/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 07:08:16 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[InfoQ]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[Multi-Paradigm Design]]></category>
		<category><![CDATA[Multi-languages projects]]></category>
		<category><![CDATA[Polyglot Programming]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2008/09/25/paradigm-based-polyglot-programming/</guid>
		<description><![CDATA[ 
How many languages are you using on the same project? If you go counting you will see that they are many. I mean XML, Java, XSLT, HTML, CSS&#8230; etc. But the reason why you are using almost all of them is that they happen to be mainstream and, oftentimes, they are the only language [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sadekdrobi.com/wp-content/uploads/2008/09/dsc-01721.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="429" alt="DSC_0172" src="http://sadekdrobi.com/wp-content/uploads/2008/09/dsc-0172-thumb1.jpg" width="640" border="0"></a> </p>
<p>How many languages are you using on the same project? If you go counting you will see that they are many. I mean XML, Java, XSLT, HTML, CSS&#8230; etc. But the reason why you are using almost all of them is that they happen to be mainstream and, oftentimes, they are the only language choice for a needed framework. You are actually almost obliged to use them. <em>The choice is done for you. Style? CSS. Configuration? Often XML. Web interface description? Html.</em> However, if you want to adopt true polyglot programming, you will have to face inevitable decision of language choice.</p>
<p><span id="more-517"></span></p>
<p><a href="http://www.infoq.com/articles/paradigm-based-polyglot-prog">Read my article on Paradigm based Polyglot Programming at InfoQ.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2008/09/25/paradigm-based-polyglot-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do we actually need Methods in C# 3.0? We just need a powerful function type inference</title>
		<link>http://sadekdrobi.com/2008/09/21/do-we-really-need-methods-in-csharp-3/</link>
		<comments>http://sadekdrobi.com/2008/09/21/do-we-really-need-methods-in-csharp-3/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 22:54:15 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Functional Programming]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2008/09/21/do-we-actually-need-methods-in-c-30-we-just-need-a-powerful-function-type-inference/</guid>
		<description><![CDATA[
The big milestone of C# 3.0 got me thinking, what can we do more to improve the language. After a lot of interesting discussions an debates I got with people that care about the subject, I realized that it can be really interesting to remove some unimportant complexity of the language. This can be done [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sadekdrobi.com/wp-content/uploads/2008/09/dsc-0150.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="367" alt="DSC_0150-" src="http://sadekdrobi.com/wp-content/uploads/2008/09/dsc-0150-thumb.jpg" width="537" border="0"></a></p>
<p>The big milestone of C# 3.0 got me thinking, what can we do more to improve the language. After a lot of interesting discussions an debates I got with people that care about the subject, I realized that it can be really interesting to remove some unimportant complexity of the language. This can be done by abstracting and generalizing some concepts. An example that I thought of for this blog post is Methods.</p>
<p><span id="more-507"></span></p>
<h2>Do we need Methods?</h2>
<p>Why do we need methods at all? For me, in C# 3.0, a method is just a special case of of a property that returns a function as value. What I mean is that this:</p>
<p>public string SayHello(){</p>
<p>return &#8220;Hello&#8221;;<br />} </p>
<p>is identical to</p>
<p>public Func&lt;string&gt; SayHello{<br />get{<br />return ( ) =&gt; &#8220;Hello&#8221;;<br />}<br />}</p>
<p>In functional programming languages, functions are values exactly like int and string. They can be assigned to variables, passed as a parameter and return from other functions. This fits very well with the definition of a method I&#8217;ve just given.&nbsp;&nbsp; So what I am doing here is eliminating the need for the special case of method and using properties of function type instead. The syntax is acceptable (actually I can even argue that it is more readable). Moreover, adopting this approach buys us much more than removing one existing duplication in the language.</p>
<h2>Benefits of generalizing Methods to Properties of function value type</h2>
<p>The first thing I would argue about is readability,&nbsp; I guess it is more readable to describe methods as lambdas, but this can be considered being subjective, so I will rather focus on other practical benefits of the generalization:</p>
<h3>Passing some methods implementations in the constructor:</h3>
<p>Almost one year ago, I asked the C# team whether it can be possible to implement anonymous classes in C#. Anonymous classes ( quite different from Anonymous Types) is a neat feature that allows you to instantiate an instance of a Class that implements a desired contract. With anonymous classes you do not actually need to create the class, you just specify the contract you need to satisfy then you start implementing the logic.</p>
<p>Using our generalization we can do something similar (at least semantically).&nbsp; For Instance we can do:</p>
<p>new HelloWordContract( HelloWorldGreeter= (s=&gt;&nbsp; Console.WriteLine(&#8221;Hello World &#8220;+ s)) );</p>
<h3>Modifying an implementation at runtime only for the instance:</h3>
<p>Manipulating functions exactly like values opens up for a very powerful mechanism of function passing. One very powerful functionality in Ruby is that you can change an instance&#8217;s method implementation at runtime. And that will only mutate the instance&#8217;s implementation and won&#8217;t touch to the class&#8217; definitions. Using our generalization it becomes really easy to implement an extension method that changes the implementation (which is the property value) of a method for an instance.</p>
<p>public static ModifyImplementation&lt;TObject,TFunc&gt;(this TObject object, Func&lt;TObject,TFunc&gt; newFunctionValue){&#8230;} //here I pass the instance value in case needed by the function</p>
<h2>Conclusion</h2>
<p>Improving programming languages is not only about adding features, but it is sometimes about deleting some.&nbsp; I illustrated briefly in this post how we could, with the simple method generalization, benefit from a very powerful use of functions in C#. To support better this approach we still need a better type inference for functions types (delegates) and function types with more parameters ( something like Func&lt;T1,T2,T3,&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.Tn,R&gt;.</p>
<p>&nbsp;</p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:afdfa728-076a-4ede-b7b9-1457f63de1aa" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Mots clÃ©s Technorati : <a href="http://technorati.com/tags/c#" rel="tag">c#</a>,<a href="http://technorati.com/tags/Functional-programming" rel="tag">Functional-programming</a>,<a href="http://technorati.com/tags/meta-programming" rel="tag">meta-programming</a>,<a href="http://technorati.com/tags/method%20generalization" rel="tag">method generalization</a>,<a href="http://technorati.com/tags/functions" rel="tag">functions</a>,<a href="http://technorati.com/tags/type-inference" rel="tag">type-inference</a>,<a href="http://technorati.com/tags/higher-order-functions" rel="tag">higher-order-functions</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2008/09/21/do-we-really-need-methods-in-csharp-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

