<?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>Tore Vestues blogs &#187; Architecture</title>
	<atom:link href="http://tore.vestues.no/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://tore.vestues.no</link>
	<description>On a quest for the silver bullet..</description>
	<lastBuildDate>Sun, 19 Jun 2011 19:34:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rethinking web architecture</title>
		<link>http://tore.vestues.no/2011/06/19/rethinking-web-architecture/</link>
		<comments>http://tore.vestues.no/2011/06/19/rethinking-web-architecture/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 19:26:09 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=160</guid>
		<description><![CDATA[Last year I was a speaker at NDC for the first time, and I'm proud to again have been given the opportunity at this years NDC. The presentation this year is titled: “When less is more - Agile web architecture”, and I did together with Jonas Follesø.
]]></description>
			<content:encoded><![CDATA[<p>Last year I was a speaker at NDC for the first time, and I&#8217;m proud to again have been given the opportunity at this years NDC. The presentation this year is titled: “When less is more &#8211; Agile web architecture”, and I did together with <a href="http://jonas.follesoe.no/">Jonas Follesø</a>.</p>
<p><strong>Rethinking thinking</strong> </p>
<p>Rather than talking about rethinking web architecture, we are actually talking about rethinking our thinking and practices when designing web architecture. So, although we do give a concrete example, this is not <em>the one</em> new architecture. The main points we&#8217;re trying to convey is that you should keep it simple (often much simpler than we normally do) and that architecture should evolve (adding only when you have to, when you have to). The example shows one way of doing that.</p>
<p><strong>Growing architecture</strong></p>
<p>Letting software and architecture grow as we learn is for me simply being agile, but my experience tells me that although most of us consider ourselves agile, we have a hard time wrapping our heads around what that actually means when it comes to architecture. Being agile when it comes to architecture, and being able to grow good architecture takes a lot of skill and knowledge, and let it be clear that when we talk about simplicity we do not say throw away <em>everything</em>. We say reflect on every choice you make.</p>
<p><strong>Developer productivity</strong></p>
<p>Our presentation also take a critical look at the typical three layer architecture which, a bit to my surprise, was known and used by almost everyone in the audience. The critique is mostly about productivity, or rather the lack of it. Pushing data through such an architecture is often a pretty costly affair. An interesting point is also that with this architecture we violate the DRY principle at least ten times for every piece of information in the system (that is stored in the database). I spend a few minutes explaining that one. Have a look yourself.</p>
<p>Some of the feedback we got after the presentation suggests that this talk have sparked a few discussions. That is great!</p>
<p><a href="http://ndc2011.macsimum.no/SAL2/Onsdag/1500-1600.wmv">You can watch the presentation here</a>.</p>
<p><a href="http://ndc2011.no/">The NDC 2011 website is here</a>.</p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2011/06/19/rethinking-web-architecture/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://ndc2011.macsimum.no/SAL2/Onsdag/1500-1600.wmv" length="424690686" type="video/x-ms-wmv" />
		</item>
		<item>
		<title>Tell, don&#8217;t ask</title>
		<link>http://tore.vestues.no/2009/08/16/tell-dont-ask/</link>
		<comments>http://tore.vestues.no/2009/08/16/tell-dont-ask/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 17:43:29 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Coding principles]]></category>
		<category><![CDATA[Practices]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2009/08/16/tell-dont-ask/</guid>
		<description><![CDATA[Tell, don&#8217;t ask is a way of thinking when you&#8217;re programming software, a mindset. It is something that should be in the back of your head every time you write a line of code, or a chunk of code that describes some functionality. It is not something you merely apply when trying to solve a [...]]]></description>
			<content:encoded><![CDATA[<p><em>Tell, don&#8217;t ask</em> is a way of thinking when you&#8217;re programming software, a mindset. It is something that should be in the back of your head every time you write a line of code, or a chunk of code that describes some functionality. It is not something you merely apply when trying to solve a particular problem, it is something you apply all the time.</p>
<p>It is about how your entities communicate, it is about where you place your logic. It is about where to place the code. And when you are programming you are putting code somewhere all the time. That means this is one of the fundamental things to learn as a developer.</p>
<p><strong>So, what is it?</strong></p>
<p>The phrasing itself means that you should tell other objects to do things, instead of asking other objects for information and processing it yourself. (&#8221;you&#8221; are of course an object in this case).</p>
<p><strong>Example: The car dealer</strong></p>
<p>Say you&#8217;re making software for a car dealer. You want to create a report that lists all cars for sale that can be distributed to the customers.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ForSaleReport
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> List<span style="color: #008000;">&lt;</span>Car<span style="color: #008000;">&gt;</span> allCars<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> ForSaleReport<span style="color: #000000;">&#40;</span>List<span style="color: #008000;">&lt;</span>Car<span style="color: #008000;">&gt;</span> allCars<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">allCars</span> <span style="color: #008000;">=</span> allCars<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> List<span style="color: #008000;">&lt;</span>Car<span style="color: #008000;">&gt;</span> GetAllCarsForSale<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> allCars.<span style="color: #0000FF;">FindAll</span><span style="color: #000000;">&#40;</span>car <span style="color: #008000;">=&gt;</span> car.<span style="color: #0000FF;">SoldDate</span> <span style="color: #008000;">!=</span> DateTime.<span style="color: #0000FF;">MinValue</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><em>There is a violation of &#8220;Tell, don&#8217;t ask&#8221; right there</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">car.<span style="color: #0000FF;">SoldDate</span> <span style="color: #008000;">!=</span> DateTime.<span style="color: #0000FF;">MinValue</span></pre></td></tr></table></div>

<p>You <em>ask</em> for information (the cars SoldDate), then make a calculation based on it (calculating if the car is for sale). So, what should you have done? You should <em>tell</em> the Car-object to resolve if it is for sale. It is not your concern to figure it out (when you are in the ForSaleReport), your only concern is to list out cars that are for sale, not why or how they are. So, instead of trying to figure things out yourself, you should just ask the car:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">car.<span style="color: #0000FF;">IsForSale</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><img src='http://vestues.no/tore/wp-content/istock_000002694919xsmall_adjusted_smaller.jpg' alt='Head in the sand' style='float:right'/> <strong>Be ignorant</strong></p>
<p>It is easier to apply <em>Tell, don&#8217;t ask</em> if you think of your objects as ignorant. You give them a responsibility, and beyond that they should be totally ignorant. Always ask someone else to solve the problems. This makes them ask less questions. Asking less questions means less coupling. Only caring for a single concern means higher cohesion.</p>
<p><strong>And if I don&#8217;t .. ?</strong></p>
<p>Didn&#8217;t you see the major difference between the two (asking for the SoldDate versus telling the car to figure out if it IsForSale)? Well, there is a difference, and normally it doesn&#8217;t take long before it shows.</p>
<p>Say you ask for the SoldDate (thinking <em>Tell, don&#8217;t ask</em> are for stupid programmers that wouldn&#8217;t understand as advanced logic as yourself..). And  say that since this application is growing big you ask for SoldDate several places to resolve if the car is for sale (I&#8217;ve seen systems where asking for such &#8220;innocent&#8221; information is done hundreds of places). Then one day the owner of the car dealership comes to you, quite agitated, telling you that your reports are plain wrong: &#8220;A car doesn&#8217;t have to be for sale even though the sales date is not set. It can be held of or be in for repair. Fix it now!&#8221;</p>
<p>Hm, now you have to search for all the places where you did your &#8220;innocent&#8221; information asking, changing it everywhere, and test it to see if you broke something else. Pray that you do not have any indirect references to SoldDate (getting it from a car and sending it away for processing further away), that would be hell to track down. Wouldn&#8217;t it be better if you just had to change the logic in one place? in Cars &#8220;IsForSale&#8221; method? I would think so.</p>
<p>And that is not the only problem. Opening up a class, exposing information (like SoldDate in this case) makes it easier for other classes to hard wire itself to the class. This means more coupling, and more coupling means that the class will be harder to change. In this case, there is no way you easily can change the representation of SoldDate within Car. If you want to change it, you have to change every class that refers to it. This might be a very tedious task.</p>
<p>Another problem, which might not be so obvious since there is no &#8220;principle&#8221; attached to it, is the developer experience: How easy it is to write code in this system. I find this an important issue, and a bit underestimated at times. This is important because it has to do with productivity. When writing new code for this system, and you have to find out if the car is sold or not, it would be much easier just to write &#8220;car.IsSold()&#8221;, then it would be to actually have to find out how to calculate it, and then implement it (find somewhere else in the code that calculates it, copying that code, and so on&#8230;). Figuring out if a car is sold or not should be done once. When it is figured out and implemented, everyone else should just reuse that logic, never again caring for how it is implemented (unless of course, you have to fix or change something in that logic).</p>
<p><strong>Conclusion</strong></p>
<p>For me, <em>Tell, don&#8217;t ask</em> brings with it several realizations about programming:</p>
<ul>
<li>It is important to think about your modelling when you write code. Where you put your code has major implications on your softwares maintainability.</li>
<li>Modelling isn&#8217;t just for &#8220;architects&#8221;. As a developer you make decisions every day that can make or break the software.</li>
<li>Focus on responsibilities, and who should be concerned with what. This makes your application more cohesive and less coupled.</li>
<li>Don&#8217;t repeat yourself (DRY). <em>Tell, don&#8217;t ask</em> helps you put logic one place (where its concern is handled) instead of scattering and copying it all around.</li>
<li>When modelling, it is also important to consider how easy it is to read and use the code for the developers.</li>
</ul>
<p>So, if there is only one thing you want to keep in the back of your head when programming, I suggest it is <em>Tell, don&#8217;t ask</em>.</p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2009/08/16/tell-dont-ask/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

