<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Being Cellfish</title><link>http://blogs.msdn.com/b/cellfish/</link><description>Stuff I wished I&amp;#39;ve found in some blog (and sometimes did)</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/BeingCellfish" /><feedburner:info uri="beingcellfish" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>If it is hard to test, you did something wrong</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/W1N4saCZSC4/if-it-is-hard-to-test-you-did-something-wrong.aspx</link><pubDate>Thu, 16 May 2013 12:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10419173</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10419173</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/05/16/if-it-is-hard-to-test-you-did-something-wrong.aspx#comments</comments><description>&lt;p&gt;I've often been asked questions like &lt;em&gt;how would you test this&lt;/em&gt; or been told that there cannot be unit test for some code because it is impossible to test. Well, my opinion is that if something is hard to test it is all your fault. &lt;em&gt;You&lt;/em&gt; designed it, &lt;em&gt;you&lt;/em&gt; implemented it and hence it is &lt;em&gt;your&lt;/em&gt; fault it is hard to test.&lt;/p&gt;
&lt;p&gt;The situation in which people have the hardest time accepting that it is their own fault is when dealing with external dependencies. They say things like "I'm using this other module that does not provide a nice interface". And then they typically revert to some mocking framework to cleanup their mess. Most mocking frameworks today are powerful enough through reflection or even binary instrumentation that they magically can make untestable code very untestable.&lt;/p&gt;
&lt;p&gt;Rather than using powerful tools as my savior, I use abstractions. Whenever I depend on something that is not easy to test and that I do not have the power to change I hide it behind an abstraction; an interface or just a class with a few virtual methods I can override in my tests. Is this abstraction just another level of indirection? I do not believe so. Isolating dependencies makes it possible for me to implement something the way I want it to be and then deal with the behavior of the dependency separately. Here is an example from real life:&lt;/p&gt;
&lt;p&gt;I needed to implement a feature that depended on two components that really didn't lend them selves for easy faking. So I created two new interfaces representing the functionality I needed for my feature. As I started to integrate the first component it became clear that the interface I needed was not provided by the dependency in an easy way. I needed to put some logic in there to make it work the way my feature expected it. So I created a new interface representing the dependency functionality and made that a dependency of a class that added the logic needed to transform dependency results into what my feature needed. I did not expect this but it was easy given my design and the fact I did not know exactly how the dependency worked in the beginning did not stop me from being productive. My second dependency turned out to behave the way I expected and the interface I invented could easy be used to wrap the second dependency.&lt;/p&gt;
&lt;p&gt;The key is that the wrapper for each external dependency should be thin. Preferably one-liners so there is no need to test them. That does not mean the method signature needs to be the same as your dependency. I often make my&amp;nbsp;wrapper signature simpler than what the dependency actually needs.&lt;/p&gt;
&lt;p&gt;And remember; &lt;em&gt;if it is hard to test - &lt;strong&gt;You&lt;/strong&gt; did something wrong!&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10419173" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/W1N4saCZSC4" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Test/">Test</category><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Development/">Development</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/05/16/if-it-is-hard-to-test-you-did-something-wrong.aspx</feedburner:origLink></item><item><title>Collection initializers not doing what you expect</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/PH-JW7V_HX8/collection-initializers-not-doing-what-you-expect.aspx</link><pubDate>Thu, 09 May 2013 12:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10414653</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10414653</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/05/09/collection-initializers-not-doing-what-you-expect.aspx#comments</comments><description>&lt;p&gt;Let's assume that you have a class that have a collection property and that you want the default for that collection to be to actually have a value. That class might look like this: &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Foo
&lt;span class="lnum"&gt; 2: &lt;/span&gt;{
&lt;span class="lnum"&gt; 3: &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Foo()
&lt;span class="lnum"&gt; 4: &lt;/span&gt;    {
&lt;span class="lnum"&gt; 5: &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Numbers = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 4711 };
&lt;span class="lnum"&gt; 6: &lt;/span&gt;    }
&lt;span class="lnum"&gt; 7: &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; ICollection&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; Numbers { &lt;span class="kwrd"&gt;get&lt;/span&gt;; &lt;span class="kwrd"&gt;set&lt;/span&gt;; }
&lt;span class="lnum"&gt; 8: &lt;/span&gt;}
&lt;/pre&gt;
&lt;p&gt;Now somewhere else in your code you want to override the collection value and set some other value so you do this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt;&lt;span class="kwrd"&gt;var&lt;/span&gt; foo= &lt;span class="kwrd"&gt;new&lt;/span&gt; Foo { Numbers = { 42 } };
&lt;/pre&gt;
&lt;p&gt;So what is now the value of the property Numbers? Turns out it actually holds both the initial value and the new value rather than just the one value you want. The way to do it if you only want one value is this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt;&lt;span class="kwrd"&gt;var&lt;/span&gt; foo= &lt;span class="kwrd"&gt;new&lt;/span&gt; Foo { Numbers = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 42 } };
&lt;/pre&gt;
&lt;p&gt;One way to try and avoid this is to not initialize the Numbers property with a list but rather an array like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Numbers = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 4711 };
&lt;/pre&gt;
&lt;p&gt;But that might not always be possible so you might be better off by not exposing your collections like this and only provide an IEnumerable property for enumeration and do all manipulation through separate methods and not properties.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10414653" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/PH-JW7V_HX8" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/-Net/">.Net</category><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Development/">Development</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/05/09/collection-initializers-not-doing-what-you-expect.aspx</feedburner:origLink></item><item><title>Task-based Asynchronous Pattern - kick starter</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/p5OjiseRo7s/task-based-asynchronous-pattern-kick-starter.aspx</link><pubDate>Thu, 02 May 2013 12:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10414651</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10414651</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/05/02/task-based-asynchronous-pattern-kick-starter.aspx#comments</comments><description>&lt;p&gt;Regardless of if you are new to TAP (Task-based Asynchronous Pattern aka "&lt;em&gt;async/await&lt;/em&gt;") or have been&amp;nbsp;doing it for a while&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/pfxteam/archive/2013/02/20/mvp-summit-presentation-on-async.aspx" target="_blank"&gt;this presentation from an MVP summit&lt;/a&gt; in February (2013)&amp;nbsp;serves both as a good introduction explaining how it works as well as providing deeper knowledge and high-lighting a few common problems. It's a short presentation so definitely worth downloading and reading!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10414651" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/p5OjiseRo7s" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/-Net/">.Net</category><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Development/">Development</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/05/02/task-based-asynchronous-pattern-kick-starter.aspx</feedburner:origLink></item><item><title>How to know when the garbage collector is not helping you</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/ZvLD4plq_SY/how-to-know-when-the-garbage-collector-is-not-helping-you.aspx</link><pubDate>Thu, 25 Apr 2013 11:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10411153</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10411153</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/04/25/how-to-know-when-the-garbage-collector-is-not-helping-you.aspx#comments</comments><description>&lt;p&gt;A while back I did an &lt;a href="http://blogs.msdn.com/b/cellfish/archive/2012/02/22/object-pooling-vs-creating-lots-of-them.aspx"&gt;experiment&lt;/a&gt; where it turned out that allocating objects was better than pooling them. Since then I have encountered a few times where allocating actually turned out to be a bad thing. I've never seen this being a problem in a client application, but in servers allocating a lot of objects can be a problem even if the objects are very short lived. What happened to me was that so many objects were created that the garbage collector wanted to run several times a second to try and clean things up. Each time a few of these short lived objects would escape from generation zero to generation one making any following garbage collections more expensive. This time I was lucky because the object in question was a byte array buffer that could be both reduced and reused with some simple logic.&lt;/p&gt;
&lt;p&gt;What might be harder is when you add async/await and tasks into the mix. The reason is that async/await is very good at making your async code easy to understand but at the same time it can create a lot of objects if you just do the naive implementation of what you want to do. However the naive approach is still the preferred one I think since it reduces the risk of creating something that does not do what you want under all circumstances. But it is always good to know what is happening and that is why &lt;a href="http://blogs.msdn.com/b/dotnet/archive/2013/04/04/net-memory-allocation-profiling-with-visual-studio-2012.aspx" target="_blank"&gt;you should read this article&lt;/a&gt; that explains how to use the memory profiler and as an example look at an example with tasks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10411153" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/ZvLD4plq_SY" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/-Net/">.Net</category><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Tools/">Tools</category><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Development/">Development</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/04/25/how-to-know-when-the-garbage-collector-is-not-helping-you.aspx</feedburner:origLink></item><item><title>Using T4 to eliminate maintenance</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/VcBPpJH27Ts/using-t4-to-eliminate-maintenance.aspx</link><pubDate>Thu, 18 Apr 2013 11:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10407471</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10407471</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/04/18/using-t4-to-eliminate-maintenance.aspx#comments</comments><description>&lt;p&gt;I like to abstract diagnostics (logging and performance counters) into a separate interface or abstract class. But it becomes tedious to manually keep the fake diagnostics (used to test that that proper diagnostics calls are made), dummy diagnostics (when I just need something to pass around), console loggers (used for command line applications) and production logging in sync with the interface. And it is boring to do manually since the first three essentially have the same implementation for all methods.&lt;/p&gt;
&lt;p&gt;So what I've started to do is to use &lt;a href="http://msdn.microsoft.com/en-us/library/bb126445(v=vs.110).aspx" target="_blank"&gt;T4&lt;/a&gt; to generate those three files but also the interface. Production logging is still updated manually but I think it is important to consider exactly what events and performance counters should be triggered by each event. And I want to keep my diagnostics definition simple. So this is what I do:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I created a include file in a common place (solution item)&amp;nbsp;that defines some common classes to generate method declarations and method calls.&lt;/li&gt;
&lt;li&gt;I created a include file&amp;nbsp;in a common place (solution item) that defines my interface.&lt;/li&gt;
&lt;li&gt;I created one template (where needed, typically in different projects) to generate the interface, fake, dummy and console logger.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I find it easy to work with the T4 template files (even though it feels a little like you're back to classical PHP/ASP style programing, but it does remove some boring tasks. And the error messages you get when you have errors in your template have been pretty good for me so it has been easy to correct the problems.&lt;/p&gt;
&lt;p&gt;The only downside with this is that when you change the include file you need to transform the templates manually in visual studio. Unless you install an SDK that defines a build target you can use. This Is because the T4 transformation happens when the template file is saved, not when one of its dependencies change. I did however find &lt;a href="http://stackoverflow.com/questions/1646580/get-visual-studio-to-run-a-t4-template-on-every-build" target="_blank"&gt;this clever way&lt;/a&gt; of getting around it which is essentially running the tool manually as a build step. I prefer that over forcing additional SDKs to be installed by everyone including the build servers. I only hope this will be just working in a future version if VS.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10407471" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/VcBPpJH27Ts" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Tools/">Tools</category><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Development/">Development</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/04/18/using-t4-to-eliminate-maintenance.aspx</feedburner:origLink></item><item><title>Analyzing logs from Azure web sites</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/hoXr_hKRHZc/analyzing-logs-from-azure-web-sites.aspx</link><pubDate>Thu, 11 Apr 2013 11:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10406446</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10406446</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/04/11/analyzing-logs-from-azure-web-sites.aspx#comments</comments><description>&lt;p&gt;I recently played around with &lt;a href="http://www.windowsazure.com/en-us/home/scenarios/web-sites/" target="_blank"&gt;Azure web sites&lt;/a&gt; and wanted to analyze the IIS logs generated by azure but none of the tools I tried could parse the file I downloaded. Turned out that the header line of the file that looks like this:&lt;/p&gt;
&lt;pre&gt;# date time s-sitename cs-method ...&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;That is apparently not correct W3C log format. once I change the line to this:&lt;/p&gt;
&lt;pre&gt;#Fields: date time s-sitename cs-method ...&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;With that change all the tools I tried were happy with the log files.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10406446" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/hoXr_hKRHZc" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Tools/">Tools</category><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Azure/">Azure</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/04/11/analyzing-logs-from-azure-web-sites.aspx</feedburner:origLink></item><item><title>Factory pattern improved</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/U40F64nb44c/factory-pattern-improved.aspx</link><pubDate>Mon, 01 Apr 2013 11:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10402542</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10402542</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/04/01/factory-pattern-improved.aspx#comments</comments><description>&lt;p&gt;My impression of most major west coast cities like Seattle, San Francisco, Los Angeles etc, is that people in general are very healthy. And Redmond where Microsoft have its HQ is even the &lt;a href="http://en.wikipedia.org/wiki/Redmond,_Washington" target="_blank"&gt;bicycle capital of the north west&lt;/a&gt;&amp;nbsp;(I guess anything can be the capital of anything if you just constrain geography in a convenient way). And people who like to exercise also typically like to be environment friendly. And in the spirit to make applications more environmentally friendly there are a few new patterns you need to learn. I have been using these new patterns together with a &lt;a href="http://www.linkedin.com/in/dbroekman" target="_blank"&gt;co-worker&lt;/a&gt;&amp;nbsp;for exactly one year now. The first pattern is a replacement for the polluting factory pattern; &lt;strong&gt;&lt;em&gt;the farmers market pattern&lt;/em&gt;&lt;/strong&gt;!&lt;/p&gt;
&lt;p&gt;The farmers market pattern is similar to the factory pattern in that it is used to create other objects, but instead of having all the bad properties of a factory such as being far away from the object and not caring about the object's community. Factories also tend to keep the benefit they create for themselves.&amp;nbsp;The farmers market pattern gives you a local object that can create your objects on a local and hence more environmentally friendly way. Here is what it looks like in it's most simple form:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Foo
&lt;span class="lnum"&gt; 2: &lt;/span&gt;{
&lt;span class="lnum"&gt; 3: &lt;/span&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; Foo()
&lt;span class="lnum"&gt; 4: &lt;/span&gt;    {
&lt;span class="lnum"&gt; 5: &lt;/span&gt;    }
&lt;span class="lnum"&gt; 6: &lt;/span&gt;&amp;nbsp;
&lt;span class="lnum"&gt; 7: &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; FarmersMarket
&lt;span class="lnum"&gt; 8: &lt;/span&gt;    {
&lt;span class="lnum"&gt; 9: &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Foo Create()
&lt;span class="lnum"&gt; 10: &lt;/span&gt;        {
&lt;span class="lnum"&gt; 11: &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Foo();
&lt;span class="lnum"&gt; 12: &lt;/span&gt;        }
&lt;span class="lnum"&gt; 13: &lt;/span&gt;    }
&lt;span class="lnum"&gt; 14: &lt;/span&gt;}
&lt;/pre&gt;
&lt;p&gt;Having a the farmers market class local like this will save CPU cycles during compilation making sure your application is produced with minimal carbon dioxide footprint. Tomorrow I'll show you the hybrid pattern.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10402542" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/U40F64nb44c" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/-Net/">.Net</category><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Development/">Development</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/04/01/factory-pattern-improved.aspx</feedburner:origLink></item><item><title>Using HTML as your web service format</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/3z47HmFZmtE/using-html-as-your-web-service-format.aspx</link><pubDate>Thu, 28 Mar 2013 10:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10403384</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10403384</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/03/28/using-html-as-your-web-service-format.aspx#comments</comments><description>&lt;p&gt;In the past I've seen examples of clever use of style sheets to turn XML responses into browsable results that are human readable and more important; human navigable. But &lt;a href="http://codeartisan.blogspot.com/2012/07/using-html-as-media-type-for-your-api.html" target="_blank"&gt;this&lt;/a&gt; was the first time I heard about using HTML straight up to create the content of a web service API. It is interesting that there is so much focus of defending HTML as shorter than JSON when I think size should not really be a factor here. Sure, mobile clients want smaller payload but with faster and faster networks and clients with more memory the availability of parser are far more important. but if we can assume that all client have both JSON and XML parsers that is not a deciding factor. I think the most important factor is what the client wants. The linked article mentions that using compressed payload is common and as such it is used as an argument why HTML is not really larger than JSON. But whether or not compression is used is something the clients requests in its request headers. Which content type a client can handled is also an HTTP header so I think it is a no-brainer for a web service to support multiple content types if needed by its clients. Supporting both XML and JSON should be trivial these days and implementing a HTML serializer should be trivial.&lt;/p&gt;
&lt;p&gt;I also think the format the author used for HTML was a little bit surprising. My first thought was to convert the example JSON used into something like this:&lt;/p&gt;
&lt;pre&gt;&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;
&amp;lt;dl&amp;gt;
 &amp;lt;dt&amp;gt;contacts&amp;lt;/dt&amp;gt;
 &amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;dt&amp;gt;firstname&amp;lt;/dt&amp;gt;&amp;lt;dd&amp;gt;Jon&amp;lt;/dd&amp;gt;&amp;lt;dt&amp;gt;lastname&amp;lt;/dt&amp;gt;&amp;lt;dd&amp;gt;Moore&amp;lt;/dd&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;dt&amp;gt;firstname&amp;lt;/dt&amp;gt;&amp;lt;dd&amp;gt;Homer&amp;lt;/dd&amp;gt;&amp;lt;dt&amp;gt;lastname&amp;lt;/dt&amp;gt;&amp;lt;dd&amp;gt;Simpson&amp;lt;/dd&amp;gt;&amp;lt;/li&amp;gt;
 &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;
&amp;lt;/dl&amp;gt;
&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/pre&gt;
&lt;p&gt;That even turned out to be slightly smaller than what was suggested in the article. Not that size matters...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10403384" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/3z47HmFZmtE" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Development/">Development</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/03/28/using-html-as-your-web-service-format.aspx</feedburner:origLink></item><item><title>Analysing code coverage</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/i_dkaOk4j4U/analysing-code-coverage.aspx</link><pubDate>Thu, 21 Mar 2013 13:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10402456</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10402456</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/03/21/analysing-code-coverage.aspx#comments</comments><description>&lt;p&gt;I was recently asked to look at a project that had around&amp;nbsp;60% code coverage and was asked to give my recommendations on what area to focus on to increase the code coverage. There were a lot of unit tests and actually there was around 10% more unit test code than &lt;em&gt;production code &lt;/em&gt;so I was a little surprised that the coverage was as low as 60%. Obviously something must be wrong with the tests. A closer look showed that the code that implemented the logic of the application had very high coverage in general and that only the code dealing with external dependencies had low coverage. Also there wasn't that much code so the boilerplate code just to initialize the application was around 15% of the code. The code dealing with external dependencies and that low coverage was slightly less than 10%. So all in all 60 of the possible 75% was covered. Relatively speaking that is 80% - a number I've often heard managers be very happy with (&lt;a href="http://blogs.msdn.com/b/cellfish/archive/2008/06/16/code-coverage.aspx"&gt;but remember code coverage itself is a shady property to measure&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;So what was missing? Well there were a few cases where a few small classes completely were missing unit tests so they would be easy to fix. There were also a bunch of classes that had unit tests exclusively for the happy path of execution and those can be fixed easily too. But I still think it would be possible to bring coverage up above 90%. How is that possible you might think? Well, the boiler plate code had some, but more important the code dealing with external dependencies had a lot of room for improvement. They were much more than simple pass through objects needing no testing and with a simple refactoring like extracting the external call as a protected virtual method of the class you could easily add unit tests for a huge portion of that code to I think.&lt;/p&gt;
&lt;p&gt;So my conclusion? The original coverage was not bad. It was covering the important pieces and functional tests (not used when I analysed code coverage) covered a big portion of the code not covered by unit tests. So the situation was not bad. But when you use a code coverage report the right way and look at what and why it is not covered you can always find areas of improvement.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10402456" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/i_dkaOk4j4U" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Development/">Development</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/03/21/analysing-code-coverage.aspx</feedburner:origLink></item><item><title>Certificates are hard</title><link>http://feedproxy.google.com/~r/BeingCellfish/~3/x7gngN80M_c/certificates-are-hard.aspx</link><pubDate>Thu, 14 Mar 2013 14:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10396640</guid><dc:creator>Emil Gustafsson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/cellfish/rsscomments.aspx?WeblogPostID=10396640</wfw:commentRss><comments>http://blogs.msdn.com/b/cellfish/archive/2013/03/14/certificates-are-hard.aspx#comments</comments><description>&lt;p&gt;Almost to the day, Azure had &lt;a href="http://blogs.msdn.com/b/windowsazure/archive/2013/02/24/windows-azure-service-disruption-from-expired-certificate.aspx" target="_blank"&gt;another certificate related outage&lt;/a&gt;. &lt;a href="http://blogs.msdn.com/b/cellfish/archive/2012/03/13/time-is-hard.aspx"&gt;Last year was more interesting&lt;/a&gt; I think and this year it was something different. My initial&amp;nbsp;guess (remember I don't work for Azure nor do I have any knowledge about the details other than what has been communicated to the public)&amp;nbsp;was that a few years ago when they were first creating Azure they generated some certificates to be used with SSL. My guess&amp;nbsp;was that the certificates generated were valid for a long time. Probably like 5 years or something. Since the certificates were created long before azure was available to customers nobody thought about adding monitoring to detect when the certificates expired. Turns out &lt;a href="http://blogs.msdn.com/b/windowsazure/archive/2013/03/01/details-of-the-february-22nd-2013-windows-azure-storage-disruption.aspx" target="_blank"&gt;I was wrong&lt;/a&gt; and that there were good alerting in place, but that the process had other flaws.&lt;/p&gt;
&lt;p&gt;So how can you prevent this from happening in your Project? I would suggest you do the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;During development use certificates with very short lifetime. Just one or two months. This way you get used to your certificates expiring and the monitoring you add to warn you when a certificate is about to expire will be tested on a regular basis.&lt;/li&gt;
&lt;li&gt;When you do a risk analysis of your system remember to be detailed and consider the implications of your certificates expiring.&lt;/li&gt;
&lt;li&gt;Learn from others! When things like this happens to the big companies, think about if it could happen to you.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The funniest thing about this outage is an &lt;a href="http://www.news.com.au/technology/microsoft-xbox-azure-services-taken-offline/story-e6frfro0-1226584080719" target="_blank"&gt;article in Australia&lt;/a&gt; thinking this was caused by hackers... I guess I shouldn't get surprised that news papers don't check their facts...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10396640" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/BeingCellfish/~4/x7gngN80M_c" height="1" width="1"/&gt;</description><category domain="http://blogs.msdn.com/b/cellfish/archive/tags/Azure/">Azure</category><feedburner:origLink>http://blogs.msdn.com/b/cellfish/archive/2013/03/14/certificates-are-hard.aspx</feedburner:origLink></item></channel></rss>
