<?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>{(something&#124;&#124;other).soft()} &#187; General</title>
	<atom:link href="http://www.somethingorothersoft.com/category/general/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.somethingorothersoft.com</link>
	<description>About Software Development And Other Stuff By Igor Zevaka</description>
	<lastBuildDate>Mon, 25 Jul 2011 00:03:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Unable to Restore From Backup Using Windows 7 Recovery CD on a Mac</title>
		<link>http://www.somethingorothersoft.com/2011/07/25/unable-to-restore-from-backup-using-windows-7-recovery-cd-on-a-mac/</link>
		<comments>http://www.somethingorothersoft.com/2011/07/25/unable-to-restore-from-backup-using-windows-7-recovery-cd-on-a-mac/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 00:03:47 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=542</guid>
		<description><![CDATA[If you are restoring from backup made using Windows 7 Backup and Restore system image on Mac you might find that you can&#8217;t access network location containing the backup. This is due to the network card&#8217;s driver not being loaded. Don&#8217;t worry though, there is a solution and once the driver is loaded the restore <a href="http://www.somethingorothersoft.com/2011/07/25/unable-to-restore-from-backup-using-windows-7-recovery-cd-on-a-mac/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>If you are restoring from backup made using Windows 7 Backup and Restore system image on Mac you might find that you can&#8217;t access network location containing the backup. This is due to the network card&#8217;s driver not being loaded. Don&#8217;t worry though, there is a solution and once the driver is loaded the restore can proceed successfully.</p>

<p>Windows drivers for Mac come with Boot Camp installer, however they are two problems:<br />
 1. They are inside one of many installers.<br />
 2. You need to know which driver to use.</p>

<p>The first problem is pretty easy to solve &#8211; the installers are actually self-extracting archives, so they can extracted with WinRar. The second problem is a bit tougher to deal with and requires a bit of research, either on Windows and  MacOS to try and figure out which one of the hundreds of available drivers is the right one.</p>

<h3>Driver Details</h3>

<p>So before jumping into recovery, and you should really do this in controlled circumstances &#8211; i.e. practice recovery, have a look at what network driver you have in Windows. Mine (15&#8243; April 2011 MacBook Pro) looks like this:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2011/07/driver.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2011/07/driver.png" alt="" title="driver" width="352" height="444" class="alignnone size-full wp-image-543" /></a></p>

<p>If you are stuck and can only boot into MacOS, you look up the adapter&#8217;s details in System Diagnostics for hints about what it&#8217;s called.</p>

<h3>Extracting Boot Camp drivers</h3>

<p>Get hold of MacOS install DVD or download those with Boot Camp Assistant in MacOS and put them onto a USB stick. Have a browse though the driver installers(<MacOS DVD>\Boot Camp\Drivers&#41; and extract any of the ones that might sound like they contain the network adapter that you need &#8211; Intel, Broadcom and NVidia are main suspects there. In my case it was BroadcomEthernet64.exe that contained the driver in question.</p>

<h3>Recovery</h3>

<p>Boot into Windows Recovery CD and bring up the screen to load drivers. Navigate to the folder containing extracted driver installer and select the only .INF file there &#8211; b57nd60a.inf. You will be presented with a select driver dialog that, in the case of Broadcom, contains tons of duplicated drivers. Select second(first one didn&#8217;t work) &#8220;Broadcom 570x Gigabit Integrated Controller&#8221;.</p>

<p>The add driver dialog doesn&#8217;t really tell you whether or not installation was successful. You need to proceed to browse to the network location to actually find out if the driver worked. Side note: The system will not actually acquire an IP address through DHCP until you click to browse network. There is a short cut that you can take if a lot of trial and error is involved.  Bring up command prompt and type in &#8220;ipconfig&#8221;. Once the driver is loaded, you will see an adapter in the command&#8217;s output.</p>

<p>Once the network location is available, the restore process should proceed without problems. Leave all options default (including the scary &#8220;Format partition&#8221; checkbox) &#8211; it will not overwrite MacOS partition.</p>

<p>Happy restoring.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2011/07/25/unable-to-restore-from-backup-using-windows-7-recovery-cd-on-a-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone &#8211; A very little little detail</title>
		<link>http://www.somethingorothersoft.com/2011/06/20/iphone-a-very-little-little-detail/</link>
		<comments>http://www.somethingorothersoft.com/2011/06/20/iphone-a-very-little-little-detail/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 23:37:26 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=534</guid>
		<description><![CDATA[There is a Tumblr blog out there -http://littlebigdetails.com that mainly deals with oohing and aahing about Apple&#8217;s &#8220;awesome&#8221; UI and attention to detail. Apple is sometimes good at that, but not that as much as they think they are. Just look at Finder. So the other day I found the most useless UI detail in <a href="http://www.somethingorothersoft.com/2011/06/20/iphone-a-very-little-little-detail/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>There is a Tumblr blog out there -<a href="http://littlebigdetails.com">http://littlebigdetails.com</a> that mainly deals with oohing and aahing about Apple&#8217;s &#8220;awesome&#8221; UI and attention to detail. Apple is sometimes good at that, but not that as much as they think they are. Just look at Finder.</p>

<p>So the other day I found the most useless UI detail in iPhone, and from a quick Google search, not many people found it either. It is a subtle difference in the appearance of the Shift key, depending on whether or not the word is auto-captalised or not. At the beginning of a sentence, it is slightly bolder, than if you were to press Shift yourself.</p>

<p>Below image demonstrates the effect:</p>

<p><img src="http://www.somethingorothersoft.com/wp-content/uploads/2011/06/Shift.gif" alt="" title="Shift" width="320" height="256" class="alignnone size-full wp-image-535" /></p>

<p>You can easily verify this yourself by following these steps:</p>

<ol>
<li>Start a new message.</li>
<li>Type in a letter &#8211; say &#8216;A&#8217;.</li>
<li>Press Shift.</li>
<li>Type in another letter &#8211; say &#8216;A&#8217;.</li>
<li>Backspace twice. You will notice the Shift key changing appearance when erasing the first letter.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2011/06/20/iphone-a-very-little-little-detail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DDD &#8211; Defect Driven Development &#8211; The inevitable agile stage of waterfall projects</title>
		<link>http://www.somethingorothersoft.com/2011/05/31/ddd-defect-driven-development-the-inevitable-agile-stage-of-waterfall-projects/</link>
		<comments>http://www.somethingorothersoft.com/2011/05/31/ddd-defect-driven-development-the-inevitable-agile-stage-of-waterfall-projects/#comments</comments>
		<pubDate>Mon, 30 May 2011 23:46:45 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=529</guid>
		<description><![CDATA[Do you ever get an urge to do things properly? To stop screwing around, plan ahead and execute the plan meticulously? I mean, proper planning is the only way to get big projects completed on time. Right?... Right? The end result, for the projects that I was involved in, was inevitably disappointing.]]></description>
			<content:encoded><![CDATA[<p>Yes, this is yet another waterfall bashing post. If you are of the mindset that agile is for lazy code cowboy hippies, then I probably won&#8217;t convince you otherwise. By the same token this is not <strong>yet another</strong> AGILE RULEZ write-ups, so perhaps it might be worth your while.</p>

<p>Gojko Adzic, in his excellent book <em>Bridging Communication Gap: Agile Acceptance Testing</em> states that Waterfall projects succeed when the team has worked together before on the same kind of project a number of times and amount of discovery to be done is minimal.</p>

<p>And indeed, that is rarely the case. The projects that I&#8217;ve been on involved a large amount of discovery, by the teams frequently unfamiliar with the most fundamental aspects of the delivery &#8211; technology, usability, functionality and little experience working together. In my opinion, unless you have done the same thing five times over, chances are your estimate is not worth the paper it&#8217;s printed on.</p>

<p>There is a sentiment in the programming circles that software engineering should be a lot like other areas of traditional engineering. Yes, we have a lot to learn from those industries, but they are not immune to time and budget blowouts. Just of think of the last couple of big public infrastructure projects in your capital city that were on time and on budget.</p>

<p>There is one project in Sydney that has all the hallmarks of a large software project going wrong and that is <a href="http://en.wikipedia.org/wiki/Epping_to_Chatswood_railway_line">Parramatta to Chatswood rail link</a>. Surveying was complete, estimates were done, by the time the project was complete it was over budget by almost a billion dollars. After finally getting trains on the tracks it was discovered that the tunnels were a little narrow in one spot and in some trains this was causing high levels of noise. This in turn caused further delays and the need to reshuffle the train fleet.</p>

<p>The above example demonstrates that 100% insurance aginst unpredictable is impossible. One can always count on obstacles just popping up out of nowhere. Now, in this instance I am not advocating that the train line should be built in an agile fashion, in fact I am certin that will simply not work. However, software systems have a unique advantage over brick and mortar projects where the system is better off grown gradually over time, rather than delivered once with all the features present.</p>

<p>Every waterfall projects starts off with grand plans for the software to do everything under the sun. At the time when you spend a few weeks talking about what features should be in, they all seem quite achievable, and you have plenty of time, since you decide how long you need for the whole project. There alsmost is a constant factor that you need to multiply your time planning features to get the implementation time. Something in the order of 1 hour of planning gives you enough features to work for two weeks. Say 1:80. Similar to the movie Inception, if you spend a week planning features, be prepared for 80 weeks of coding.</p>

<p>In my experience, the first round of testing comes at a time where only half of the features intended for delivered are implemented and in turn half of those are buggy. At this time the project is kicked into a whole new phase &#8211; what I call Defect Driven Development.</p>

<p>Defect Driven Development (DDD for short &#8211; Hi Eric Evans :) ) is where developers only work on high priority defects as identified by QA and Business Analysts. This is really a fundamental shift in the rhythm of the project. At this point the releases to testing become closer (usually around two weeks between them), development becomes more focused and features are starting to get culled.</p>

<p>Come to think about it, these are all hallmarks of agile software projects:</p>

<ul>
<li>Prioritisation of features on nearly daily basis</li>
<li>Close iterations</li>
<li>Cutting scope</li>
<li>Releasing with minimal set of features</li>
</ul>

<p>I find this stage of the project the most exciting. I could be &#8220;in the zone&#8221; for days, churning out fixes and features. Some people find it stressful and annoying &#8211; to each their own. There is,however, one difference to a proper agile project &#8211; reduced responsibility on behalf of the developers. I found that &#8220;Let the testers find bugs&#8221; attitude quite common. After all, if it&#8217;s not in the bug system &#8211; you don&#8217;t have to do it.</p>

<p>What I found the most interesting is that inadvertently, teams slip into what Agile proponents have been advocating for a good decade now. What I would like to see is recognition that there is something natural about the above qualities of software development and integrating those practices into the project from the get go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2011/05/31/ddd-defect-driven-development-the-inevitable-agile-stage-of-waterfall-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oz Power Saver is a scam</title>
		<link>http://www.somethingorothersoft.com/2011/01/31/oz-power-save-is-a-scam/</link>
		<comments>http://www.somethingorothersoft.com/2011/01/31/oz-power-save-is-a-scam/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 12:58:08 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=504</guid>
		<description><![CDATA[For those of who were unfortunate enough to catch some of tonight&#8217;s ACA that promoted Oz Power Saver, you&#8217;d be pleased to know that the device is a complete scam. Just in case you are still wondering, here is a very detailed explanation of these devices are supposed to be saving you money and how <a href="http://www.somethingorothersoft.com/2011/01/31/oz-power-save-is-a-scam/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>For those of who were unfortunate enough to catch some of tonight&#8217;s ACA that <a href="http://aca.ninemsn.com.au/article.aspx?id=8204229">promoted Oz Power Saver</a>, you&#8217;d be pleased to know that the device is a complete scam.</p>

<p>Just in case you are still wondering, <a href="http://www.nlcpr.com/Deceptions1.php">here</a> is a very detailed explanation of these devices are supposed to be saving you money and how they actually aren&#8217;t.</p>

<p>The story and the website have all the hallmarks of a scam. Here are a few:</p>

<ul>
<li>Most of the ACA is testimonials. The kind of testimonials that are never (sarcasm) used by snake oil salesmen.</li>
<li>The <a href="http://www.ozpowersave.com.au/">Oz Power Saver website</a> has nothing but a contact form. Not device information,  how it&#8217;s supposed to work, where to buy it, regulatory information etc.</li>
</ul>

<p>My understanding of Power Factor correction from nlcpr website really boils down to this:</p>

<blockquote>
  <p>Capacitors can be used to intercept the reactive power from inductive motors, and return it to the source on the next cycle. However, if the capacitors are at the service entrance or utility panel, they will do nothing to reduce I2R losses in the wiring between the panel and the motor. In order to eliminate line losses, the power factor correction device must be mounted at the inductive load.</p>
</blockquote>

<p>This means that whilst a power factor correcting device can save you money by lowering current and reducing heat losses in the wiring of your house (in the order of cents per year), mounting it at the meter does nothing. This is where Oz Power Saver can be called out to be absolute 100% scam.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2011/01/31/oz-power-save-is-a-scam/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Coverage, ASP.NET MVC Coverage, SpecFlow in MS Team Build</title>
		<link>http://www.somethingorothersoft.com/2010/10/31/coverage-asp-net-mvc-coverage-specflow-in-ms-team-build/</link>
		<comments>http://www.somethingorothersoft.com/2010/10/31/coverage-asp-net-mvc-coverage-specflow-in-ms-team-build/#comments</comments>
		<pubDate>Sun, 31 Oct 2010 12:01:23 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=459</guid>
		<description><![CDATA[In this post I will go through creating solutions with code coverage, including ASP.NET MVC projects, setting up MS Test Specflow projects and getting all that to run on MS Team Build 2010. The default out of the box setup for doing the above is not too tricky, however Team Build has stricter test pass <a href="http://www.somethingorothersoft.com/2010/10/31/coverage-asp-net-mvc-coverage-specflow-in-ms-team-build/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>In this post I will go through creating solutions with code coverage, including ASP.NET MVC projects, setting up MS Test Specflow projects and getting all that to run on MS Team Build 2010.</p>

<p>The default out of the box setup for doing the above is not too tricky, however Team Build has stricter test pass criteria, so it is important to get both coverage and SpecFlow features with non-implemented steps to not return any errors.</p>

<h3>Code coverage for MS Test projects</h3>

<p><strong>Problem:</strong> Collecting code coverage data.</p>

<p>Once your solution has at least one MS Test project, there will be a <em>.testsettings</em> file created. Double click it and go to <em>Data And Diagnostics > Code Coverage(Check Enable) > Configure</em>. Select your projects and you are good to go.</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/10/codecoverage.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/10/codecoverage.png" alt="" title="codecoverage" width="673" height="614" class="alignnone size-full wp-image-461" /></a></p>

<p>Once that is done, every time a test is run, code coverage data will be collected. To show the results, simply click the <em>Show Code Coverage Results</em> button in the <em>Test Results</em> window.
<a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/10/showcodecoverage.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/10/showcodecoverage.png" alt="" title="showcodecoverage" width="437" height="141" class="alignnone size-full wp-image-464" /></a></p>

<h3>Coverage for ASP.NET MVC projects</h3>

<p><strong>Problem:</strong> ASP .NET projects cause a test run error that looks this:</p>

<pre><code>Cannot initialize the ASP.NET project 'Project'. Exception was thrown: The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'http://localhost:5803/VSEnterpriseHelper.axd' returned an error: The remote server returned an error: (500) Internal Server Error.
</code></pre>

<p>The problem, as I understand it, is to do with misconfigured Development Web Server (Cassini) that does not properly expose a helper handler for profiler to collect code coverage data. Not ever having used ASP .NET MVC specific features in MS Test (like <code>[UrlToTestAttribute]</code>), I simply removed all those attributes and removed that project from test coverage.</p>

<p>Next, in order to collect code coverage I simply added the MVC project DLL and the problem went away. By default, code coverage does special handling for MVC projects to instrument them as websites (which also causes the web server to start up and slow down the test run). If you then add the MVC project&#8217;s DLL, it&#8217;ll run with no issues.
<a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/10/mvccoverage.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/10/mvccoverage.png" alt="" title="mvccoverage" width="520" height="634" class="aligncenter size-full wp-image-466" /></a></p>

<h3>SpecFlow features</h3>

<p><strong>Problem:</strong> SpecFlow features with non-implemented steps fail build.
When a step in a feature is not implemented, the default implementation makes the test inconclusive. This is fine when run locally, but will fail a Team Build build.</p>

<p>There are a number of solutions that I have profiled before settling on adding <code>@ignore</code> attribtue to every feature that hasn&#8217;t been implemented.</p>

<ol>
<li><p>Set Team Build to not fail build on unit test fail. I rejected this as there shouldn&#8217;t be a state where there are failing tests in a build. If a build fails, the culprit will have more incentive to fix a failing build than a simple statistic from TFS saying x per cent of tests are failing.</p></li>
<li><p>Create a test list and white list the unit tests that should be run during Test Build (by specifying the list name as part of Team Build configuration). This is fairly robust in the way that adding a new feature and not disabling it will not fail the build, however the overhead of having to add every unit test that you write to the list is too much. Chances are, developers won&#8217;t do it simply because there is nothing guiding them to have to do it.</p></li>
<li><p>Disable all SpecFlow tests from test list editor. As with above approach, the overhead of opening up test list window and marking a SpecFlow test as disabled makes for a bad team process. Also, the test lists tend to get unwieldy as the number of them grows and because disabled tests are referenced explicitly from withing the <code>.vsmdi</code> file, removed test will stay there and will pollute the view.</p></li>
<li><p>My preferred way. Use SpecFlow <code>@ignore</code> attribute to disable the feature/scenario. The advantage over the above approach is that the fact that the feature is disabled lives in the feature file, not in the <code>.vsmdi</code> file. The business analysts still need to mark them them disabled, but the amount of friction is slightly less to make the process workable.</p></li>
</ol>

<p>In Order to get SpecFlow unit test generator to spit out attributes, you will need to edit <code>specflow.exe.config</code> to look like this:</p>

<div>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;configuration&gt;
  &lt;configSections&gt;
    &lt;section name=&quot;specFlow&quot; type=&quot;TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow&quot;/&gt;
  &lt;/configSections&gt;

  &lt;specFlow&gt;
    &lt;unitTestProvider name=&quot;MsTest.2010&quot; /&gt;
  &lt;/specFlow&gt;
&lt;/configuration&gt;
</pre>
</div>

<h3>In conclusion</h3>

<p>Hopefully, with these simple tips, you will be able to fine tune your CI environment using TFS to eliminate the little niggling things that take hours(days, in the case of MVC coverage issues) to resolve.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/10/31/coverage-asp-net-mvc-coverage-specflow-in-ms-team-build/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why My Dyson Is A Better Smartphone Than iPhone 4</title>
		<link>http://www.somethingorothersoft.com/2010/07/31/why-my-dyson-is-a-better-smartphone-than-iphone-4/</link>
		<comments>http://www.somethingorothersoft.com/2010/07/31/why-my-dyson-is-a-better-smartphone-than-iphone-4/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 11:28:55 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[border-collie]]></category>
		<category><![CDATA[dyson]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=421</guid>
		<description><![CDATA[In which I try to relate border collies, Dyson vacuum cleaners, City 2 Surf and iPhone 4.

<a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/07/lrg_ACC-DC20TURBINEHEAD-IT.jpg"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/07/lrg_ACC-DC20TURBINEHEAD-IT.jpg" alt="" title="lrg_ACC-DC20TURBINEHEAD-IT" width="200" height="200" class="alignnone size-full wp-image-426" /></a>]]></description>
			<content:encoded><![CDATA[<p>In order to start explaining how Dyson, which is a vacuum cleaner, and iPhone 4, which is a smartphone, are related I must start with <a href="http://city2surf.com.au/">City 2 Surf</a>. C2S is an annual 14 km fun run that happens in Sydney, Australia. This would be the third time I am entering it and I have been training quite a bit. I am also looking at smashing my personal best this year.</p>

<p>So, as part of my training, I have been running to the gym in Saturdays sometimes &#8211; about a 10 km round trip. On one of those trips I decided to pop into the Harvey Norman, which is an electronics store, and grab a <a href="http://www.dyson.com.au/store/parts.asp?accessory=ACC-DC20TURBINEHEAD-IT&amp;product=DC19">Turbine Head</a> for my vacuum cleaner.</p>

<p>The reason I wanted one of these is because two giant border collies make the carpet in our house gets real hairy real fast.</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/07/PB100173.jpg"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/07/PB100173.jpg" alt="" title="PB100173" width="270" height="360" class="alignnone size-full wp-image-423" /></a><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/07/20081031_0376.jpg"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/07/20081031_0376.jpg" alt="" title="20081031_0376" width="240" height="360" class="alignnone size-full wp-image-422" /></a></p>

<p>The store had the vacuum attachment that I was after but it was a lot bigger than i anticipated. I thought it would fit into my backpack, but it was at least twice the size of it. So I ran back home carrying it in my hands. I must have looked ridiculous :) but I got there in the end.</p>

<p>Of course, the Turbine Head didn&#8217;t fit. I took it back to the store and the salesperson apologised profusely, which he shouldn&#8217;t have, because I could have easily looked at the box and figured out that it doesn&#8217;t fit my model. He got on the phone to Dyson and had me talk to them. The Dyson person said that the turbine head for my model is generally not available from retail stores and I have to order it from them. Fair enough, at that point I wanted to give them my credit card number to which the Dyson person said no need, I already paid for it at Harvey Norman.</p>

<p>Mildly confused I got off the phone thinking that Dyson and Harvey Norman will work out who pays for what between themselves and relayed the conversation to the salesperson. He got confused as well, thinking that what they did was offer it to me for free, as he would give me a refund. That surely didn&#8217;t make sense to me as that means Dyson is sending me a free $130 part.</p>

<p>At point we got on the phone to Dyson again to figure out what&#8217;s happening. Long story short, they <strong>are</strong> sending it to me for free. Just because I wanted it. Unbelievable. Let me stress that the part didn&#8217;t not originally come with my vacuum, it was an optional accessory. Let me also stress that Dyson full well knew that my vacuum didn&#8217;t come with a turbine head as I gave them its serial number.</p>

<p>The thing arrived in the mail merely two days after I spoke to them and I am still somewhat shocked that they would just send this $130 part to me for free. In my books, this makes Dyson the most awesomest company in the world.</p>

<p>So how does that make my Dyson a better smartphone than iPhone 4? Well, by now we all know about <a href="http://www.pcworld.com/article/201297/apples_iphone_4_antennagate_timeline.html">iPhone 4 antenna brouhaha</a>. My take on this is that the issue is real but fairly insignificant, depending on where you are. It took Apple, however, weeks of media assault, not helped by Steve Jobs&#8217; snarky emails to finally offer the crappy $30 bumper cases for free to the iPhone 4 customers.</p>

<p>Now, there is a gulf of difference between the $30 phone case (which probably costs 30c to manufacture) and a $130 vacuum head (which probably is worth $10-20). Not only that, the vacuum did not have a design flaw, it was simply the wrong implement for my particular case. Yet Dyson sent it to for free, for no other reason than I wanted it. Unlike Apple, who had to bow in to the pressure of <a href="http://blogs.consumerreports.org/electronics/2010/07/apple-iphone-4-antenna-issue-iphone4-problems-dropped-calls-lab-test-confirmed-problem-issues-signal-strength-att-network-gsm.html">Consumer Reports</a> with the whole free bumper thing.</p>

<p>So there, if Dyson was in the market of making phones, I would buy one instead of Apple&#8217;s counterpart. Oh and from preliminary testing the turbine head totally works on our carpets.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/07/31/why-my-dyson-is-a-better-smartphone-than-iphone-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting an Expression to a compiled Lambda</title>
		<link>http://www.somethingorothersoft.com/2010/06/18/converting-an-expression-to-a-compiled-lambda/</link>
		<comments>http://www.somethingorothersoft.com/2010/06/18/converting-an-expression-to-a-compiled-lambda/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 23:45:08 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[expressions]]></category>
		<category><![CDATA[lamdbas]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=398</guid>
		<description><![CDATA[A quick guide on how to convert an expression to a compiled lambda.]]></description>
			<content:encoded><![CDATA[<h3>Compiling an expression to a lambda</h3>

<p>Today I had to convert a binary expression to a lambda and then use in a where clause on a collection. Easy enough, I thought, make an <code>ExpressionLambda</code>, compile it, substitute it into the where clause, no worries.</p>

<p>This is the first cut of the code:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">

public class ClassWithProperties {
    public string Prop { get; set; }
}

static void ExpressionCrashes() {

    var expr = Expression.Equal(Expression.Property(Expression.Variable(typeof(ClassWithProperties)), &quot;Prop&quot;), Expression.Constant(&quot;value2&quot;));

    var props = new[] { Expression.Parameter(typeof(ClassWithProperties)) };
    //Throws &lt;variable '' of type 'SOCSTest.ClassWithProperties' referenced from scope '', but it is not defined&gt;
    var lambda = Expression.Lambda&lt;Func&lt;ClassWithProperties, bool&gt;&gt;(expr, props).Compile();

    var items = new List&lt;ClassWithProperties&gt; { 
        new ClassWithProperties{Prop = &quot;value1&quot;},
        new ClassWithProperties{Prop = &quot;value2&quot;},
        new ClassWithProperties{Prop = &quot;value2&quot;}
    };

    //Should return &lt;&quot;value2&quot;, &quot;value2&quot;&gt;
    items.Where(lambda);
}

</pre>
</div>

<p>The expression is a basic one &#8211; it calls an equality comparison on a property off an object and a constant. It is equivalent to this:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">
value.Prop == &quot;value2&quot;
//Where value is a parameter of type ClassWithProperties
</pre>
</div>

<p>Googling for this exception and just general expression and lambda stuff kinda hints at people having the same problem as I am but with no fast solution. It was Jon Skeet&#8217;s <a href="http://stackoverflow.com/questions/1574427/lambda-parameter-not-in-scope-while-building-binary-lambda-expression/1574455#1574455">answer to question I didn&#8217;t understand</a> on StackOverflow that finally put me onto the right track.</p>

<p>In order to compile a lambda from an expression, you need to provide <strong>all instances of <code>ParameterExpression</code></strong> that appear in the expression tree when creating a lambda expressionn (i.e. when calling <code>Expression.Lambda&lt;T&gt;(Expression, params ParameterExpression[])</code>). The Expression engine will not match types and names parameters in an expression &#8211; as far as it&#8217;s concerned different instances of <code>ParameterExpression</code> are discrete parameters.</p>

<p>Rewriting the above code yields something that doesn&#8217;t crash:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">
static void ExpressionWorks() {
    var variable = Expression.Variable(typeof(ClassWithProperties));
    var expr = Expression.Equal(Expression.Property(variable, &quot;Prop&quot;), Expression.Constant(&quot;value2&quot;));

    var props = new []{ variable };
    var lambda = Expression.Lambda&lt;Func&lt;ClassWithProperties, bool&gt;&gt;(expr, props).Compile();

    var items = new List&lt;ClassWithProperties&gt; { 
        new ClassWithProperties{Prop = &quot;value1&quot;},
        new ClassWithProperties{Prop = &quot;value2&quot;},
        new ClassWithProperties{Prop = &quot;value2&quot;}
    };

    //Returns &lt;&quot;value2&quot;, &quot;value2&quot;&gt;
    items.Where(lambda);
}
</pre>
</div>

<p>As you can see, we reused the instance <code>variable</code> in both expression declaration and <code>Expression.Lambda</code> call. Everything works fine now.</p>

<h3>Getting the parameters from Expression at runtime</h3>

<p>My situation was such as that I had to deal with an already created expression. So I couldn&#8217;t simply take the variable parameters that are used to create an expression and reuse them when creating a lambda. The solution was to traverse the expression tree and get a list of all the <code>ParameterExpression</code> instances that are contained in the expression and pass those to <code>Lambda</code> function.</p>

<p>Luckily, <a href="http://msdn.microsoft.com/en-us/library/bb546136%28v=VS.90%29.aspx"><code>ExpressionVisitor</code></a> API provides an easy way to achieve this. All you have to do is inherit from <code>ExpressionVisitor</code> and implement one function to trap all the goodies we need:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">
public class ParameterVisitor : ExpressionVisitor{

    List&lt;ParameterExpression&gt; m_Parameters;

    public IEnumerable&lt;ParameterExpression&gt; GetParameters(Expression expr) {
        m_Parameters = new List&lt;ParameterExpression&gt;();
        Visit(expr);
        return m_Parameters;
    }
        
    protected override System.Linq.Expressions.Expression VisitParameter(System.Linq.Expressions.ParameterExpression p) {

        if(!m_Parameters.Contains(p))
            m_Parameters.Add(p);
            
        return base.VisitParameter(p);
    }
}
</pre>
</div>

<p>We can even create an extension method to hide all complexity of creating a lambda:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">
public static Func&lt;TSource, TResult&gt; CreateLambda&lt;TSource, TResult&gt;(this Expression expression) {
    var visitor = new Bluecap4.Core.Expressions.ParameterVisitor();
    var parameters = visitor.GetParameters(expression);
            
    return Expression.Lambda&lt;Func&lt;TSource, TResult&gt;&gt;(expression, parameters).Compile();
}
//Usage
static void ExpressionWorks() {
    var expr = Expression.Equal(Expression.Property(Expression.Variable(typeof(ClassWithProperties)), &quot;Prop&quot;), Expression.Constant(&quot;value2&quot;));

    var items = new List&lt;ClassWithProperties&gt; { 
        new ClassWithProperties{Prop = &quot;value1&quot;},
        new ClassWithProperties{Prop = &quot;value2&quot;},
        new ClassWithProperties{Prop = &quot;value2&quot;}
    };

    //Returns &lt;&quot;value2&quot;, &quot;value2&quot;&gt;
    items.Where(expr.CreateLambda&lt;Func&lt;ClassWithProperties,bool&gt;&gt;());
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/06/18/converting-an-expression-to-a-compiled-lambda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A few things you might not know about System.Nullable</title>
		<link>http://www.somethingorothersoft.com/2010/05/29/a-few-things-you-might-not-know-about-system-nullable/</link>
		<comments>http://www.somethingorothersoft.com/2010/05/29/a-few-things-you-might-not-know-about-system-nullable/#comments</comments>
		<pubDate>Sat, 29 May 2010 13:59:24 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=385</guid>
		<description><![CDATA[There is plenty of information about Nullable&#60;T&#62; type out there and how to use it. There are, however a few tidbits that are not quite as obvious at first glance. Nullable is a value type It&#8217;s a struct that can be null. The only reason why int? intVal = null; compiles is because C# compiler <a href="http://www.somethingorothersoft.com/2010/05/29/a-few-things-you-might-not-know-about-system-nullable/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>There is plenty of information about <code>Nullable&lt;T&gt;</code> type out there and how to use it. There are, however a few tidbits that are not quite as obvious at first glance.</p>

<h1>Nullable<T> is a value type</h1>

<p>It&#8217;s a struct that can be null. The only reason why <code>int? intVal = null;</code> compiles is because C# compiler supports nullable types. You <strong>cannot</strong> define the same kind of struct yourself.</p>

<p>The decision to make <code>Nullable&lt;T&gt;</code> a value type actually makes sense if you think about it. Calling its member methods and properties will always succeed, i.e. NullReferenceException will never be thrown. This gurantees that <code>HasValue</code> never throws a NullReferenceException.</p>

<h1>Comparison to null</h1>

<p>Under the hood, the compiler, in fact translates comparison to null to a call to HasValue. The below MSIL demonstrates that:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">
    .locals init ([0] valuetype [mscorlib]System.Nullable`1&lt;int32&gt; 'value',
           [1] bool hasvalue,
           [2] bool hasvalue2)

    //int? value = null;
    IL_0001:  ldloca.s   'value'
    IL_0003:  initobj    valuetype [mscorlib]System.Nullable`1&lt;int32&gt;
    //bool hasvalue = value.HasValue;
    IL_0009:  ldloca.s   'value'
    IL_000b:  call       instance bool valuetype [mscorlib]System.Nullable`1&lt;int32&gt;::get_HasValue()
    IL_0010:  stloc.1
    //bool hasvalue2 = value != null;
    IL_0011:  ldloca.s   'value' //loads a variable onto evaluation stack
    IL_0013:  call       instance bool valuetype [mscorlib]System.Nullable`1&lt;int32&gt;::get_HasValue() //calls HasValue
    IL_001b:  stloc.2 //Stores the result in location 2 (hasvalue2)
</pre>
</div>

<p>As you can see the generated IL for <code>hasvalue = value.HasValue</code> and <code>hasvalue2 = value != null</code> are identical.</p>

<h1>null Assignment</h1>

<p>Also from above code you can see that assigning null to a nullable value is the same as calling the parameterless contructor (which all value types have).</p>

<h1>Ternary operator</h1>

<p>C# compiler also does special things with ternary operator for nullable types. The following code compiles:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">
int? nullableIntVal = 4;
int intVal = nullableIntVal ?? -1;
</pre>
</div>

<p>The above is just syntactic sugar for calling <code>HasValue</code> and if it&#8217;s true calling GetValueOrDefault(). The compiler actually generates a temporary variable to call <code>HasValue</code> off in both Release and Debug modes. Not sure why that is. Below code illustrates the equivalent C# code to what the compiler generates for ternary operator.</p>

<div>
<pre class="brush: csharp; title: ; notranslate">
int? nullableIntVal = 4;
int? temp = nullableIntVal;
int intVal = temp.HasValue ?? temp.GetValueOrDefault() : -1;
</pre>
</div>

<h1>Summary</h1>

<p><code>Nullable&lt;T&gt;</code> is a special value type that has support from C# compiler to allow the following:</p>

<ul>
<li><code>null</code> assignment  &#8211; under the hood: calling defualt constructor.</li>
<li><code>null</code> comparison &#8211; under the hood: calling <code>HasValue</code> property.</li>
<li>ternary operator <code>??</code> &#8211; under the hood: calling <code>HasValue</code> and conditionally <code>GetValueOrDefault</code>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/05/29/a-few-things-you-might-not-know-about-system-nullable/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Unit Tests As A Refactoring Tool</title>
		<link>http://www.somethingorothersoft.com/2010/02/20/unit-tests-as-a-refactoring-tool/</link>
		<comments>http://www.somethingorothersoft.com/2010/02/20/unit-tests-as-a-refactoring-tool/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 07:23:34 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unit-testing]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=283</guid>
		<description><![CDATA[So I have this class that is a bit too fat and has no unit tests. It&#8217;s way overdue for a clean up. I thought I would investigate how to refactor with unit tests. Application The application in question is a fairly normal case of a business DSL where the domain rules are expressed in <a href="http://www.somethingorothersoft.com/2010/02/20/unit-tests-as-a-refactoring-tool/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>So I have this class that is a bit too fat and has no unit tests. It&#8217;s way overdue for a clean up. I thought I would investigate how to refactor with unit tests.</p>

<h3>Application</h3>

<p>The application in question is a fairly normal case of a business DSL where the domain rules are expressed in XML and the compiler generates an application for different platforms (web, mobile web, PDA, WPF). Code is written in C#, tested with MbUnit v.3 and NMock2.</p>

<p>This particular class parses XML and generates JSON to be later consumed by ExtJS library. The JSON is a declaritive form of the control that users will eventually see. This control is complicated and has many options. Hence the fatness.</p>

<h3>Enter the unit tests</h3>

<p>Now, unit tests are touted to be great for refactoring. They are. The usual approach is to write the tests, make sure they pass, then refactor and make sure the tests don&#8217;t break. Well, I want to take it one step further and let the writing of the tests guide the refactoring.</p>

<p>Thoroughly unit tested code tends to have really good code smells. This is mainly due to fact that in order to test all aspects of a large block of code, you must isolate all of its constituents. This is evident in all projects that are written in a TDD way. They are all very modular and modular is good(I think :-) ).</p>

<p>So my goal here is just simply write the unit tests and see where it takes me. I would imagine that just by making the code testable, it will become a little bit better.</p>

<p>I never invisaged this to become a full blown article, but now that I am here, lets introduce some numbers to make this more scientific. I will be using Microsoft Team Studio Analysis Tools throughout the process. Here is a snapshot of what the class looks like at the start:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/start.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/start.png" alt="" title="start" width="808" height="173" class="alignnone size-full wp-image-284" /></a></p>

<p>As you can see the <code>Build</code> method is too big &#8211; 250 lines. This is bad. It&#8217;s one of those <code>DoIt</code> methods that does everything.</p>

<h3>First refactor</h3>

<p>Alright, lets get cranking. Straight away I noticed that I was reading a particular bit of XML and making decisions based on the node contents. This particular functionality has already been abstracted away in another class, so I might as well use that class. So I just refactored that without writing any tests before or after. That&#8217;s pretty naughty :)) Lets make it proper and rip this code into another function so we can test it.</p>

<p>Starting from the top of the method I am looking at a bit of code that parses an atribute and calls a method that is defined in the base class depending on whether or not the attribute exists.</p>

<h3>Base class dependency</h3>

<p>Now refactoring that into a method is not a problem, the problem is isolating the call to the base class. There is case to be made for having the base class contain all the dependencies that are required for all of its subclasses, however, just by skimming the code it looks like a lot of the methods there are simply in one place for convinience. So this could potentially be a case of Inheritance vs. Composition. Lets start off by abstracting  this particular method into an interface and have our base derive from the interface. Then in our derived class we access that method through a reference to the interface, not implicitly.</p>

<p>This is what it looks like now:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">
class Builder {
   public DoStuff(string blah){
      //impl
   }
}

class GridBuilder : Builder{
   public void Build() {
      var elem = Element.GetAttribute(&quot;Blah&quot;);
      DoStuff(blah);
   }
}
</pre>
</div>

<p>Let&#8217;s tweak it as described in the previous paragraph:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">
interface IBuilder {
    DoStuff(string blah);
}

1
class Builder : IBuilder {
   [Obsolete]
   public DoStuff(string blah){
      //impl
   }
}

class GridBuilder {
   
   IBuilder _Builder;
   
   public GridBuilder() {
     _Builder = this;
   }
   
   public GridBuilder(IClientBuilder b) {
            m_ClientBuilder = b;
    }
   
   public void Build() {
      var elem = Element.GetAttribute(&quot;Blah&quot;);
      _Builder = DoStuff(blah);
   }
}
</pre>
</div>

<p>So what I have done is put that <code>DoStuff</code> into an interface and marked the implementation as Obolete. This is more out of convinience to get the compiler to show me where else this method is being used. Turns out this was the only case where it was used in <code>GridBuilder</code>. I could have just as well used text search, but hey, if there is a fancy compiler feature, why not use it? Notice that I also added a dependency constructor so I can compose <code>GridBuilder</code> in a unit test.</p>

<p>Let's make a unit test for this use of <code>DoStuff</code>. As I am doing that I realised that my base class is in a different assembly and required some code duplication from another test project to make the test not crash. The fact that I had to do that is a pretty bad, but my copying the common setup file and including it in my test project is even worse. We can come back to that later, lets concentrate on what we are doing now. Might as well use the <code>Obsolete</code> attribute to remind me to refactor the unit test later on.</p>

<h3>Finally, I can test <code>Build</code></h3>

<p>So, after a long time setting up <code>GridBuilder</code>'s dependencies I am finally here - the test runs. Lets review what I've achieved so far and have a peek at the metrics. So here is the summary of what was required just to make the test run:</p>

<ul>
<li>Two instances of referring to the base class have been abstractes into two interfaces.</li>
<li>Found a bug where if a required element is present but contains no nodes the builder crashes.</li>
<li>The test creates a total of three mock objects with a total of five <code>Stubs</code> and one <code>Expect</code>.</li>
<li>The test needs to pass in an Xml element with two elements and one atribute.</li>
<li>Found a small refactoring job that is not really related to the unit testing aspect of this excercise.</li>
</ul>

<p>Code metrics:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/step1.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/step1.png" alt="" title="step1" width="954" height="210" class="alignnone size-full wp-image-286" /></a></p>

<p>So I didn't get anywhere as far as most metrics are concerned, in fact I almost went backwards, if anything. Let's keep going. So now I have a unit test that runs the <code>Build</code> method lets keep trying to test more and more parts of it.</p>

<p>Before I go on, I would like to emphasize the fact that I had to create lots of mocks and pass in lots of dependencies just to make one method not crash. Here is the unit test. Definitely too much for ONE method:</p>

<div>
<pre class="brush: csharp; title: ; notranslate">

        [SetUp]
        public void Setup() {
            m_Mocks = new Mockery();
            m_Settings = new InlineBuilderSettings {
                Compiler = m_Mocks.NewMock&lt;IWebCompiler&gt;(),
                ComponentName = &quot;Test&quot;
            };
            //Used by setup method
            Stub.On(m_Settings.Compiler).GetProperty(&quot;ServerCompiler&quot;).Will(Return.Value(null));
            Stub.On(m_Settings.Compiler).GetProperty(&quot;ServerType&quot;).Will(Return.Value(typeof(Data.ServerAplication)));
        }
        
        [Test]
        public void BuildShouldCallRequireComponentWhenViewAttribute() {

            var iClientBuilder = m_Mocks.NewMock&lt;IClientBuilder&gt;();
            var iBuilder = m_Mocks.NewMock&lt;IWebBuilder&gt;();

            Builder builder = new Builder(iClientBuilder, iBuilder);
            m_Settings.Element = 
                new XElement(&quot;Grid&quot;, new XAttribute(&quot;View&quot;, &quot;test&quot;), 
                    new XElement(&quot;Source&quot;, new XAttribute(&quot;View&quot;, &quot;DataTest&quot;)),
                    new XElement(&quot;Fields&quot;));

            Expect.Once.On(iClientBuilder).Method(&quot;RequireComponent&quot;).With(&quot;test&quot;, m_Settings.Element).Will();
            Stub.On(iClientBuilder).Method(&quot;GetComponentInfo&quot;).Will(Return.Value(new ComponentInfo()));
            Stub.On(iBuilder).Method(&quot;AddConfig&quot;).Will();
            Stub.On(m_Settings.Compiler).Method(&quot;AddInclude&quot;).Will();
            
            builder.Setup(m_Settings);
            builder.Build();
        }
</pre>
</div>

<p>Realistically, in order to complete the build process we need all those dependencies. That's pretty fundamental. However, it should be possible to reduce the amount of dependencies ONE method has.</p>

<h3>Next refactor</h3>

<p>My next target was a reasonably self contained code block that I did "Extract Method" method on. Two more unit tests. Slight improvement in maintainability and complexity.</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/step2.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/step2.png" alt="" title="step2" width="996" height="236" class="alignnone size-full wp-image-287" /></a></p>

<p>Next one is a big sucker. This block produces about 5 output objects that are dumped to JSON later on. I actually moved to another two classes. One to perform the build and another to store the output.</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/step3.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/step3.png" alt="" title="step3" width="896" height="236" class="alignnone size-full wp-image-288" /></a></p>

<p>Good improvement on all counts. Lets keep splitting the Build method and writing tests for it. As I am doing this I decided to make the GridBuilder a namespace within a project. There are a number of classes in it by now, might as well contain them in a folder.</p>

<h3>Day later.</h3>

<p>I have somewhat abandoned refactoring GridBuilder as I found a whole bunch of other tightly coupled classes. The unit tests have proven to be a great tool exposing those dependencies. They also become usefull when the refactoring becomes non-trivial - i.e. goes beyond just moving a block of code out of a method.</p>

<p>This is what the class looked like once I finished with it:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/step4.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/02/step4.png" alt="" title="step4" width="975" height="230" class="alignnone size-full wp-image-289" /></a></p>

<p>Now that I ran out of time that I gave myself for this task I think I have a few notes for future.</p>

<ul>
<li>Parsing an XML collection is ugly and tends to get messy when things need to be addded to the inner loop. I think for this scenario I would need some sort of visitor pattern implemented so that you could add things to the inner loop without having to alter the loop itself.</li>
<li>Having implicit dependencies (like a dependency on a property of an actual dependency) totally breaks the unit tests. A situation where you create one mock and then have its method return another mock is a bit ridiculous.</li>
<li>A unit test for a monstrous method will too be monstrous. There is almost 1-to-1 relationship between how fat the method is and how fat its unit test is. I think that if one aims to make unit test simpler, the code under test will in turn become simpler.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/02/20/unit-tests-as-a-refactoring-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I Like Words &#8211; Or Introduction Into Functional Programming and F#.</title>
		<link>http://www.somethingorothersoft.com/2010/02/09/i-like-words-or-introduction-into-functional-programming-and-f/</link>
		<comments>http://www.somethingorothersoft.com/2010/02/09/i-like-words-or-introduction-into-functional-programming-and-f/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 07:11:56 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[f#]]></category>
		<category><![CDATA[functional-programming]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=270</guid>
		<description><![CDATA[If you hoped to find some sort of functional programming introduction here you are sadly mistaken. This is MY introduction into such said programming. Or it is more like &#8220;I&#8217;ve read up on F#, my brain exploded and spilled out into this blog post&#8221;. I would like to start off by comparing programming languages to <a href="http://www.somethingorothersoft.com/2010/02/09/i-like-words-or-introduction-into-functional-programming-and-f/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>If you hoped to find some sort of functional programming introduction here you are sadly mistaken. This is MY introduction into such said programming. Or it is more like &#8220;I&#8217;ve read up on F#, my brain exploded and spilled out into this blog post&#8221;.</p>

<p>I would like to start off by comparing programming languages to spoken languages. Most will agree that the comparison is fair. Programming languages bear most hallmarks of real life languages. There is syntax, grammar, dictionary, there are historical reasons for why the language the way it is, etc. Generally speaking one is most fluent in their native tongue and could deal with a couple of others. Similarly in programming you have your native language &#8211; C family, VB, Pascal, Ruby, Python, Perl, hieroglyphics(PHP) etc.</p>

<p>My native language is Russian and that&#8217;s what I grew up with. From a reasonalby early age I learnt English and was reasonably fluent in it as a second language. I would like to equate this SECOND language to your FIRST programming language. The similarity, for the sake of this post, is that you think in your native language and translate it into code. The process, as those who speak other tongues would know, is similar. You form what you want to say in your head, translate all the words into the other language, rearrange the sentence if the target language requies so and then produce the output.</p>

<p>As with a second spoken language, writing programs eventually becomes second nature. Enter third (spoken) langague, e.g. French, that I learned in school. I found that my brain was stuck in this binary Russian/English mode and I could not add French to the mix, so my French was coming out very English like.</p>

<p>This is the problem I am facing with F#. It is SO compltely different that my C/C++/C#/Whatever-happy brain does not accept it. If comparing to spoken languages, it&#8217;s even further away from C than French is from English. It&#8217;s more like Japanese, where both the alphabet and the mindset are different.</p>

<p>So, coming back to the point of this dribble. I like words. I like the explicitness of procedural languages. I think it tends to follow how one thinks. <code>if</code> statements, <code>while</code> statements, assignment, parameter passing &#8211; they are all very logical.</p>

<p>My biggest hurdle understanding F# is the fact that the same syntax can be used for instantiation and matching. For example defining a function that takes a tuple with two members:</p>

<p><pre class="brush: fsharp; title: ; notranslate">let func (a, b) = printfn &quot;a: %d, b: %d&quot; a b;;</pre></p>

<p>The syntax is the same as when you define a tuple:</p>

<p><pre class="brush: fsharp; title: ; notranslate">let tuple = (4, 5);;</pre></p>

<p>Wheres a, say C++ would do something like this:</p>

<div>

<pre class="brush: cpp; title: ; notranslate">
Tuple&lt;int, int&gt; = new Tuple&lt;int, int&gt;(4,5);

void func(Tuple&lt;int, int&gt; tuple) {
}
</pre>
</div>

<p>F# seems to just use all these symbol operators for everything and I just can&#8217;t let go of my attachment to words. <code>List.Add</code> is logical, <code>[4;5;]@[6;7]</code> is less so, especially considering that the operands cound be either values or lists.</p>

<p>Speaking of words, here is some lingo that you will undoubttedly come across as you learn a functional programming language. The list is not complete and some words are not simple definitions, but quite complex concepts &#8211; like combinators &#8211; those will make your head hurt extra good :))</p>

<ul>
<li>High Order Function &#8211; Function that can take functions as parameters and/or return a function</li>
<li>Curried function &#8211; High Order Function that binds one or more of the parameters to a predetermined value and returns a function that takes less parameters.</li>
<li>Purity &#8211; Functions not having side effects &#8211; i.e. the function produces an output without chnaging the input or modifying state somewhere else. This normally invoves using immutable data structures and combinators.</li>
<li>Cons operator (<code>::</code>) &#8211; Adding an element to the beginning of the list.</li>
<li>Strictness &#8211; Evaluating parameters to the function before the function is evaluated.</li>
<li>combinator &#8211; High order function that has no free variables. Short version is that this function only operates on its parameters, not any other functions or values defined elsewhere.</li>
<li>Memoization &#8211; Remembering the result of a slow running function for future use (Caching).</li>
<li>Imperative programming &#8211; &#8220;normal&#8221; programming &#8211; i.e. Procedural, Object Orientated, etc.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/02/09/i-like-words-or-introduction-into-functional-programming-and-f/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

