<?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>Fluid Code</title>
	<atom:link href="http://blog.refactoringin.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.refactoringin.net</link>
	<description>A blog about refactoring, .Net and all things agile by Danijel Arsenovski</description>
	<lastBuildDate>Sun, 02 May 2010 01:16:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The truth about CMMI certification: It does not exist!</title>
		<link>http://blog.refactoringin.net/?p=145</link>
		<comments>http://blog.refactoringin.net/?p=145#comments</comments>
		<pubDate>Sun, 02 May 2010 01:11:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[certification]]></category>
		<category><![CDATA[cmmi]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=145</guid>
		<description><![CDATA[one can not but wonder how come that some agile circles were not able to avoid the certification trap, when even some of the organizations that inspired the whole movement, were smarter than that?]]></description>
			<content:encoded><![CDATA[<p>No matter where you look, everyone talking about CMMI will sooner or later mention the “c” word. Even Google, when you enter “CMMI” as a search term will try to help you by presenting “CMMI Certification” as a related search.</p>
<p>No wonder your surprise to learn that such thing ,as a CMMI Certification, does not exits! Software Engineering Institute (SEI) of Carnegie Mellon  University issues a meager &#8220;appraisal&#8221;. Well, you might say, appraisal, certification what&#8217;s the difference? In the end, it&#8217;s the same thing and to reason to make a fuss about it.</p>
<p>Let&#8217;s see what does SEI has to say about it:</p>
<p><em>&#8220;The SEI does not certify the results of any appraisal nor is there an official accreditation body for CMMI. True certification of appraisal results would involve the ongoing monitoring of organizations’ capabilities, a shelf life for appraisal results, and other administrative elements. When an organization is appraised against the CMMI model, their Lead Appraiser’s findings may indicate that the organization is operating at a particular “maturity level.” The SCAMPI appraisal method maturity ratings are 1 through 5.</em></p>
<p><em>The SEI does not have a defined requirement for periodic follow-up after appraisals, nor does it accept legal responsibility for the performance of appraised organizations. All of these characteristics are required for a program that would provide certification of appraisal results. However, CMMI Appraisal results do expire after a period of three years.&#8221;</em></p>
<p>Source: <a href="http://www.sei.cmu.edu/cmmi/start/faq/appraisals-faq.cfm">SEI website</a></p>
<p>While difference is subtle, it is by no means innocuous, as it is explained clearly on the SEI website. SEI does not accept any legal responsibility for performance of companies they awarded appreciation report nor does it monitor them directly.</p>
<p>As you can see, the choice of words was not random, but carefully made. No reason then to be surprised by <a href="http://stackoverflow.com/questions/65296/does-anyone-still-believe-in-the-capability-maturity-model-for-software">reports </a>(and <a href="http://stackoverflow.com/questions/1927004/does-a-process-like-cmmi-really-helps-a-project">here</a>) where companies that get CMMI &#8220;Certified&#8221; use only one department or team on order to get the logo, where companies after certification soon go back to old ways, where only motivation they have is winning a contract or a tender etc. Ever heard of the LCPBCs? If not you can google it, I will not spoil the fun <img src='http://blog.refactoringin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>In the end, one can not but wonder how come that some agile circles were not able to avoid the certification trap, when even some of the organizations that inspired the whole movement, were smarter than that?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=145</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>It’s NOT OK to cut corners, but it’s OK to cut features.</title>
		<link>http://blog.refactoringin.net/?p=139</link>
		<comments>http://blog.refactoringin.net/?p=139#comments</comments>
		<pubDate>Mon, 15 Feb 2010 15:49:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=139</guid>
		<description><![CDATA[It’s NOT OK to cut corners, but it’s OK to cut features.
I guess that sums a great deal that agile development is all about!]]></description>
			<content:encoded><![CDATA[<p>Just had my say in a discussion on <a href="http://www.linkedin.com/groups?gid=43315">LIDNUG </a>group on LinkedIn. The question put for discussion was “Is it ok to cut corners to meet a deadline?”. Most of answers (or at least the way I interpreted them) say that you generally shouldn’t, but that sometimes you just might have to compromise, especially if that can be justified from business point of view. I think that from agile point of view, the reply is quite obvious. Here is what I had to say:</p>
<h2>It’s NOT OK to cut corners, but it’s OK to cut features.</h2>
<p>I guess that sums a great deal that agile development is all about! You do very short iterations but you do them properly (no cutting corners). Once you start with new iteration, your client can invent new, eliminate old, reprioritize all features etc. (This is what I actually mean by “cutting features”.) As it happens, most of the time the client will realize that some features are not needed, that other are, and will accept that he can live without “nice to have” as long as the core features are done right and without bugs. As a matter of fact, it is difficult (no to say impossible) to know all the features you will need right at the start of the project. So, why should you cut corners to deliver a feature you are not even sure it’s needed? This doesn’t necessarily have to do with 80-20 rule, it’s more of looking at the software as the “work in progress”. You can release the first version once you have implemented the minimum set of core features that do something useful.</p>
<p>Once you and the client change the mentality from “features initially put into the contract” to “real business value delivered”, you will have no need to cut corners. Switching to short iterations and having users participate in planning and accepting results of each feature had a profound effect on how my team is operating and had enabled us to really uphold the quality aspect of software.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=139</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SOLID design principles explained</title>
		<link>http://blog.refactoringin.net/?p=137</link>
		<comments>http://blog.refactoringin.net/?p=137#comments</comments>
		<pubDate>Tue, 29 Dec 2009 01:06:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Robert C. Martin]]></category>
		<category><![CDATA[SOLID]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=137</guid>
		<description><![CDATA[Take a look at this post at lostechies.com.
Good one   
]]></description>
			<content:encoded><![CDATA[<p>Take a look at this post at <a href="http://www.lostechies.com/blogs/derickbailey/archive/2009/02/11/solid-development-principles-in-motivational-pictures.aspx">lostechies.com</a>.<br />
Good one <img src='http://blog.refactoringin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=137</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Telerik announces (yet another) .NET refactoring tool</title>
		<link>http://blog.refactoringin.net/?p=130</link>
		<comments>http://blog.refactoringin.net/?p=130#comments</comments>
		<pubDate>Thu, 03 Dec 2009 16:17:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Refactoring in C#]]></category>
		<category><![CDATA[Refactoring in VB]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=130</guid>
		<description><![CDATA[Refactoring support in Visual Studio 2010 lags miles behind refactoring support in in free tools like Eclipse or Netbeans. ]]></description>
			<content:encoded><![CDATA[<p>Does this say anything about refactoring adoption among .NET developers? Maybe. It definitely says something about Microsoft refactoring tools state of the art (thanks Jeff). Refactoring support in Visual Studio 2010 lags miles behind refactoring support in free tools like Eclipse or Netbeans. JustCode features <a href="http://www.telerik.com/products/justcode/features.aspx">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=130</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Visual Studio and TDD: Better late than never</title>
		<link>http://blog.refactoringin.net/?p=124</link>
		<comments>http://blog.refactoringin.net/?p=124#comments</comments>
		<pubDate>Sat, 12 Sep 2009 06:13:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=124</guid>
		<description><![CDATA[After hearing that UML is touted as a “next big thing” in Visual Studio 2010, I must admit I was less than elated. Since I am hardly a “new kid on the block”, I freely admit that I remember that quirky diagramming tool called Visual Modeler that shipped with Visual Studio 6.0. (“Ten years after” already?)]]></description>
			<content:encoded><![CDATA[<p>After hearing that UML is touted as a “next big thing” in Visual Studio 2010, I must admit I was less than elated. Since I am hardly a “new kid on the block”, I freely admit that I remember that quirky diagramming tool called <a href="http://msdn.microsoft.com/en-us/library/aa267720%28VS.60%29.aspx">Visual Modeler</a> that shipped with Visual Studio 6.0. (“Ten years after” already?). Had it been 1999, I guess UML might even sound, well… intriguing.<br />
Fortunately, I recently came across this video:<br />
<a href="http://channel9.msdn.com/posts/VisualStudio/Test-Driven-Development-with-Visual-Studio-2010">TDD with Visual Studio</a><br />
Believe it or not, but 2010 version of Visual Studio should finally provide a lot less friction for TDD developers. It can generate class and member stubs based on client code. More surprisingly, there is an integrated Test Runner that does not “fall apart” (just pick your song!) if you have tests written is some 3rd party unit testing frameworks. (On the video Karen shows executing MbUnit tests with VS Test runner.)<br />
TDD is hardly a news these days, but hardly feels as passé as UML!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=124</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>YAGNI is not SLACKING!</title>
		<link>http://blog.refactoringin.net/?p=103</link>
		<comments>http://blog.refactoringin.net/?p=103#comments</comments>
		<pubDate>Fri, 05 Jun 2009 00:34:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Lean]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Technical Debt]]></category>
		<category><![CDATA[YAGNI]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=103</guid>
		<description><![CDATA[Sometimes I hear YAGNI principle invoked in a way that it is clearly misinterpreted. For example “Maybe you do not need to refactor this code just yet” or “Maybe you do not need all those unit tests”. Thing is, to be able to do YAGNI, you need to have your code refactored and covered with tests. You need continuous integration and automated builds. Without these practices, once you need to implement a new feature in JIT fashion, things will inevitably start to break,]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It">YAGNI</a> is a clever rule. It says that by doing less your are doing yourself and everyone else a favor. In some schools of Agile Thought like <a href="http://en.wikipedia.org/wiki/Lean_software_development">Lean</a> it has become a whole philosophy (although  they are more keen on some strange sounding Japanese words, mind you).</p>
<p>Only a decade or so ago, general approach was quite different. You&#8217;d try to make your system as encompassing, flexible and configurable as possible. You&#8217;d design your system for tomorrow&#8217;s needs. </p>
<p>I will give you a quick example. Imagine you need to program a feature on your website where you export some data to an excel file. In the old days, you&#8217;d analyze the problem, design your classes let&#8217;s say in a form of hierarchy where ExcelExporter and PdfExporter inherit BaseExporter class. You do not need to export data to pdf just yet, but you think you might need it some day, so you better be ready.<br />
These days, however, you live in the present. You just program ExcelExporter. If one day you need pdf export feature, you will reorganize your classes so that both ExcelExporter and PdfExporter inherit BaseExporter class that contains some features common to both child Exporter classes so you can avoid duplication. If you never come to need this feature, you leave your ExcelExporter alone. You will implement new features as they are needed: just-in-time. </p>
<p>But there is a catch. In order to be able to move just-in-time, you should have a well designed, mercilessly refactored code covered with tests. Without refactoring or automated testing you are probably better of doing things the old fashioned way.<br />
I think YAGNI is great and I try to follow YAGNI mercilessly. However, sometimes I hear YAGNI principle invoked in a way that it is clearly misinterpreted. For example “Maybe you do not need to refactor this code just yet” or “Maybe you do not need all those unit tests”. Thing is, to be able to do YAGNI, you need to have your code refactored and covered with tests. You need continuous integration and automated builds. Without these practices, once you need to implement a new feature in JIT fashion, things will inevitably start to break. One way to avoid “Maybe you do not need good quality software” kind of dilemmas is to make practices like <a href="http://www.extremeprogramming.org/rules/testfirst.html">TDD</a>, refactoring and continuous integration integral part of your development process. Then, there is no need to think that you might leave out unit tests; since you are doing TDD these are in place already; since you refactor all the time, then there is no way to leave it out.</p>
<p>Remember, YAGNI applies to features, not to quality! One way to use YAGNI properly is to think about <a href="http://martinfowler.com/bliki/TechnicalDebt.html">Technical Debt</a>. Is the decision NOT to do something resulting in Technical Debt? Technical Debt has to be payed off with interest and with software rates are extremely steep. If you are getting into debt, you are not YAGNI, you are plain&#8217; SLACKING!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=103</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Another Free C# Refactoring Tool from Devexpress</title>
		<link>http://blog.refactoringin.net/?p=96</link>
		<comments>http://blog.refactoringin.net/?p=96#comments</comments>
		<pubDate>Tue, 26 May 2009 14:58:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Refactoring in C#]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=96</guid>
		<description><![CDATA[Developer Express have released another free C# tool that includes “a fresh selection of hand-picked features taken from CodeRush and Refactor! Pro.” ]]></description>
			<content:encoded><![CDATA[<p>I just realized I have failed to mention this on time, but I think the news still deserves a post. Developer Express have released another free C# tool that includes “a fresh selection of hand-picked features taken from CodeRush and Refactor! Pro.” You can download the tool from this <a href="http://devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/">URL </a>and read more about the features it offers <a href="http://community.devexpress.com/blogs/markmiller/archive/2008/10/27/announcing-coderush-express-for-c.aspx">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=96</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Map two classes with one-to-one relationship to a single table in LINQ to SQL.</title>
		<link>http://blog.refactoringin.net/?p=76</link>
		<comments>http://blog.refactoringin.net/?p=76#comments</comments>
		<pubDate>Tue, 19 May 2009 17:33:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=76</guid>
		<description><![CDATA[After performing a refactoring on a class and extracting associated class, I had to make my classes map to a single table in database. For that purpose I used the usual  Association attribute.]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">Some time ago I came across the following problem. After performing a refactoring on a class and extracting associated class, I had to make my classes map to a single table in database. For that purpose I used the usual<span>  </span>Association attribute and ended up with a code akin to this:</p>
<pre>[Table()]
    class Customer
    {
        private Address address;

        [Column(IsPrimaryKey=true, IsDbGenerated=false)]
        public String SSN
        {
            get;
            set;
        }

        [Column]
        public String FirstName
        {
            get;
            set;
        }

        [Column]
        public String LastName
        {
            get;
            set;
        }

        [Association(ThisKey="SSN", Storage="address", OtherKey="SSN")]
        public Address Address
        {
            get
            {
                return address;
            }
            set
            {
                address = value;
            }
        }

    [Table(Name="Customer")]
    class Address
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = false)]
        public String SSN
        {
            get;
            set;
        }

        [Column]
        public string Street
        {
            get;
            set;
        }
    }

        static void Main(string[] args)
        {
            DataContext context = new DataContext("Data Source=XYZ;Initial Catalog=TEST;Integrated Security=SSPI");

            Customer customer = new Customer{
                SSN = "123",
                FirstName = "First",
                LastName = "Last",
                Address = new Address{
                    Street = "My Street",
                    SSN = "123"
                }
            };

            Table customers = context.GetTable();
            customers.InsertOnSubmit(customer);
            context.SubmitChanges();
        }

//DB DDL
CREATE TABLE [DBO].[CUSTOMER](
        [SSN] [NVARCHAR](50) NOT NULL,
        [FIRSTNAME] [NVARCHAR](50) NULL,
        [LASTNAME] [NVARCHAR](50) NULL,
        [STREET] [NVARCHAR](50) NULL,
 CONSTRAINT [PK_CUSTOMER] PRIMARY KEY CLUSTERED</pre>
<p class="MsoNormal">As you can see, a single Customer has a single Address. Customer with corresponding Address maps to a table Customer. Everything works well, until you try save new instances. You get the following error: Violation of PRIMARY KEY constraint &#8216;PK_Customer&#8217;. Cannot insert duplicate key in object &#8216;dbo.Customer&#8217;. If you try to execute the code and you should be able to reproduce the error.</p>
<h2>Solution</h2>
<p class="MsoNormal">In the end, it is all just about method call order.<br />
The solution is the commit the root object first (Customer) in our example, without related object (Address). This way, the instance of related object is created also, with all properties empty.<br />
Second step is to set the properties of related object. Here the important detail is not to create the instance of related object, since it has been already created by linq2sql. Then, you commit changes again and this time the related object is also updated and saved.<br />
It would probably not work if you had to enforce not null constraint on some of the related object properties.</p>
<p class="MsoNormal">Here is the same example fixed to work without error.</p>
<pre>class Program
    {
        static void Main(string[] args)
        {
            DataContext context = new DataContext(
                "Data Source=XYZ;Initial Catalog=TEST;Integrated Security=SSPI");
            Table customers = context.GetTable();
 

            Customer customer = new Customer
            {
               SSN = "SomeSSN",
               FirstName = "First",
               LastName = "Last"
            };
            customers.InsertOnSubmit(customer);
            //Save customer first, this will also create the Address
            context.SubmitChanges();   

            //Now Address is not null anymore, so it will be updated
            //Linq2SQL will not try to insert new row
            customer.Address.Street = "Updated";
            context.SubmitChanges();

            //get one instance for demo purposes
            Customer saved = (from all in customers
                                 select all).First();
            Console.WriteLine(saved.Address.Street);

        }
    }

    [Table()]
    class Customer
    {
        private EntityRef
<address> address;
 

        [Column(IsPrimaryKey=true, IsDbGenerated=false)]
        public String SSN
        {
            get;
            set;
        }

        [Column]
        public String FirstName
        {
            get;
            set;
        }

        [Column]
        public String LastName
        {
            get;
            set;
        }

        [Association(ThisKey="SSN", Storage="address")]
        public Address Address
        {
            get
            {
                return address.Entity;
            }
            set
            {
                address.Entity = value;
            }
        }
    }

    [Table(Name="Customer")]
    class Address
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = false)]
        public String SSN
        {
            get;
            set;
        }

        [Column]
        public string Street
        {
            get;
            set;
        }
    } 

//DB DDL
CREATE TABLE [dbo].[Customer](
        [SSN] [nvarchar](50) NOT NULL,
        [FirstName] [nvarchar](50) NULL,
        [LastName] [nvarchar](50) NULL,
        [Street] [nvarchar](50) NULL,
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED
</address>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=76</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Professional Refactoring in C# and ASP.NET published!</title>
		<link>http://blog.refactoringin.net/?p=69</link>
		<comments>http://blog.refactoringin.net/?p=69#comments</comments>
		<pubDate>Wed, 15 Apr 2009 17:18:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Refactoring in C#]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=69</guid>
		<description><![CDATA[you can already order Professional Refactoring in C# and ASP.NET from Amazon and take a look at some excerpts from the book at wrox.com]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">While still under “Upcoming” tag on wrox.com, you can already order Professional Refactoring in C# and ASP.NET from <a href="http://www.amazon.com/dp/047043452X/">Amazon </a>and take a look at some excerpts from the book at <a href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-Refactoring-in-C-ASP-NET.productCd-047043452X.html">wrox.com</a>. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=69</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code, aesthetics and symmetry</title>
		<link>http://blog.refactoringin.net/?p=55</link>
		<comments>http://blog.refactoringin.net/?p=55#comments</comments>
		<pubDate>Mon, 23 Mar 2009 17:36:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://blog.refactoringin.net/?p=55</guid>
		<description><![CDATA[It might sound funny to mention aesthetic qualities like symmetry when speaking about source code... It has to do with inner workings of our brain. These qualities are the way to communicate with fellow programmer on another level. ]]></description>
			<content:encoded><![CDATA[<p>It might sound funny to mention aesthetic qualities like symmetry when speaking about source code. It is exactly the principle that Kent Beck mentions in his book <a href="http://www.amazon.com/Implementation-Patterns-Addison-Wesley-Signature-Kent/dp/0321413091">Implementation Patterns</a>. It has to do with inner workings of our brain. These qualities are the way to communicate with fellow programmer on another level. I’d say symmetry might be put under more general “Consistency” principle that <a href="http://www.amazon.com/Framework-Design-Guidelines-Conventions-Development/dp/0321545613">Abrams and Cwalina</a> are so keen about. And it is definetly in the spirit of <a href="http://en.wikipedia.org/wiki/Principle_of_least_surprise">Principle of least surprise</a>.</p>
<p class="MsoNormal">What got me thinking about it is a bug I investigated recently that had to do with two base java classes: <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html">java.net.URL</a> and <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html">java.net.URLConnection</a>. The symptom was a generation of leaking file handles, resulting in server hanging after few hours of operation.</p>
<p class="MsoNormal">Take a look at this java code:</p>
<pre><span>           </span>URL url = configuration.getURL();</pre>
<pre><span>           </span>URLConnection connection = url.openConnection();</pre>
<pre>           long date = connection.getLastModified();</pre>
<p class="MsoNormal">Now, I’d typically put method open on the connection object. If you take a look at URLConnection, you will see that the class does not have the close method. That’s all right, following the symmetry principle, it would be then consistent to place closeConnection method inside the URL class. Alas, neither the URL has the method that closes the connection!</p>
<p class="MsoNormal">This was the source of our bug. The programmer had to open the connection in order to read getLastModified. But, since neither URL nor URLConnection had the close method, he “forgot” to close the connection. The solution is to do the following after reading the date:</p>
<pre style="padding-left: 30px;"><span style="font-family: Georgia; line-height: 19px; white-space: normal;">I</span>nputStream stream = connection.getInputStream();</pre>
<pre style="padding-left: 30px;">stream.close();</pre>
<p class="MsoNormal">No wonder the programmer forgot to close the connection; there was no obvious method he could call to do so. I haven&#8217;t bothered to take a look at the code of these classes, but it seems unlikely that there was no other option when designing them. Had the authors thought about symmetry when creating URL and URLConnection classes, a nasty bug could have been averted. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.refactoringin.net/?feed=rss2&amp;p=55</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
