<?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; Coding principles</title>
	<atom:link href="http://tore.vestues.no/category/coding-principles/feed/" rel="self" type="application/rss+xml" />
	<link>http://tore.vestues.no</link>
	<description>On a quest for the silver bullet..</description>
	<lastBuildDate>Mon, 26 Jul 2010 12:22:05 +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>Speaking at NDC 2010</title>
		<link>http://tore.vestues.no/2010/04/13/speaking-at-ndc-2010/</link>
		<comments>http://tore.vestues.no/2010/04/13/speaking-at-ndc-2010/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 12:41:57 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Coding principles]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=92</guid>
		<description><![CDATA[I&#8217;m very proud to announce that I will be speaking at the Norwegian Developers Conference 2010 (track 6, day 3, 16:20). 
My talk is named &#8220;A Style of programming&#8221;:
&#8220;This talk describes a set of coding principles that constitutes a style of programming that focuses on ease of coding, ease of changing the code, and ease [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_93" class="wp-caption alignright" style="width: 210px"><img src="http://vestues.no/tore/wp-content/ndc2010.png" alt="Ndc 2010" title="ndc2010" width="200" height="83" class="size-full wp-image-93" /><p class="wp-caption-text">Ndc 2010</p></div>
<p>I&#8217;m very proud to announce that I will be speaking at the <a href="http://www.ndc2010.no/">Norwegian Developers Conference 2010</a> (track 6, day 3, 16:20). </p>
<p>My talk is named &#8220;A Style of programming&#8221;:</p>
<p>&#8220;This talk describes a set of coding principles that constitutes a style of programming that focuses on ease of coding, ease of changing the code, and ease of testing the code. The presentation aims at helping programmers understand how the principles relate to actual code. Every principle is made concrete through examples. This style of programming is influenced by leading object oriented and agile developers, and it is perfect for applying on object oriented languages such as C#.&#8221;</p>
<p>Hope to see you there!</p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2010/04/13/speaking-at-ndc-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</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>0</slash:comments>
		</item>
		<item>
		<title>Understand, don&#8217;t just follow</title>
		<link>http://tore.vestues.no/2009/05/02/understand-dont-just-follow/</link>
		<comments>http://tore.vestues.no/2009/05/02/understand-dont-just-follow/#comments</comments>
		<pubDate>Sat, 02 May 2009 13:52:48 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Coding principles]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Practices]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2009/05/02/understand-dont-just-follow/</guid>
		<description><![CDATA[It still surprises me, and scares me, how many people in our industry that just follow ideas and practices just because &#8220;someone&#8221; says it is the way to go, and how those same people do not understand why they are actually doing it.
Let me give you an example.
When Kent Beck and his extreme programmers started [...]]]></description>
			<content:encoded><![CDATA[<p>It still surprises me, and scares me, how many people in our industry that just follow ideas and practices just because &#8220;someone&#8221; says it is the way to go, and how those same people do not understand <em>why</em> they are actually doing it.</p>
<p>Let me give you an example.</p>
<p>When Kent Beck and his extreme programmers started out (with XP &#8211; extreme programming), they were talking about not writing comments in your code. And they explained what they meant: Comments are often an indication that your code isn&#8217;t readable on its own, the fix is often to write code that is easier to understand, not to add comments.</p>
<p>For me this is great advice. I try to keep my code clean and readable, and when I feel the urge to write comments, I first check if I can make the code more self explainable on its own. I personally write some comments, but never to explain code that looks like crap.</p>
<p>The problem with this advice is that it is actually bad advice if you do not understand <em>why</em> you should follow it. Those that do not understand why they should reduce their amount of comments, but still dig the idea, are probably writing as unreadable code as they always did, but now explaining the mess with even less comments. The result is probably all over worse code than if they didn&#8217;t follow the advice in the first place!</p>
<p>There are at least two lessons to be learned here.</p>
<p>First, if you do not understand <em>why</em> you are doing something, you are probably doing it wrong. It is time to start questioning what you are doing, always ask why.</p>
<p>Second. Say too many people misunderstand the purpose of something, thus applies it wrong, and thus is actually producing worse results than before. In our &#8220;no comment&#8221; example, people would, based on empirical evidence of the practitioners, say that the &#8220;no comment&#8221;-idea is a joke (since most of its followers are actually writing worse code). So by applying the idea wrong you are probably discrediting the whole idea.</p>
<p>I like to define agile in one sentence: &#8220;Ask Why&#8221;. &#8220;Why should we write this piece of documentation?&#8221; &#8220;Why should we follow this process?&#8221; &#8220;Why should we follow this practice?&#8221; If we better understand what we are doing, and can adjust our practices accordingly, I think we will get a long way. I think this is the core of agile.</p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2009/05/02/understand-dont-just-follow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The importance of code that communicates</title>
		<link>http://tore.vestues.no/2009/03/10/the-importance-of-code-that-communicates/</link>
		<comments>http://tore.vestues.no/2009/03/10/the-importance-of-code-that-communicates/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 19:03:51 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Coding principles]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Practices]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2009/03/10/the-importance-of-code-that-communicates/</guid>
		<description><![CDATA[One of the major reasons that our industry produces software that is full of bugs, with a massive cost of change and with a short life expectancy is that developers do not understand the importance of writing code that communicates. Yes, one of the most important aspects of software development is to write code that [...]]]></description>
			<content:encoded><![CDATA[<p>One of the major reasons that our industry produces software that is full of bugs, with a massive cost of change and with a short life expectancy is that developers do not understand the importance of writing code that communicates. Yes, <i>one of the most important aspects of software development is to write code that communicates</i>. </p>
<p><strong>Disclaimer:</strong> There are several reasons software projects fail and many of them are caused by management &#8211; way above the developers. Still, we as developers have to take our part of the blame, and crap code is our contribution to the failure. </p>
<p><strong>It is not about algorithms and performance</strong></p>
<p>I didn&#8217;t learn much about communicative code at the University. And I still do not think people learn a lot about it. Students probably still think that software development is all about performance and effective algorithms. I&#8217;m sorry, often it&#8217;s nothing like that. In most business applications today there are no fancy algorithms. It&#8217;s just a huge amount of code that is trying to express the rules and logic that exist in the business. Performance might be an issue, but it has nothing to do with tweaking algorithms, it&#8217;s about architecture, data loads and sometimes really bad code.</p>
<p><strong>So, what&#8217;s the problem?</strong></p>
<p>The major problem with business applications today is the huge amount of code. The amount is not a problem in itself, but it gets to be a problem very fast when it&#8217;s hard to understand what it does.</p>
<p>Let&#8217;s take a simple example: Methods in today’s software are often way too long. It takes a lot of time to understand 100 lines of code that does several different things, and it&#8217;s even harder to change it without breaking something. I&#8217;ve seen tons of code that looks like that, and I&#8217;ve spent ages fixing such code. Believe me, code like this is very expensive and it will soon be full of bugs. Such software deteriorates pretty fast, and before you know it you&#8217;re at a point where whenever you remove a bug, you add two new ones. We should all be ashamed, honestly.</p>
<p>Code that is hard to understand is hard to change; software that is hard to change will be expensive and slow to change, and the risk of the changes adding new bugs is high. Who wants an application where it costs a fortune to add features, takes forever, and adds new bugs?</p>
<p><strong>It&#8217;s about communication</strong></p>
<p>Yes, it is a mess, but what can you do? We have to understand that writing software is about communication!</p>
<p>Put simple: Code that is easy to understand is easy to change. When it&#8217;s easy to change the risk of introducing bugs is low. That&#8217;s the kind of software your customers want!</p>
<p>Martin Fowler hit the nail on the head when he said:</p>
<blockquote><p>&#8220;Any fool can write code that a computer can understand. Good programmers write programs that humans understand.&#8221;</p></blockquote>
<p><strong>What can I do?</strong></p>
<p>When I write software, my main concern is actually if I am expressing my code in a way that others will be able to understand. And the &#8220;others&#8221; are quite often myself. When I get back to code I wrote two months ago I want it to be really easy to both understand and change that code. </p>
<p>When I have to work with code that is hard to understand I often make it easier to understand first, then make the changes. I keep my methods short. I keep my classes short. I try to organize my code so that related logic is grouped together, and unrelated logic is separated.  I write tests for my code that explains the code. <i>I care about the code I write</i>.</p>
<p><i>Writing code that communicates is first and foremost a mindset. Get it!</i> Then it is a set of practices and principles. Read them, train them and practice them. Find out what works for you. Nothing can replace experience.</p>
<p>Robert &#8220;Uncle Bob&#8221; Martin has written an excellent book on the topic: <a href="http://www.amazon.co.uk/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1235312824&#038;sr=8-1">Clean Code</a>. Read it now! Kent Beck is also passionate about this, and wrote this book: <a href="http://www.amazon.co.uk/Implementation-Patterns-Addison-Wesley-Signature-Kent/dp/0321413091/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1235313000&#038;sr=1-1">Implementation Patterns</a>. </p>
<p>I&#8217;m holding various presentations about what I call Code Quality. Communication is a vital part of that. </p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2009/03/10/the-importance-of-code-that-communicates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Refactoring</title>
		<link>http://tore.vestues.no/2009/01/19/refactoring/</link>
		<comments>http://tore.vestues.no/2009/01/19/refactoring/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 18:54:55 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Coding principles]]></category>
		<category><![CDATA[Practices]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2009/01/19/refactoring/</guid>
		<description><![CDATA[To make it clear: &#8220;Refactoring&#8221; (as the term made famous by Martin Fowler in his great book with the same name), means to change the code without changing its behavior. Too many people talk about refactoring when changing some of the behavior of a system. This interpretation is just plain wrong.
This distinction is not just [...]]]></description>
			<content:encoded><![CDATA[<p>To make it clear: &#8220;Refactoring&#8221; (as the term made famous by Martin Fowler in his great book with the same name), means <i>to change the code without changing its behavior.</i> Too many people talk about refactoring when changing some of the behavior of a system. This interpretation is just plain wrong.</p>
<p>This distinction is not just a play with words, it is important to understand what the practice of refactoring is.</p>
<p>When I stress the importance of the practice of continuously refactoring the code base, it would make no sense if you thought I was talking about changing requirements. When I talk about refactoring and its importance, <i>I talk about code quality</i>.</p>
<p>Refactoring means to enhance the code quality of the system. It is probably the single most important practice to prevent code rot and design debt.</p>
<p>That&#8217;s a major distinction.</p>
<p>Fowler defines refactoring this way: &#8220;a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior&#8221;.</p>
<p>Everyone should know of this practice, understand what it means, and understand its vital effects on the code base.</p>
<p>-Tore</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2009/01/19/refactoring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Looping collections in C#</title>
		<link>http://tore.vestues.no/2008/08/04/looping-collections-in-c/</link>
		<comments>http://tore.vestues.no/2008/08/04/looping-collections-in-c/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 18:32:16 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Bits and bytes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding principles]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2008/08/04/looping-collections-in-c/</guid>
		<description><![CDATA[In this post I want to demonstrate that with a few nice language features in C# we can do more with less when working with collections, meaning expressing more with less code.
There are a couple of points I want to make here. First I care about writing code that can be easily understood after it [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I want to demonstrate that with a few nice language features in C# we can do more with less when working with collections, meaning expressing more with less code.</p>
<p>There are a couple of points I want to make here. First I care about writing code that can be easily understood after it is written. Secondly, I want to express as much as possible with as little as possible. I do not want to write five lines of code if I can express the same thing with just one line of code. These two concerns do of course relate. The keywords here are flexibility and efficiency. And let us not forget writing clean, expressive code is a lot more fun than fiddling with repetitive code: How many times have you written code (more than one line) to loop a collection? And how inspiring is it really? We want to loop those collections as easy as possible.</p>
<p>Languages like Python (and its relatives like Ruby and Boo) has put a lot of effort into making working with collections (or lists) as easy as possible. My main language at work nowadays is C#, and I must admit I envy developers in these languages when it comes to collections.</p>
<p>I actually envy them so much that I&#8217;ve been reflecting on how we can make our lives easier as well. With .Net 3.5 there is actually something we can do about it.</p>
<p><strong>Collections in Python, Ruby and Boo</strong></p>
<p>But first let me show you what I envy.</p>
<p>Let&#8217;s use a simple example to demonstrate my point: We have a list of numbers where we want to make a sub list with all the numbers bigger than 10. In addition, we do of course want to print the sub list to the console.</p>
<p><a href="http://boo.codehaus.org/" title="Boo">Boo</a> (one of the most exiting languages for me these days) will simply do it this way:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">numbers = <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">15</span>,<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">100</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">19</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> numbers.<span style="color: black;">Collect</span> <span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>number <span style="color: #ff7700;font-weight:bold;">as</span> <span style="color: #008000;">int</span>| number<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>In Boo, lists have built in functionality for making sub lists.  I think this code is beautiful. The elegance (and often confusion for C#-developers not familiar with these kinds of languages) is how you declare the conditions for making the sub list. I won&#8217;t go into details about this but what we say here is: for the list &#8220;numbers&#8221;, take each &#8220;number&#8221; and add it to the sub list if &#8220;number&gt;10&#8243;. The print statement is all you need to print the list (in an understandable human form) to the console.</p>
<p>It can&#8217;t be much simpler than this. Although I actually like the Ruby-way of doing this a micro-tad better:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">numbers = <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">15</span>,<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">100</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">19</span><span style="color: black;">&#93;</span>
puts numbers.<span style="color: black;">find_all</span><span style="color: black;">&#123;</span>|number| number<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#125;</span></pre></div></div>

<p>I like the find_all method name a bit better than Collect, and I like that you do not have to say &#8220;as int&#8221;. On the downside the &#8220;puts&#8221;-statement is a bit less intuitive than plain &#8220;print&#8221;. But in the long run these are details (or at least we can pretend it is in this context).</p>
<p>In python you can say it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">numbers = <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">15</span>,<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">100</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">19</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: black;">&#91;</span>number <span style="color: #ff7700;font-weight:bold;">for</span> number <span style="color: #ff7700;font-weight:bold;">in</span> numbers <span style="color: #ff7700;font-weight:bold;">if</span> number <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">10</span><span style="color: black;">&#93;</span></pre></div></div>

<p>Maybe a bit weirder at first glance, but it&#8217;s very concise if you&#8217;re used to it.</p>
<p>Ok, the point of this was to demonstrate that it is actually quite easy to express a loop very compact and elegant, and this is where I want to be when I loop collections in C#.</p>
<p><strong>Looping collections in C#</strong></p>
<p>The &#8220;this will work in almost any language&#8221;-code for doing the same job in C# will look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> numbers <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">15</span>, <span style="color: #FF0000;">7</span>, <span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">5</span>, <span style="color: #FF0000;">19</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span> subset <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> number <span style="color: #0600FF;">in</span> numbers<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>number <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span>
        subset.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>number<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> number <span style="color: #0600FF;">in</span> subset<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    Console.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>number <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>It&#8217;s outright horrible compared to the Boo-example! It makes me wonder how many times longer it takes to develop a C#-application, and how much less readable it will be.</p>
<p>So what can we do? Well, let&#8217;s see if we can make it simpler.</p>
<p><strong>Using delegates</strong></p>
<p>With .Net 2.0, we were introduced to the concept of delegates (function pointers). It&#8217;s an odd concept for the traditional C#/vb/Java-developer. Function pointers are very common in some languages (again, typically in Python and friends), but not in &#8220;our&#8221; languages. Anyway, I&#8217;m really happy that Microsoft introduced us to this as it gives us some interesting possibilities.</p>
<p>We can remove a foreach-loop by using the Array.FindAll-method that takes a delegate. The delegate specifies how to filter the array, and then we have a sub list. This sounds a bit nicer. It looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> numbers <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">15</span>, <span style="color: #FF0000;">7</span>, <span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">5</span>, <span style="color: #FF0000;">19</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> subset <span style="color: #008000;">=</span> Array.<span style="color: #0000FF;">FindAll</span><span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>numbers, 
      <span style="color: #FF0000;">delegate</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> number<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> number <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> number <span style="color: #0600FF;">in</span> subset<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    Console.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>number <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Still a lot of code unfortunately, and the FindAll-method call isn&#8217;t really as clear and simple as it could have been either. I won&#8217;t go into details about the delegate-concept here, but if you do not understand how it works, I really advice you to take a look. It&#8217;s a powerful tool. (Look at my post <a href="http://tore.vestues.no/2007/12/10/delegates-the-interface-for-methods/">Delegates, the interface for methods</a>)</p>
<p><strong>Using extension methods</strong></p>
<p>The fact that you can just write &#8220;print&#8221; in Boo, where I have to write a foreach/Console.Write in C#, annoys me. Let&#8217;s fix it.</p>
<p>We could fix this by creating a subclass of Array, and override the ToString()-method. But frankly I do not like the idea. That would mean that everybody everywhere have to use that subclass instead of the standard Array-class. And that isn&#8217;t going to happen. There must be an easier way, and it is if you are fortunate enough to be working with .Net 3.0 . Here you can add an <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx">Extension Method</a> to the Array-class. Unfortunately you cannot override a method by doing this (i.e. ToString), but you can create new methods on the Array. So let&#8217;s do that.</p>
<p>First the extension method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> ArrayExtension
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Print<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> <span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> list<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> number <span style="color: #0600FF;">in</span> list<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Console.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>number <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</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></div></div>

<p>And then the main code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> numbers <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">15</span>, <span style="color: #FF0000;">7</span>, <span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">5</span>, <span style="color: #FF0000;">19</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> subset <span style="color: #008000;">=</span> Array.<span style="color: #0000FF;">FindAll</span><span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>numbers, 
      <span style="color: #FF0000;">delegate</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> number<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> number <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
subset.<span style="color: #0000FF;">Print</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// extension method</span></pre></div></div>

<p>Look at that. I&#8217;m feeling better now. We&#8217;re getting somewhere.</p>
<p><strong>Using Lambdas</strong></p>
<p>I still do not like the delegate-declaration in the &#8220;FindAll&#8221;-method call. It&#8217;s clumsy, verbose, and not enough to the point. Lambdas introduced in .Net 3.0 will help us simplify this. Read more about lambdas <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx">here</a>. For us, a lambda is just an easy way to declare a delegate. Look at this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> numbers <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">15</span>, <span style="color: #FF0000;">7</span>, <span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">5</span>, <span style="color: #FF0000;">19</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> subset <span style="color: #008000;">=</span> Array.<span style="color: #0000FF;">FindAll</span><span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>numbers, number <span style="color: #008000;">=&gt;</span> number <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">10</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
subset.<span style="color: #0000FF;">Print</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Sweet! When you get used to it (and you should) the lambda-syntax is very easy to read. And look at how we do not have to declare the types anymore. I really like it. There can be a big difference between how you <em>can</em> do things, and how you <em>should</em> do things. I think this is how you <em>should</em> do it.</p>
<p><strong>Using Linq</strong></p>
<p>Actually, .Net introduces another elegant way to do this, Linq. It has quite a different syntax from most other languages with one notable exception: Sql. Linq treats almost anything like a collection that can be queried. Thus link is in itself a little dsl query language. It&#8217;s a great idea, I&#8217;ll give Microsoft that. Anyway, this is how our solution will look if we use Linq:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> numbers <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">int</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">15</span>, <span style="color: #FF0000;">7</span>, <span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">5</span>, <span style="color: #FF0000;">19</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
var subset <span style="color: #008000;">=</span>
    from n <span style="color: #0600FF;">in</span> numbers
    where n <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">10</span>
    select n<span style="color: #008000;">;</span>
&nbsp;
subset.<span style="color: #0000FF;">Print</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// new extension method</span></pre></div></div>

<p>Yes, I like this one too. If you know Sql, and we probably all do, this is very easy to read.</p>
<p>Which one of these two do I like the most? To be honest, I&#8217;m not sure. I like them both. Feel free to give your thoughts on the issue.</p>
<p><strong>Conclusion</strong></p>
<p>To be honest I still like the Python/Ruby/Boo- way a little bit better, but with lambdas or linq I think C# is almost as elegant.</p>
<p>I want to make two points here:</p>
<p>First, it’s important to evaluate how we write code. We should always try to find ways to express more with less, and in this case we have been given several tools to help us on the way. It&#8217;s just up to us to use them, and use them well.</p>
<p>Secondly, do not let a language limit you. Try different languages and look at how they solve problems in different ways. Many times it will inspire you to find new and better ways to use a language, like here where we&#8217;ve applied a little <a href="http://faassen.n--tree.net/blog/view/weblog/2005/08/06/0">pythonic</a> thinking to C#.</p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2008/08/04/looping-collections-in-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Declarative Mindset</title>
		<link>http://tore.vestues.no/2008/07/31/the-declarative-mindset/</link>
		<comments>http://tore.vestues.no/2008/07/31/the-declarative-mindset/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 07:19:36 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Bits and bytes]]></category>
		<category><![CDATA[Coding principles]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2008/07/31/the-declarative-mindset/</guid>
		<description><![CDATA[I&#8217;ve been playing around with web-programming lately, and it&#8217;s interesting to see how a little declarative thinking can help improve your code.
The declarative mindset 
First, let me specify my viewpoint: My interest in declarative programming is not primarily from a programming language point of view (at least not in this context). I care about it [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with web-programming lately, and it&#8217;s interesting to see how a little declarative thinking can help improve your code.</p>
<p><strong>The declarative mindset </strong></p>
<p>First, let me specify my viewpoint: My interest in declarative programming is not primarily from a programming language point of view (at least not in this context). I care about it from a <em>programming mindset</em> point of view.</p>
<p>The easiest way to define declarative programming is to say it cares about <strong><em>what</em> to do, not <em>how</em> to do it</strong>. There is more to declarative programming (and the languages) then that, but for me this captures the essence, and this is the kind of thinking that can help improve our code.</p>
<p><strong>Example</strong></p>
<p>Let me start off with a little example. Let&#8217;s make a menu bar in Html.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text-align:right;</span>
<span style="color: #009900;">    background-color:#dddddd;</span>
<span style="color: #009900;">    padding-top:2px;</span>
<span style="color: #009900;">    padding-bottom:2px;</span>
<span style="color: #009900;">    padding-right:4px;</span>
<span style="color: #009900;">    border: 1px solid #666666;&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;home.html&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color:#666666;</span>
<span style="color: #009900;">    font-weight: bold;</span>
<span style="color: #009900;">    text-decoration:none;</span>
<span style="color: #009900;">    padding-left:6px;</span>
<span style="color: #009900;">    padding-top:2px;</span>
<span style="color: #009900;">    padding-bottom:2px;</span>
<span style="color: #009900;">    BORDER-LEFT: #666666 1px solid;</span>
<span style="color: #009900;">    text-decoration: underline;&quot;</span>&gt;</span>home<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;login.html&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color:#666666;</span>
<span style="color: #009900;">    font-weight: bold;</span>
<span style="color: #009900;">    text-decoration:none;</span>
<span style="color: #009900;">    padding-left:6px;</span>
<span style="color: #009900;">    padding-top:2px;</span>
<span style="color: #009900;">    padding-bottom:2px;</span>
<span style="color: #009900;">    BORDER-LEFT: #666666 1px solid;&quot;</span>&gt;</span>log in<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;news.html&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color:#666666;</span>
<span style="color: #009900;">    font-weight: bold;</span>
<span style="color: #009900;">    text-decoration:none;</span>
<span style="color: #009900;">    padding-left:6px;</span>
<span style="color: #009900;">    padding-top:2px;</span>
<span style="color: #009900;">    padding-bottom:2px;</span>
<span style="color: #009900;">    BORDER-LEFT: #666666 1px solid;&quot;</span>&gt;</span>news<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;contact.html&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color:#666666;</span>
<span style="color: #009900;">    font-weight: bold;</span>
<span style="color: #009900;">    text-decoration:none;</span>
<span style="color: #009900;">    padding-left:6px;</span>
<span style="color: #009900;">    padding-top:2px;</span>
<span style="color: #009900;">    padding-bottom:2px;</span>
<span style="color: #009900;">    BORDER-LEFT: #666666 1px solid;&quot;</span>&gt;</span>contact<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Html is a declarative language in itself, so this is by default declarative. But strict a definition isn&#8217;t very useful here. I want to improve my coding, not adhere to a definition. So let&#8217;s try to improve this code with thinking &#8220;<em>What</em> to do, not <em>how</em> to do it&#8221;. <em>What</em> do I really want to do here? I simply want to make a menu bar with clickable items. Nice. And this code tells me nothing about <em>how</em> I do it? Well, it actually does. It tells me quite a lot about how it is supposed to look.</p>
<p>Let&#8217;s use a separate css-file to extract the &#8220;how it looks&#8221;-part from my declarative menu bar-code.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;menuline&quot;</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;home.html&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;current&quot;</span>&gt;</span>home<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;login.html&quot;</span>&gt;</span>akvareller<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>log in<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;news.html&quot;</span>&gt;</span>news<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;contact.html&quot;</span>&gt;</span>contact<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>That&#8217;s better. Now there is not much &#8220;How&#8221; left in my menu declaration. It&#8217;s mostly &#8220;What&#8221;: A menu bar with clickable items.</p>
<p>Notice that the css-part is also by itself declarative in the strict definition, but for our usage that information is not declarative when we want to define the &#8220;what&#8221;-part of the menu bar.  Again, the important thing here is not to define what declarative really means in programming language terms. The important thing is to see how it makes us think when we code, and how that mindset affects the code.</p>
<p><strong>Advantages</strong></p>
<p>This is of course a trivial example, and most of us already separate a lot of looks-code into css-files, maybe even without reflecting on why. My point here is not to talk about how to best use css-files. My point is to reflect on what this &#8220;declarative mindset&#8221; actually does in a broader sense. In my opinion, it has several positive effects on the code, including:</p>
<ul>
<li> Readability
<ul>
<li>The second coding example is easier to understand than the first. Frankly, the first example is a bit of a nightmare. Code that is easy to understand is flexible because it is easy to change. And let&#8217;s face it, it makes a developers life better. We all know that code that is hard to understand is hard to work with.</li>
</ul>
</li>
<li>Ease of use
<ul>
<li>It should be easy to write code.  Writing the &#8220;what&#8221;-part of the menu bar certainly is easier in the second example than the first. It&#8217;s easy to write new code, and it&#8217;s easy to change the code. Even the &#8220;How it looks&#8221;-part of the code will be easier in the second example. It&#8217;s tidier.</li>
</ul>
</li>
<li>Separation of Concern
<ul>
<li>This is one of the fundamental design principles in programming. In our example what we have done is actually to separate the &#8220;What&#8221;-part from the &#8220;How&#8221;-part. Thinking this way makes us automatically separate concerns.</li>
</ul>
</li>
<li>Reusability
<ul>
<li>Of course, factoring out all the looks of a menu bar makes that look easy to reuse elsewhere.</li>
</ul>
</li>
</ul>
<p><strong>Taking it further</strong></p>
<p>To be honest, I&#8217;m still not satisfied with the html-code defining the menu bar. Still there are some list item-tags there that really don&#8217;t say anything about what this is. I&#8217;m actually also a bit skeptical to the a-tag as it is a bit too technical to clearly define the &#8220;What&#8221; of this menu.</p>
<p>I want to take it further. Now I want the declarative mindset to help me think more in terms of concepts and abstractions. That is what this is about. The more I speak in general terms, in concepts and abstractions, the more I focus on &#8220;What to do&#8221;. The more technical it gets the more I focus on &#8220;How to do it&#8221;.</p>
<p>Let&#8217;s implement this in Asp.Net and see if we can get any further:</p>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #006600; font-weight: bold;">&lt;</span>menu<span style="color: #006600; font-weight: bold;">:</span>Menubar runat<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;server&quot;</span> ID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;menu&quot;</span><span style="color: #006600; font-weight: bold;">&gt;</span>
  <span style="color: #006600; font-weight: bold;">&lt;</span>menu<span style="color: #006600; font-weight: bold;">:</span>MenuItem Title<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;home&quot;</span> TargetPage<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;home.html&quot;</span><span style="color: #006600; font-weight: bold;">/&gt;</span>
  <span style="color: #006600; font-weight: bold;">&lt;</span>menu<span style="color: #006600; font-weight: bold;">:</span>MenuItem Title<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;log in&quot;</span> TargetPage<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;login.html&quot;</span><span style="color: #006600; font-weight: bold;">/&gt;</span>
  <span style="color: #006600; font-weight: bold;">&lt;</span>menu<span style="color: #006600; font-weight: bold;">:</span>MenuItem Title<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;news&quot;</span> TargetPage<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;news.html&quot;</span><span style="color: #006600; font-weight: bold;">/&gt;</span>
  <span style="color: #006600; font-weight: bold;">&lt;</span>menu<span style="color: #006600; font-weight: bold;">:</span>MenuItem Title<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;contact&quot;</span> TargetPage<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;contact.html&quot;</span><span style="color: #006600; font-weight: bold;">/&gt;</span>
<span style="color: #006600; font-weight: bold;">&lt;/</span>menu<span style="color: #006600; font-weight: bold;">:</span>Menubar<span style="color: #006600; font-weight: bold;">&gt;</span></pre></div></div>

<p>Remember what we wanted to do? &#8220;I simply want to make a menu bar with clickable items&#8221;. This code does exactly that, and nothing more. The menu bar has a type that defines everything about its look; the items have a title and a place to go to if they are clicked. That&#8217;s all. Now we really describe concepts. The technical &#8220;How&#8221;-part is completely in the background. The technical details will of course have to be implemented somewhere, but here is the beauty of separation of concern: It is to be implemented <em>somewhere else</em>. When we work with this part of the code, we do not have to worry about it. When we work with that part of the code we do not have to worry about this part of the code.</p>
<p>Bear in mind that this is a mindset and not a language-thing. Separation the &#8220;<em>what&#8221;</em> from the &#8220;<em>how</em>&#8221; can be done in any language.</p>
<p>The funny thing about the declarative mindset is that the resulting code looks quite like code that a good object oriented mindset would create. Come to think of it, that&#8217;s probably why I like it so much in the first place.</p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2008/07/31/the-declarative-mindset/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Reusability is not an issue</title>
		<link>http://tore.vestues.no/2008/05/22/reusability-is-not-an-issue/</link>
		<comments>http://tore.vestues.no/2008/05/22/reusability-is-not-an-issue/#comments</comments>
		<pubDate>Thu, 22 May 2008 17:24:59 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Coding principles]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2008/05/22/reusability-is-not-an-issue/</guid>
		<description><![CDATA[Reuse is one of the often mentioned  features, or advantages, of object oriented programming (OOP). Although I am a diehard fan of OOP, I must admit: We failed with reusability. It doesn&#8217;t work the way we were promised. Implementing reusability the way people traditionally tend to think of reuse, is very hard and time [...]]]></description>
			<content:encoded><![CDATA[<p>Reuse is one of the often mentioned  features, or advantages, of object oriented programming (OOP). Although I am a diehard fan of OOP, I must admit: <em>We failed with reusability</em>. It doesn&#8217;t work the way we were promised. Implementing reusability the way people traditionally tend to think of reuse, is very hard and time consuming. The idea that the possibility to reuse just appears if we object orient our system right, is just plain wrong. Implementing reuse is seldom done with success. And the main problem is that the idea that everything should be reusable misleads us to make wrong design decisions, making us over-generalize everything, hoping that we one day can harvest the values of reuse, which we never do.</p>
<p>That being said, I have realized that there is something about reusability that OOP is very good at, it&#8217;s just that we have been a bit mislead about the general conception of what reusability really is.</p>
<p><strong>The classical definition of <em>Reusability</em></strong></p>
<p>Traditionally, reuse has been about the reuse of components. Big components. And typically third-party components. Precompiled, general purpose components to solve every task. This is reusability at an architectural level. In a not so far past, when OO-technologies emerged, the industry were dreaming about a future where programming was reduced to assembling standardized components. Now that would have been something! But as we all know, it just didn&#8217;t happen.</p>
<p>Still many people believe in this classical idea of &#8220;the grand reuse&#8221; at some level, but most of the time it just doesn&#8217;t work.</p>
<p>It&#8217;s time to say: <em>Reusability is not an issue</em>. At least not this kind of reusability. Most projects should not spend good time and money on generalizing everything just a bit more, hoping to get some value from reusability somewhere in the future. Because most often, you won&#8217;t.</p>
<p><strong>The actual reuse in OO-systems</strong></p>
<p>So, what&#8217;s my take on reusability? Reuse happens a lot! Or at least it should. But it is all happening at the code level. As a developer you reuse when you refactor out common functionality. If your code is called from more than one place, it is being reused. Reuse is the opposite of copying code. Reuse is about factoring out common functionality. Reuse is about writing less code. This should be in the back of every developer&#8217;s head at all times. Reuse should just happen. When it comes to this kind of reuse, OO is an excellent tool. Good OO systems implements a lot of reuse. Good developers reuse a lot.</p>
<p>It&#8217;s time for business to stop believing the hype, and to start realizing that it&#8217;s the quality of their developers that really matters. It&#8217;s the developers that implement reuse, and produce the values of it in form of less code, better quality, and more flexible code.</p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2008/05/22/reusability-is-not-an-issue/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trustworthy methods</title>
		<link>http://tore.vestues.no/2008/03/14/trustworthy-methods/</link>
		<comments>http://tore.vestues.no/2008/03/14/trustworthy-methods/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 18:51:27 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Coding principles]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2008/03/14/trustworthy-methods/</guid>
		<description><![CDATA[What constitutes a great method? It&#8217;s a method you can trust, a method that you understand by looking at its name, and it doesn&#8217;t have nasty side effects. It&#8217;s about software quality, and about spending less time coding defensively. Our methods should be trustworthy so that writing code gives us &#8220;least surprise, least paranoia&#8221; (coined [...]]]></description>
			<content:encoded><![CDATA[<p>What constitutes a great method? It&#8217;s a method you can trust, a method that you understand by looking at its name, and it doesn&#8217;t have nasty side effects. It&#8217;s about software quality, and about spending less time coding defensively. Our methods should be trustworthy so that writing code gives us &#8220;least surprise, least paranoia&#8221; (coined by <a href="http://www.flexwiki.com/default.aspx/FlexWiki/Good%20Citizen.html?diff=y">the good citizen-pattern</a>). <em>We want to write trustworthy code that is easy to interact with</em>. Here are my guidelines for producing trustworthy methods.</p>
<p><strong>Communication</strong></p>
<p>The more I write code, the more I realize that understandability is one of the key aspects of writing code. Making myself understood. Writing readable code. In his book &#8220;Implementation Patterns&#8221;, Kent Beck identifies &#8220;Communication&#8221; as one of the three values &#8220;consistent with excellence in programming&#8221;.</p>
<p>We should spend more time thinking about what we want to communicate when we write code.</p>
<p>When it comes to naming methods, my rule of thumb is that <em>you&#8217;re not supposed to have to look into a method in order to understand how to use it</em>. By looking at the method name, maybe it&#8217;s parameters and return value, and considering its context (the class that encapsulates it), I should clearly understand what the method will do for me.</p>
<p><strong>Communicate intent, and intent only</strong></p>
<p>A good method name should communicate intent: What service do I offer, what will I do for you. On a collection-class, a method like</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">sort<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>communicates it&#8217;s intent well. Given the concept of a collection, we understand that this will sort the items. Now what about this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">sortUsingQuickSort<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Still we communicate intent, but there are two problems here. We now have to consider <em>how</em> we want to sort the collection when we call this method. Wouldn&#8217;t it be better if the collection made this decision itself? The collection should be in a much better position to make that choice. And often we do not care about how, we just want it done. It&#8217;s important to make the choices as easy as possible for the consumer of your methods.</p>
<p>The second problem is that we reveal implementation details. In many cases this method says to much about the inner workings of it&#8217;s class. A well designed object oriented class, reveals as little as possible about it&#8217;s implementation details. We do not want to give away that information because we reserve the right to change the implementation of the sorting later.</p>
<p><strong>No surprises<br />
</strong></p>
<p>A method should do exactly what it tells me it will do. Nothing more, nothing less. There shall be absolutely no surprises! Consider this method on a collection:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span> size<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>I&#8217;m sure we all expect this method to return the number of elements in the collection. So if this method actually removed the last element in the collection, that would have been quite a surprise! And of course that would have been a recipe for disaster. Because &#8220;all surprises in our industry are bad surprises&#8221; (I think Kevlin Henney phrased that one).</p>
<p>This case is obvious, but believe me, I have seen some pretty nasty side effects in methods. Such side effects often appear when you do not consider what the method is supposed to do in general terms, you only think about what it will do for you right now. For instance if this collection-class for the moment only was used one place in your code, and you were two hours from deadline and needed this to work, instead of implementing a queue with a dequeue-method, you just removed the last element in the size()-method. Maybe something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Warning: example of stupid code </span>
<span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>collection.<span style="color: #0000FF;">size</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">&gt;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> 
  handleElement<span style="color: #000000;">&#40;</span>collection.<span style="color: #0000FF;">getLast</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This is not the best example because the stupidity of this is so obvious, but there are lots and lots of similar examples that are more subtle but still just as stupid.</p>
<p>Make your methods as trustworthy as possible, do what you promise, but absolutely nothing more. State the intent, and stick to it.</p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2008/03/14/trustworthy-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keep it Simple, Stupid!</title>
		<link>http://tore.vestues.no/2007/10/06/keep-it-simple-stupid/</link>
		<comments>http://tore.vestues.no/2007/10/06/keep-it-simple-stupid/#comments</comments>
		<pubDate>Sat, 06 Oct 2007 09:02:36 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Coding principles]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2007/10/06/keep-it-simple-stupid/</guid>
		<description><![CDATA[Did you hear the story where NASA spent millions of dollars inventing a pen that would work in space, while the Russians simply used the pencil? (if not, read it here: The billion-dollar space pen myth). Allthough Nasa made a technologicaly extremely advanced pen (probably with all the hottest new technologies), and the russians didn&#8217;t really make a [...]]]></description>
			<content:encoded><![CDATA[<p>Did you hear the story where NASA spent millions of dollars inventing a pen that would work in space, while the Russians simply used the pencil? (if not, read it here: <a target="_blank" href="http://www.thespacereview.com/article/613/1">The billion-dollar space pen myth</a>). Allthough Nasa made a technologicaly extremely advanced pen (probably with all the hottest new technologies), and the russians didn&#8217;t really make a pen at all (just &#8220;reusing&#8221; the pencil), it is the russians that are the real geniuses in this story. Why is that?</p>
<p>Because allthough it is important to be able to solve technologically complex problems, the genius is to find solutions that helps us remove complexity.</p>
<p><em>“Fools ignore complexity; pragmatists suffer it; experts avoid it; geniuses remove it.”</em> &#8211; Alan Perlis </p>
<p><strong>Keep It Simple, Stupid!</strong> </p>
<p>&#8220;What is the simplest thing that could possibly work?&#8221; is Kent Beck&#8217;s (and XP&#8217;s) matra. The question truly captures the essence of avoiding over-engineering.</p>
<p>In software development, &#8221;keeping it simple&#8221; is important for several reasons: Developing complex code takes time, it is harder to get right, and might be harder to debug. Complex code is also harder to understand, and complex code often means more code. More code means more places for bugs to appear, and more code takes more time to understand. Complex code is often very hard to maintain.</p>
<p><strong>Essencial versus accidental complexity</strong> </p>
<p>Ok, there are complex problems that require complex solutions. These problems must of course  be treated as such. But it&#8217;s important to identify and remove what Kevlin Henney reffered to as &#8220;accidental complexity&#8221; in his talk &#8220;With economy and elegance&#8221; at Jaoo (jaoo.dk) in september 2007. The essence if it was that not all complexity comes from necessity. Sometimes it just comes from &#8220;cleverness&#8221;: &#8221;code by über-programmers is often based on speculative generality and gratuitous use of advanced techniques and language features&#8221;.</p>
<p><strong>J2EE and Spring</strong></p>
<p>A great example of removing complexity is Spring. Rod Johnson identified a problem: J2EE projects are often over-engineered, and J2EE with EJB is a heavyweight framework with lots of complexity. In his book &#8220;J2EE development without EJB&#8221; he simply states: &#8220;There <em>are</em> simple problems&#8221;. Not saying every problem is simple, but the problem with J2EE was basically that it said that all problems where complex. His solution was to remove complexity and over-engineering, and from that emerged Spring. No need to say that Spring is the prefered framework for web development on the Java platform today.</p>
<p>- Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2007/10/06/keep-it-simple-stupid/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
