<?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: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/" xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<channel>
	<title>CodeBetter.Com Posts</title>
    
	<link>http://codebetter.com</link>
	<description>Stuff you need to Code Better!</description>
	<lastBuildDate>Thu, 06 Jun 2013 16:31:35 +0000</lastBuildDate>
		<language />
        <image>
		<url>http://codebetter.com/favicon.ico</url>
		<title>CodeBetter.Com Posts</title>
		<link>http://codebetter.com</link>
	</image>
    
<generator>http://wordpress.org/?v=3.5.1</generator>
	<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CodeBetter" /><feedburner:info uri="codebetter" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodeBetter" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodeBetter" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/CodeBetter" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FCodeBetter" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FCodeBetter" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2FCodeBetter" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FCodeBetter" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><item>
		<title>TDD I Learned… Code Katas</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/m6J2hJh8pqg/</link>
		<comments>http://codebetter.com/brendantompkins/2013/06/06/tdd-i-learned-code-katas/#comments</comments>
		<pubDate>Thu, 06 Jun 2013 16:31:35 +0000</pubDate>
		<dc:creator>Brendan Tompkins</dc:creator>
				<category><![CDATA[TDD]]></category>
		<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/brendantompkins/?p=890]]></guid>
		<description><![CDATA[Continuing to make my way through Roy Osherove&#8217;s TDD course.  There&#8217;s an interesting exercise that he introduces to help practice and gain the muscle memory required to do TDD well &#8211; the Code Kata.  Wikipedia attributes the code kata to Dave&#160;&#8230; <a href="http://codebetter.com/brendantompkins/2013/06/06/tdd-i-learned-code-katas/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Continuing to make my way through <a href="https://www.udemy.com/tdd-in-net-with-roy-osherove/">Roy Osherove&#8217;s TDD course</a>.  There&#8217;s an interesting exercise that he introduces to help practice and gain the muscle memory required to do TDD well &#8211; the Code Kata.  <a href="http://en.wikipedia.org/wiki/Kata_(programming)">Wikipedia</a> attributes the code kata to Dave Thomas:</p>
<blockquote><p><b>Code Kata</b> is a term coined by <a title="Dave Thomas (programmer)" href="http://en.wikipedia.org/wiki/Dave_Thomas_(programmer)">Dave Thomas</a>, co-author of the book <i><a title="The Pragmatic Programmer" href="http://en.wikipedia.org/wiki/The_Pragmatic_Programmer">The Pragmatic Programmer</a></i>, in a bow to the Japanese concept of <a title="Kata (martial arts)" href="http://en.wikipedia.org/wiki/Kata_(martial_arts)">kata</a> in the martial arts. A code kata is an exercise in programming which helps a programmer hone their skills through practice and repetition.</p></blockquote>
<p>There&#8217;s <a href="https://github.com/garora/TDD-Katas">a nice project over here</a> on Github containing descriptions and code for a bunch of Katas, including the string calculator  that Roy introduces. Roy&#8217;s site has <a href="http://osherove.com/tdd-kata-1/">the string calculator kata executed in a bunch of different languages</a>, including <a href="http://www.autohotkey.com/">AutoHotkey</a>!</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/m6J2hJh8pqg" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/brendantompkins/2013/06/06/tdd-i-learned-code-katas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/c1de0fbc0dbc3fd24b285009c123d9b0?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Brendan Tompkins</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/brendantompkins/2013/06/06/tdd-i-learned-code-katas/</feedburner:origLink></item>
	<item>
		<title>.Net framework versions and dll hell</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/trS4gOju9Ro/</link>
		<comments>http://codebetter.com/petervanooijen/2013/06/05/net-framework-versions-and-dll-hell/#comments</comments>
		<pubDate>Wed, 05 Jun 2013 10:22:48 +0000</pubDate>
		<dc:creator>Peter van Ooijen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/petervanooijen/?p=712]]></guid>
		<description><![CDATA[With .net version numbers increasing and increasing I recently encountered something which reminded me of dllhell. Which the .net framework promised to end. The nice part is that it already shows up at build time. Not at run time, leading&#160;&#8230; <a href="http://codebetter.com/petervanooijen/2013/06/05/net-framework-versions-and-dll-hell/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>With .net version numbers increasing and increasing I recently encountered something which reminded me of <a href="http://en.wikipedia.org/wiki/DLL_Hell">dllhell</a>. Which the .net framework promised to end. The nice part is that it already shows up at build time. Not at run time, leading to disappointed customers. Framework versions can be mixed in one solution. Up to the moment one assembly references another assembly built against a higher version. At this moment the VS build process starts to lose track.</p>
<p>The catch is that it’s not always clear you’re mixing framework versions in a solution. Adding a new project will default against the newest framework version. Which is not constant over a solution’s life time. The result can be quite strange. I managed to get away with a circular reference which was not seen because one project was using a version of the other built against an older framework version. And was thus considered a different assembly. Up to the moment I checked the framework version of all projects.</p>
<p>The only good way to solve this descend into hell would be having all projects in the solution on one version. In a big solution with a lot of projects this can be quite tedious. I would love to be able to set the version on the solution level. Or else to have a nice ‘refactoring’ tool to the work for me. R# are you listening ?</p>
<p>&nbsp;</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/trS4gOju9Ro" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/petervanooijen/2013/06/05/net-framework-versions-and-dll-hell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/5cb0e972c5e405e6bff7e7f2da237c6d?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Peter van Ooijen</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/petervanooijen/2013/06/05/net-framework-versions-and-dll-hell/</feedburner:origLink></item>
	<item>
		<title>A typical effect of setting CopyLocal = true</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/ssp1s-S4sD8/</link>
		<comments>http://codebetter.com/patricksmacchia/2013/05/30/a-typical-effect-of-setting-copylocal-true/#comments</comments>
		<pubDate>Thu, 30 May 2013 08:27:09 +0000</pubDate>
		<dc:creator>Patrick Smacchia</dc:creator>
				<category><![CDATA[Acyclic componentization]]></category>
		<category><![CDATA[Code Dependency]]></category>
		<category><![CDATA[code structure]]></category>
		<category><![CDATA[Code visualization]]></category>
		<category><![CDATA[CopyLocal syndrome]]></category>
		<category><![CDATA[Dependency Cycle]]></category>
		<category><![CDATA[Dependency Graph]]></category>
		<category><![CDATA[Dependency Matrix]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[Graph of Dependencies]]></category>
		<category><![CDATA[Lines of Code]]></category>
		<category><![CDATA[Maintainability]]></category>
		<category><![CDATA[Partitioning]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[VS]]></category>
		<category><![CDATA[VStudio]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/patricksmacchia/?p=824]]></guid>
		<description><![CDATA[If you read me in the past, you certainly know that I have a problem about the Visual Studio default option that set CopyLocal = true in project references assemblies. I mean this option: I&#8217;ve already explained the problem in&#160;&#8230; <a href="http://codebetter.com/patricksmacchia/2013/05/30/a-typical-effect-of-setting-copylocal-true/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>If you read me in the past, you certainly know that I have a problem about the Visual Studio default option that set <em>CopyLocal = true</em> in project references assemblies. I mean this option:</p>
<p><a href="http://codebetter.com/patricksmacchia/files/2013/05/NancyCopyLocal.png"><img class="alignnone size-full wp-image-825" alt="NancyCopyLocal" src="http://codebetter.com/patricksmacchia/files/2013/05/NancyCopyLocal.png" width="318" height="292" /></a></p>
<p>I&#8217;ve already explained the problem in my blog, and also in <a href="http://www.ndepend.com/WhiteBooks.aspx">White-Books available on the NDepend website</a>. (see white-book <a href="http://www.ndepend.com/Res/NDependWhiteBook_Assembly.pdf" target="_blank">Partitioning code base through .NET assemblies and Visual Studio projects</a> page 4 <strong>CopyLocal = true is evil</strong>)</p>
<p><a href="http://codebetter.com/patricksmacchia/files/2013/05/CopyLocalEvil.png"><img class="alignnone size-full wp-image-826" alt="CopyLocalEvil" src="http://codebetter.com/patricksmacchia/files/2013/05/CopyLocalEvil.png" width="482" height="121" /></a></p>
<p>For example, in 2009 <a href="http://codebetter.com/patricksmacchia/2009/01/11/lessons-learned-from-the-nunit-code-base/" target="_blank">by fixing the problem on the NUnit code base</a>, I&#8217;ve been able in less than an hour, to shrink the compilation time from 32 seconds to 12 seconds.</p>
<p>So what is the consequence of <a href="http://nancyfx.org/">Nancy framework</a> relying on <em>CopyLocal = true</em>: A huge number of cloned version on Nancy.DLL for each VS project referencing it. After a recompilation, I can count 56 occurences of Nancy.dll that weights 842 KB each, it means more than 46MB wasted. Apparently it doesn&#8217;t affect so much the VS compilation duration, I guess the VS team made VS 2012 more intelligent in the sense that if it has already parsed a reference assembly for a project, it doesn&#8217;t parse it for others, which is a good thing.</p>
<p><a href="http://codebetter.com/patricksmacchia/files/2013/05/NancyDuplication.jpg"><img class="alignnone size-full wp-image-829" alt="NancyDuplication" src="http://codebetter.com/patricksmacchia/files/2013/05/NancyDuplication.jpg" width="600" height="559" /></a></p>
<p>I tried to post something on the <a href="https://groups.google.com/forum/#!forum/nancy-web-framework" target="_blank">Nancy user group</a>, without success, hence this post. To fix this issue, it is as simple as:</p>
<ul>
<li>making sure that each project compile in a <em>..\bin\Debug</em> and <em>..\bin\Release</em> folder</li>
<li>from VS projects, reference the DLLs in the <em>..\bin\Debug</em> directory, and set<em> CopyLocal = false</em> for each reference</li>
</ul>
<p>Additional, I found <em>..\bin</em> to be a good folder to host test assemblies. This way they can reference the application assemblies that live in <em>..\bin\Debug </em>and the indirection can be handled with a <em>App.config</em> file like:</p>
<script src="http://gist.github.com/5676329.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5676329" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-txt-L1" rel="file-gistfile1-txt-L1">1</span>
          <span class="line-number" id="file-gistfile1-txt-L2" rel="file-gistfile1-txt-L2">2</span>
          <span class="line-number" id="file-gistfile1-txt-L3" rel="file-gistfile1-txt-L3">3</span>
          <span class="line-number" id="file-gistfile1-txt-L4" rel="file-gistfile1-txt-L4">4</span>
          <span class="line-number" id="file-gistfile1-txt-L5" rel="file-gistfile1-txt-L5">5</span>
          <span class="line-number" id="file-gistfile1-txt-L6" rel="file-gistfile1-txt-L6">6</span>
          <span class="line-number" id="file-gistfile1-txt-L7" rel="file-gistfile1-txt-L7">7</span>
          <span class="line-number" id="file-gistfile1-txt-L8" rel="file-gistfile1-txt-L8">8</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-txt-LC1">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;</div><div class="line" id="file-gistfile1-txt-LC2">&lt;configuration&gt;</div><div class="line" id="file-gistfile1-txt-LC3">  &lt;runtime&gt;</div><div class="line" id="file-gistfile1-txt-LC4">    &lt;assemblyBinding xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot;&gt;</div><div class="line" id="file-gistfile1-txt-LC5">      &lt;probing privatePath=&quot;Debug&quot; /&gt;</div><div class="line" id="file-gistfile1-txt-LC6">    &lt;/assemblyBinding&gt;</div><div class="line" id="file-gistfile1-txt-LC7">  &lt;/runtime&gt;</div><div class="line" id="file-gistfile1-txt-LC8">&lt;/configuration&gt;</div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/anonymous/5676329/raw/c91a0ddd751ce082686065a78563fe34050ef353/gistfile1.txt" style="float:right">view raw</a>
          <a href="https://gist.github.com/anonymous/5676329#file-gistfile1-txt" style="float:right; margin-right:10px; color:#666;">gistfile1.txt</a>
          <a href="https://gist.github.com/anonymous/5676329">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<h1><strong>On Nancy code structure</strong></h1>
<p>One very good point is that <em>Nancy.dll</em> is a single DLL that only depends on .NET Fx assemblies so it is optimally packaged.</p>
<p><a href="http://codebetter.com/patricksmacchia/files/2013/05/NancyRefs.png"><img class="alignnone size-full wp-image-834" alt="NancyRefs" src="http://codebetter.com/patricksmacchia/files/2013/05/NancyRefs.png" width="573" height="136" /></a></p>
<p>On the other hand, this large DLL made of more than 7.000 lines of code and almost 300 classes, doesn&#8217;t abide by any kind of layered architecture. The consequence is that each namespace depends on all other namespaces.</p>
<p><a href="http://codebetter.com/patricksmacchia/files/2013/05/NancyGraph.png"><img class="alignnone size-full wp-image-831" alt="NancyGraph" src="http://codebetter.com/patricksmacchia/files/2013/05/NancyGraph.png" width="571" height="604" /></a></p>
<p>As a consequences classes are not layered at all, there is no high level or low level classes.</p>
<p>Let&#8217;s have a look at the dependency matrix below. It is made of the 287 Nancy.dll classes, in mode indirect dependency. A blue cells means that the class in column depends (directly or indirectly) on the class in row, a green cell means the opposite, and a black cell means that the 2 classes are dependents on each others. A perfectly layered set of classes (which is not wished, but what should be approached) would be a lower triangular matrix blue, and a higher triangular matrix green. Here the matrix has blue and green cells mixed equally in both lower and higher triangulars, which is another way to figured out that classes are not layered.</p>
<p><a href="http://codebetter.com/patricksmacchia/files/2013/05/NancyMatrix.jpg"><img class="alignnone size-full wp-image-832" alt="NancyMatrix" src="http://codebetter.com/patricksmacchia/files/2013/05/NancyMatrix.jpg" width="600" height="533" /></a></p>
<p>It means that it must be difficult to unit-test a set of cohesive classes (i.e a component) in isolation from the others (even by using mocks that don&#8217;t help in case or re-entrant dependency). It also means that maintenance and evolution must be impaired by this absence of code structure, because touching a single class can virtually have an unexpected effect anywhere in the code base.</p>
<h2></h2>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/ssp1s-S4sD8" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/patricksmacchia/2013/05/30/a-typical-effect-of-setting-copylocal-true/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/aff180ba8312104219eb0c2529aa131e?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Patrick Smacchia</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/patricksmacchia/2013/05/30/a-typical-effect-of-setting-copylocal-true/</feedburner:origLink></item>
	<item>
		<title>Why Can’t I Update an Event?</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/NnDGk0Bxa9k/</link>
		<comments>http://codebetter.com/gregyoung/2013/05/28/why-cant-i-update-an-event/#comments</comments>
		<pubDate>Tue, 28 May 2013 06:26:59 +0000</pubDate>
		<dc:creator>gregyoung</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/gregyoung/?p=402]]></guid>
		<description><![CDATA[Last week on a call with someone the question came up about the Event Store about why can they not update and event and how should they handle the case where they need to. The conversation that came out of&#160;&#8230; <a href="http://codebetter.com/gregyoung/2013/05/28/why-cant-i-update-an-event/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Last week on a call with someone the question came up about the Event Store about why can they not update and event and how should they handle the case where they need to. The conversation that came out of this was very rich in architectural insight into how the event store works as well as overall event sourcing understanding so I thought that it would be worth spending a bit of time to write up where the constraint comes from.</p>
<h2>An Event Sourcing Perspective</h2>
<p>Let&#8217;s start with why you want to update an event? An event is a fact that happened at a point in time with the understanding of it from that point in time, a new understanding of the fact would be a new fact(naturally this does not apply to politicians). To update a previous event is generally a very bad idea. Many want to go back and update events to new versions, this is not the best way to handle versioning!</p>
<p>The prefered mechanism from an event sourcing perspective is to write a new face that supercedes the old fact. As an example I could write that event 7 is a mistake, this is a correction, I might as well put in a comment &#8220;this was due to bug #1342&#8243; (similar to a journal entry in accounting). There are a few reasons this is a better way of handling things.</p>
<p>The first is my ability to look back at my history. If I were to change the fact and I look back at that point in time I have changed what it means. What about others who made decisions at that point in time? I can no longer see what it was they made decisions off of. Beyond this I might have a very valid query to ask your event streams of &#8220;how long on average does it take us to find bugs in previous events&#8221;.</p>
<p>The second model leads us to two types of queries supported on event streams (as-of vs as-at).</p>
<p>Beyond that with Event Sourcing the updating of an event can be inherently evil. How do you update any projections that the update occured? What about other subscribers who may be listening to the streams? Any easy answer might be to replay fully all involved with the stream but this quickly falls apart.</p>
<p>These are the primary reasons why the Event Store does not support an update operation on an event. There are however some wonderful architectural benefits that come from this particular constraint.</p>
<h2>Architectural Goodness</h2>
<p>If we prevent an event from ever being updated, what would the cachability of that event be? Yes it would be infinite. The Event Store supports a RESTful API (ATOM). All events served from the event store have infinite cachability, what does that mean?</p>
<p>Imagine you have a projection updating into a SQL table that has been running for the past eight weeks. You make a change and need to restart it (replaying from event 0). When the replay occurs and it requests events from the Event Store where do they likely come from? Your hard drive! You don&#8217;t make requests to the Event Store for them.</p>
<p>Beyond the events being infinitely cachable if you look through our atom implementation in fact every single request we serve with the exception of the head uri (http://somewhere.com/streams/{stream}) is also infinitely cachable. In other words when you want to reread $all (say for 5m events) you will hit exactly one non-cachable request!</p>
<p>This is very important when we start talking about scalability and performance. The Event Store can pretty easily serve 3-5k atom requests/second on a laptop (per node in clustered version) but how many will actually get to the Event Store? In order to scale you focus on commoditized reverse proxies in front of the Event Store not scaling the Event Store itself. nginx or varnish can easily saturate your network, just drop them in front only head calls make it through (and there is even a setting per stream to allow caching for x seconds of head links).</p>
<p>This is often a hard lesson to learn for developers. More often than not you should not try to scale your own software but instead prefer to scale commoditized things. Building performant and scalable things is hard, the smaller the surface area the better. Which is a more complex problem a basic reverse proxy or your business domain?</p>
<p>This also affects performance of replays for subscribers as you can place proxies near the subscribers (local http cache is a great start!). This is especially true for say an occasionally connected system. Gmail uses this trick to provide &#8220;offlining out of the box&#8221; for web apps. Since much of the data will already be in the http cache your hits will be hitting it, in many cases you can build say a mobile app with no further support.</p>
<p>Over Atom if we allowed updates, NO uris could be cachable!</p>
<h2>This is all cool but I actually need to update!</h2>
<p>Occasionally there might be a valid reason why an event actually needs to be updated, I am not sure what they are but I imagine there must be some that exist. There are a few ways this can actually be done.</p>
<p>The generally accepted way of handling the scenario while staying within the no-update constraintis to create an entire new stream, copy all the events from the old stream (manipulating as they are copied). Then delete the old stream. This may seem like a PITA but remember all of the discussion above (especially about updating subscribers!).</p>
<p>Some however may be using the TCP API and are willing to take the pains and complexity that come from subscribers (you can imagine they have none). In this one case, updates would be acceptable and simpler than adding new events. We have been going back and forth on whether or not to support this. It would not be much work at all for us but I imagine that it would be misused 1000 times for every 1 time it was used reasonably. I am reminded of the examples of being able to call .NET code from a biztalk orchestration or being able to execute .NET code inside my SQL database both have valid uses but should rarely be used. Perhaps we will make a command line parameter &#8211;run-with-scissors-updates or make people build from source to enable.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/NnDGk0Bxa9k" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/gregyoung/2013/05/28/why-cant-i-update-an-event/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/8a61736c3f6b3e02b173c9aa6ce6ca8e?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">gregyoung</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/gregyoung/2013/05/28/why-cant-i-update-an-event/</feedburner:origLink></item>
	<item>
		<title>TDD I Learned…</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/GRe-6Cd29AU/</link>
		<comments>http://codebetter.com/brendantompkins/2013/05/24/tdd-i-learned/#comments</comments>
		<pubDate>Fri, 24 May 2013 13:45:18 +0000</pubDate>
		<dc:creator>Brendan Tompkins</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[TDD]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/brendantompkins/?p=891]]></guid>
		<description><![CDATA[A few weeks ago, Roy Osherove released his full TDD master class in .NET available a video series of over nine hours, recorded live in class. I&#8217;m a TDD wannabe.  I&#8217;ve done small tasks using TDD, and I&#8217;ve written plenty of&#160;&#8230; <a href="http://codebetter.com/brendantompkins/2013/05/24/tdd-i-learned/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>A few weeks ago, <a href="http://osherove.com/">Roy Osherove</a> <a href="https://go.madmimi.com/redirects/1363545594-b74e8b07eb6aa688a66bdc9837564a54-5a302e6?pa=381768481047987771" target="_blank">released his full TDD master class in .NET available a video series of over nine hours, recorded live in class</a>.</p>
<p>I&#8217;m a TDD wannabe.  I&#8217;ve done small tasks using TDD, and I&#8217;ve written plenty of tests, but most just get shuffled around, never included in my CI builds, and basically the entire thing is a mess&#8230;  Perhaps it&#8217;s because I&#8217;ve been <a href="http://codebetter.com/gregyoung/2013/03/06/startups-and-tdd/">writing code for startups</a>, but most likely it&#8217;s because I&#8217;ve just not taken the time to learn the right way.  I&#8217;ve never truly seen the benefits that it can bring.  So I saw this class as a great chance to learn from the master.</p>
<p>I&#8217;m going to blog about my experiences going through this course.  I&#8217;ve been through the first two hours, and so far I really like the pace and Roy&#8217;s teaching style.  Roy is snarky-funny, and so the content is entertaining to boot.</p>
<p>So here are some of the more interesting things that I&#8217;ve learned from the course so far&#8230;</p>
<p><strong>Difference between Integration Tests and Unit Tests</strong></p>
<p>Although the generally <a href="http://stackoverflow.com/questions/10752/what-is-the-difference-between-integration-and-unit-tests">accepted definition of the difference may be up to some debate</a>, Roy&#8217;s definition is simple, I like it, and it&#8217;s useful for me.  Roy says that a unit test is all in memory.  It should pass on any new developer&#8217;s machine, and is not tied to disk, databases or anything outside of the memory scope of the test.  This is important because confidence in your unit tests is paramount.  If you cannot trust that a failing test is due to a bug, i.e. if it&#8217;s due to some setup on disk, etc. it diminishes the usefulness of your test suite and developers cannot quickly setup to work on a codebase.</p>
<p><strong>Arrange, Act, Assert</strong></p>
<p>The three A&#8217;s of unit testing was new to me, and  <a href="http://c2.com/cgi/wiki?ArrangeActAssert">is a pattern</a> for writing tests that Roy introduces:</p>
<blockquote><p>Each method should group these functional sections, separated by blank lines:</p>
<ol>
<li><strong>Arrange</strong> all necessary preconditions and inputs.</li>
<li><strong>Act</strong> on the object or method under test.</li>
<li><strong>Assert</strong> that the expected results have occurred.</li>
</ol>
</blockquote>
<p><span style="font-size: 16px;">This approach, by eliminating assert code intermixed with code that sets up or acts upon your objects, reduces smelly tests by separating what is being tested from all the other stuff.  See, I need stuff like this to help me fall into a pit of success of testing.  </span></p>
<p>There&#8217;s a lot of good stuff in there about creating readable and maintainable tests.  Roy also delves into best practices for naming tests, offers some good hints on how to setup Resharper live templates, a good deal of information on why he prefers <a href="http://www.testdriven.net/">TestDriven.Net</a> as a test runner (and how to use it to debug methods directly!) including an interesting history lesson on <a href="http://jameskovacs.com/2007/05/31/microsoft-vs-jamie-cansdale/">MSFT vs  TestDriven.Net&#8217;s Jamie Cansdale</a>.</p>
<p>W<span style="font-size: 16px;">ith over nine hours of course total, I&#8217;m expecting to learn a lot.  Oh, and apparently serial killers practice TDD.  :)</span></p>
<p>-Brendan</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/GRe-6Cd29AU" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/brendantompkins/2013/05/24/tdd-i-learned/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/c1de0fbc0dbc3fd24b285009c123d9b0?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Brendan Tompkins</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/brendantompkins/2013/05/24/tdd-i-learned/</feedburner:origLink></item>
	<item>
		<title>Pre-Process your images with promises</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/RP09-r6Nx3Q/</link>
		<comments>http://codebetter.com/johnvpetersen/2013/05/20/pre-process-your-images-with-promises/#comments</comments>
		<pubDate>Mon, 20 May 2013 15:40:35 +0000</pubDate>
		<dc:creator>johnvpetersen</dc:creator>
				<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WinJS]]></category>
		<category><![CDATA[promises]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/johnvpetersen/?p=584]]></guid>
		<description><![CDATA[For this post, I&#8217;m using Windows 8 WinJS as the vehicle. However, this approach is applicable by any method that implements an XMLHttpRequest. Here&#8217;s the scenario: you have an application with several images and those images are stored on a&#160;&#8230; <a href="http://codebetter.com/johnvpetersen/2013/05/20/pre-process-your-images-with-promises/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>For this post, I&#8217;m using Windows 8 WinJS as the vehicle. However, this approach is applicable by any method that implements an XMLHttpRequest.</p>
<p>Here&#8217;s the scenario: you have an application with several images and those images are stored on a remote server. The sources of each image is something like http://someserver.com/myimage.png. </p>
<p>Looking at a Windows 8 store app as an example, the good news is that your page will display immediately. Your images <em>may</em> display immediately. Or more likely, they will begin to display <em>after</em> the page has loaded. You may see the images incrementally appearing. This does not make for a good user experience. </p>
<p>The good news is that WinJS implements the Promise Pattern and XMLHttpRequest via the WinJS.xhr object. This means we can pre-fetch images and resolve them to blob URL&#8217;s and then bind our UI to the blob URL instead of the raw image url.</p>
<p>Using a stock WinJS Navigation Project, the following code is placed in the app.addEventListener(&#8220;activated&#8221;, function (args) {} handler:</p>
<pre class="brush: jscript; title: ; notranslate" title="">
var promises = [];

//Load the blob for the default image in the event a specified image URL does not work.
WinJS.xhr({ url: &quot;images/no-available-image.png&quot;, responseType: &quot;blob&quot; }).done(function 
(data) {
 var noImageBlob = URL.createObjectURL(data.response);
  //The imageResults.json file is a static result from the Bing Images API.
  WinJS.xhr({ url: &quot;js/imageResults.json&quot; }).done(function (data) {
     var results = JSON.parse(data.responseText);
     //Loop through the results to create the promise array.
     results.d.results[0].Image.forEach(function (element, index, array) {
     promises[index] = WinJS.xhr({ url: element.MediaUrl, responseType: &quot;blob&quot; })
        .then(function (e) {
           //When the promise executes, an imageBlob property is created
           //holding the image blob URL
           results.d.results[0].Image[index].imageBlob = URL.createObjectURL(e.response);
        }, function error(e) {
           //If an error occurs when trying to retrieve the image
           //the No Image BLob URL created on line 28 is used instead
           results.d.results[0].Image[index].imageBlob = noImageBlob;
        });
     });
     //The join method kicks off the promises handed to it.
     //The promises can run in any order and finish at any time. 
     //The done event for the join method fires after all of the promises
     //in the promise array have been fulfilled.
     WinJS.Promise.join(promises).done(function (e) {
        //Need to create a global namespace to hold a reference
        //to the images array. To facilitate data binding, 
        //the WinJS.BindingList method is invoked, passing the 
        //image array.
        WinJS.Namespace.define(&quot;ImageList&quot;,
           {
              Images: new WinJS.Binding.List(results.d.results[0].Image)
           });;
           //Now that all of the pre-processing has occurred, we can now
           //navigate to the home page that displays the images.
           if (app.sessionState.history) {
              nav.history = app.sessionState.history;
           }
           args.setPromise(WinJS.UI.processAll().then(function () {
              if (nav.location) {
                 nav.history.current.initialPlaceholder = true;
               return nav.navigate(nav.location, nav.state);
           }
           else {
                return nav.navigate(Application.navigator.home);
           }
        }));
     });
  });
);
</pre>
<p>JavasScript, being a dynamic language, we can simply augment the object from the parsed JSON. In this example, I used a static file from the Bing Image Search API. You will have to conform the object references to the specific API you are working with. In the previous code, we wait until all of the images have been fetch. In an async world, this can be a challenge. We don&#8217;t know what order the requests will be processed. In some cases, a server status 500 could result. This approach affords us an opportunity to handle that error with a place holder image. If on the other hand, you deal with the raw URL&#8217;s directly, you have no such opportunity to intercept errors.</p>
<p>On the HTML markup side, I have this code to bind an image tag&#8217;s src to the newly created imageBlob property. For this example, the raw URL that is returned in the response is MediaUrl. </p>
<pre class="brush: xml; title: ; notranslate" title="">
&lt;section aria-label=&quot;Main content&quot; role=&quot;main&quot;&gt;
   &lt;div id=&quot;ImagesTemplate&quot; data-win-control=&quot;WinJS.Binding.Template&quot;&gt;
      &lt;div style=&quot;width: 150px; height: 100px;&quot;&gt;
          &lt;img src=&quot;#&quot; style=&quot;width: 60px; height: 60px;&quot; 
              data-win-bind=&quot;alt: MediaUrl; src: imageBlob&quot; /&gt;
      &lt;div&gt;
       &lt;h4 data-win-bind=&quot;innerText: MediaUrl&quot;&gt;&lt;/h4&gt;
      &lt;/div&gt;
   &lt;/div&gt;
&lt;/section&gt;
&lt;div id=&quot;ImageListView&quot; 
   data-win-control=&quot;WinJS.UI.ListView&quot;  
   data-win-options=&quot;{itemDataSource : ImageList.Images.dataSource, 
                      itemTemplate: select('#ImagesTemplate')}&quot;&gt;
&lt;/div&gt;
</pre>
<p>In the markup, I have a WinJS ListView control that uses the ImageList.Images.dataSource as its datasource. The ListView also references a simple template to display the output.</p>
<p>Here is the result (looks a bit skewed due to this page&#8217;s dimensions):</p>
<p><a href="http://codebetter.com/johnvpetersen/files/2013/05/images.png"><img src="http://codebetter.com/johnvpetersen/files/2013/05/images.png" alt="images" width="1792" height="469" class="alignleft size-full wp-image-587" /></a> </p>
<p>When the page displays, because the images have already been pre-fetched, they will immediately display as well. This makes for a more pleasant user experience. </p>
<p>Looking at the first image, it has a raw URL of:</p>
<p>http://www.israbox.com/uploads/posts/2011-04/1303738133_john-coltrane.jpg</p>
<p>When pre-fetched, the blob URL is:</p>
<p>blob:354BAAC6-B8D8-4172-A283-4DF2F037FECD</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/RP09-r6Nx3Q" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/johnvpetersen/2013/05/20/pre-process-your-images-with-promises/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/545d3ad0823f1fc4431ff9521a8e74f1?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">johnvpetersen</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/johnvpetersen/2013/05/20/pre-process-your-images-with-promises/</feedburner:origLink></item>
	<item>
		<title>The joy of being a programmer</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/WUQ4mwi7myE/</link>
		<comments>http://codebetter.com/patricksmacchia/2013/05/17/the-joy-of-being-a-programmer/#comments</comments>
		<pubDate>Fri, 17 May 2013 14:04:45 +0000</pubDate>
		<dc:creator>Patrick Smacchia</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/patricksmacchia/?p=813]]></guid>
		<description><![CDATA[I am programming since I am 10 and I am now 38. Today I measure how much good programming bring to my life, directly and indirectly. I&#8217;d like to give credit to aspects I love in my job. Hopefully some&#160;&#8230; <a href="http://codebetter.com/patricksmacchia/2013/05/17/the-joy-of-being-a-programmer/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>I am programming since I am 10 and I am now 38. Today I measure how much good programming bring to my life, directly and indirectly. I&#8217;d like to give credit to aspects I love in my job. Hopefully some young people will read this and will consider maybe doing one of the most wonderful job on earth.</p>
<p><strong>Getting in the flow:</strong> According to <a href="http://en.wikipedia.org/wiki/Flow_(psychology)" target="_blank">wikipedia</a>, <em>flow is the mental state of operation in which a person performing an activity is fully immersed in a feeling of energized focus, full involvement, and enjoyment in the process of the activity. In essence, flow is characterized by complete absorption in what one does</em>. Focus, immersion, being concentrated, involvement &#8230;  being everyday in the flow by coding hours and hours, contribute a lot to a solid positive state of mind, it is a bit like meditation.  These are moments where one can completely forget about minor everyday pesky stuff, but also forget for a while more serious problem in life everyone has to face. Being in the flow is the condition to solve challenging problems and to create beautiful pieces of engineering. Being in the flow can lead to addiction but it is not addiction. This is essential to control when to check-in in the flow and when check-out, making sure to not be disturbed meantime.</p>
<p><strong>Being creative:</strong> Being a software engineer is one of the most mainstream way of being paid for being creative. Often, writing software is deemed to be an artistic activity. A programmer has to be humble, because this is a kind of art not understood by the mass. But being humble is a chance to become wiser and increase self-confidence. Also, knowing you are going to be creative for a while, is an excellent motivation to overcome the first step effort to jump in the flow. But the truth is that for every passionate programmer, there is a background thread in the mind in charge of creativity (often running at sleep-time), that makes it so that in the morning the envy to create what you have in mind is too strong.</p>
<p><strong>Becoming an expert:</strong> It is common to hear that a programmer must know numerous technologies, that its skill is to learn how to learn new technologies. On this I disagree because what makes me really happy is to master completely a technology and exercise daily my expertise. I used to master all the tricky details of C++ and COM and it was fun. Before that I used to master some assembly level programming and it was fun, I was not even getting paid for <a href="http://en.wikipedia.org/wiki/Amiga_demos" target="_blank">that</a>. In 2002/2003 and then  2005 I wrote two editions of a <a href="http://www.amazon.fr/Pratique-NET-2-0-C/dp/2841773396" target="_blank">1.000 pages book on .NET and C#</a> and writing it has been one of the most blessed moment in my career. Since then I capitalize on this knowledge every single hour of coding, letting me focus my thoughts on problems to solve, and not on all the non-trivial things a complex platform like .NET is actually performing under my feet. Of course I am constantly discovering new details about surrounding technologies, like functional programming paradigms through the prism of functional paradigm introduced in .NET languages. But I know what is my core knowledge, both in terms of technologies and in term of program design skills. And as long as I won&#8217;t be forced to change my core skills, relying on my expertise to express my creativity and making a living on top of it is a source of personal achievement.</p>
<p><strong>Meet inspiring people sharing the same passion:</strong> I imagine meeting peers is a source of happiness for every expert in something. This is also why investing in a solid programming particular set of skills is a positive thing. Not only respect from others programmers arise, but it lets have great exchange with smart people as passionate as you. The importance of flow, underlined above, also comes with the disadvantage of being often alone with your thoughts. Most programmers enjoy working alone anyway, but for those who need a bit of more social activity, having an expertise in something is also a great way to become <em>partly</em> a teacher (in professional or academic spheres), <em>partly</em> an architect and contribute to important decisions, <em>partly</em> a team-leader and be responsible for project progressing, <em>partly</em> a consultant, and be able to share your knowledge in a pleasant social environment. I put the word <em>partly</em> in italic because if your social activity make it so that you are not writing code meant to be run in production anymore, you shouldn&#8217;t consider you as a programmer anymore and you&#8217;ll loose a great deal of the points I am mentioning here. If you need social interactions all day long, programming is not for you. This is also why (sadly) there are so few women in software, because <a href="http://en.wikipedia.org/wiki/Evolutionary_psychology" target="_blank">evolution</a> designed them to be much more social beings than men.</p>
<p><strong>Being involved in something that make sense:</strong> Here also my position might be a bit different of what is widely accepted. I agree that for juniors, it is important to multiply the opportunities to work in several different teams and companies, to get an idea of what they like and what they don&#8217;t, to be influenced by several inspiring mentors. But once you become seniors, working on the same application in the long term, where you feel well programming in,  polishing it days after days, seeing its evolution across years, maintaining it in a clean state by adopting modern paradigms like automatic tests, DbC or relentless refactoring, having your word to say about strategic decisions, personally I found this being a great source of daily happiness and a great motivation to involve myself! In addition, working hard to achieving important milestones regularly, is an excellent way to give a sense to your professional career, which is (much) more the exception than the rule.</p>
<p><strong>Work wherever, whenever you like:</strong> A 2KG laptop with the proper tools set installed, a few hours of electricity every 24 hours, this is all what a programmer needs to do his job well. A descent internet connection is often appreciated, and there are today only few points on earth where internet is not available at all somehow. Programming might be probably the less demanding working activity in terms of time and space requirement. Getting in a flow in a 12 hours plane flying across the planet, scheduling half a year to live and work in a <a href="http://www.youtube.com/watch?v=-a2jugsYQXM" target="_blank">paradise tropical island</a>, avoiding traffic jam by staying at home for work (in your pijama), delaying programming in the night or early morning to take care of the kids and their education, all this is not only possible but pretty common actually. Most serious software companies let some of their skilled engineers work wherever they prefer. Did you know that many of the great minds behind Visual Studio didn&#8217;t actually moved with their family to Seattle, but still live in their preferred location, sometime far away from the US?</p>
<p><strong>Make a decent living doing something you like: </strong>Last but not least, everywhere, skilled programmers get paid above the average salary in their countries, and if we take the example of a developing country like India, good programmers get a much much higher income than the average. On top of that, a skilled programmer have pretty close to zero chances to remain unemployed for a long time. This also means that if you don&#8217;t like your current position, it is easy to find another better suited one. This situation is made possible because less than two decades ago, the modern civilization realized that IT is the condition for its development. It is a fact that many of the richest persons in the world were originally programmers and every motivated programmer has the potential to create <a href="http://www.ndepend.com/" target="_blank">its own ISV business</a>. A programmer can also decide to make more money by coding for the financial industry, or even bet on a startup and potentially makes millions in a few years.</p>
<p>All the next big things will consume even more IT, this includes human genome analysis for the mass, the entire medicine that will be deeply impacted by that, more prevalent portable devices, more sophisticated entertainments, augmented reality, robots and automated machines to do surgery, to assist the increasing growing number of old people, artificial intelligence in the long term, and certainly everything nobody hasn&#8217;t imagined yet. After all 20 years ago, nobody anticipated the impact of Google. 10 years ago nobody anticipated the impact of Facebook and smart phones.</p>
<p>Ok enough getting in the flow of writing my passion for programming, I have some code to write before the weekend <img src='http://codebetter.com/patricksmacchia/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/WUQ4mwi7myE" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/patricksmacchia/2013/05/17/the-joy-of-being-a-programmer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/aff180ba8312104219eb0c2529aa131e?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Patrick Smacchia</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/patricksmacchia/2013/05/17/the-joy-of-being-a-programmer/</feedburner:origLink></item>
	<item>
		<title>Scripting ease with Script Packs</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/DPgX8Cv04nM/</link>
		<comments>http://codebetter.com/glennblock/2013/05/14/scripting-ease-with-script-packs/#comments</comments>
		<pubDate>Tue, 14 May 2013 18:10:28 +0000</pubDate>
		<dc:creator>Glenn Block</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[scriptcs]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/glennblock/?p=736]]></guid>
		<description><![CDATA[Script Packs are a really cool extensibility point we added into scriptcs. A pack delivers a bundle of functionality that makes frameworks more palatable to consume from script. They are available as nuget packages making them very easy to consume.&#160;&#8230; <a href="http://codebetter.com/glennblock/2013/05/14/scripting-ease-with-script-packs/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Script Packs are a really cool extensibility point we added into scriptcs. A pack delivers a bundle of functionality that makes frameworks more palatable to consume from script. They are available as nuget packages making them very easy to consume.</p>
<p>For example, if you look at our <a href="https://github.com/scriptcs/scriptcs-samples/tree/master/webapihost">Web API sample</a>, you’ll see there’s a bunch of friction if you just try to get Web Api working from scratch.</p>
<ul>
<li>You need to add <a href="https://github.com/scriptcs/scriptcs-samples/blob/master/webapihost/start.csx#L4">using</a> statements for each namespace you want to use. This is a lot more painful than one might think when you don’t have intellisense.</li>
<li>You need to <a href="https://github.com/scriptcs/scriptcs-samples/blob/master/webapihost/webapiconfig.csx#L11">configure</a> web API, this involves creating a host, defining default routes etc. Adding lots of object creation and such starts to make the script pretty hairy. Not impossible, but painful when there’s no template.</li>
<li>You need to teach Web Api how to resolve controllers in script by implementing a custom <a href="https://github.com/scriptcs/scriptcs-samples/blob/master/webapihost/webapiconfig.csx#L1">controller resolver</a>.</li>
</ul>
<p>Now pull in the <a href="https://github.com/scriptcs/scriptcs-webapi">Web Api script pack</a> (scriptcs –install scriptcs.webapi) using the Require&lt;WebApi&gt;() function and your boiler plate code evaporates to this:</p>
<script src="http://gist.github.com/5578077.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5578077" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-cs-L1" rel="file-gistfile1-cs-L1">1</span>
          <span class="line-number" id="file-gistfile1-cs-L2" rel="file-gistfile1-cs-L2">2</span>
          <span class="line-number" id="file-gistfile1-cs-L3" rel="file-gistfile1-cs-L3">3</span>
          <span class="line-number" id="file-gistfile1-cs-L4" rel="file-gistfile1-cs-L4">4</span>
          <span class="line-number" id="file-gistfile1-cs-L5" rel="file-gistfile1-cs-L5">5</span>
          <span class="line-number" id="file-gistfile1-cs-L6" rel="file-gistfile1-cs-L6">6</span>
          <span class="line-number" id="file-gistfile1-cs-L7" rel="file-gistfile1-cs-L7">7</span>
          <span class="line-number" id="file-gistfile1-cs-L8" rel="file-gistfile1-cs-L8">8</span>
          <span class="line-number" id="file-gistfile1-cs-L9" rel="file-gistfile1-cs-L9">9</span>
          <span class="line-number" id="file-gistfile1-cs-L10" rel="file-gistfile1-cs-L10">10</span>
          <span class="line-number" id="file-gistfile1-cs-L11" rel="file-gistfile1-cs-L11">11</span>
          <span class="line-number" id="file-gistfile1-cs-L12" rel="file-gistfile1-cs-L12">12</span>
          <span class="line-number" id="file-gistfile1-cs-L13" rel="file-gistfile1-cs-L13">13</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-cs-LC1"><span class="k">public</span> <span class="k">class</span> <span class="nc">TestController</span> <span class="p">:</span> <span class="n">ApiController</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-cs-LC2">  <span class="k">public</span> <span class="kt">string</span> <span class="nf">Get</span><span class="p">()</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-cs-LC3">    <span class="k">return</span> <span class="s">&quot;Hello world!&quot;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC4">  <span class="p">}</span></div><div class="line" id="file-gistfile1-cs-LC5"><span class="p">}</span></div><div class="line" id="file-gistfile1-cs-LC6">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC7"><span class="kt">var</span> <span class="n">webApi</span> <span class="p">=</span> <span class="n">Require</span><span class="p">&lt;</span><span class="n">WebApi</span><span class="p">&gt;();</span></div><div class="line" id="file-gistfile1-cs-LC8"><span class="kt">var</span> <span class="n">server</span> <span class="p">=</span> <span class="n">webApi</span><span class="p">.</span><span class="n">CreateServer</span><span class="p">(</span><span class="s">&quot;http://localhost:8080&quot;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC9"><span class="n">server</span><span class="p">.</span><span class="n">OpenAsync</span><span class="p">().</span><span class="n">Wait</span><span class="p">();</span></div><div class="line" id="file-gistfile1-cs-LC10">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC11"><span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">&quot;Listening...&quot;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC12"><span class="n">Console</span><span class="p">.</span><span class="n">ReadKey</span><span class="p">();</span></div><div class="line" id="file-gistfile1-cs-LC13"><span class="n">server</span><span class="p">.</span><span class="n">CloseAsync</span><span class="p">().</span><span class="n">Wait</span><span class="p">();</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/glennblock/5578077/raw/5184de1b66121ec7838ca04d443069e8a4ab7cc7/gistfile1.cs" style="float:right">view raw</a>
          <a href="https://gist.github.com/glennblock/5578077#file-gistfile1-cs" style="float:right; margin-right:10px; color:#666;">gistfile1.cs</a>
          <a href="https://gist.github.com/glennblock/5578077">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>The script pack does all of the following to make the experience better:</p>
<ul>
<li>Removes the need for using statements for common namespaces. The script pack provides those which is why you don&#8217;t have to add the web api namespaces in your example above.</li>
<li>Adds dll and nuget package references that bring the dependencies the framework needs.</li>
<li>Removes general boilerplate code. In the previous sample you need to create a host, define routes etc as I mentioned. In this case the script pack creates the host for you and configure with the default routes. You can customize if you need to.</li>
<li>Provide APIs to fill gaps that prevent the framework from working well in script / supporting dynamically emitted assemblies. The Web Api script pack brings in and configures a custom controller resolver for you.</li>
</ul>
<p>We&#8217;re just getting started with the work we&#8217;ve done with script packs, but they are a really nice extensibility point and really take advantage of nuget as a delivery mechanism. The community has been rising to the occasion and building out quite the <a href="https://github.com/scriptcs/scriptcs/wiki/Script-Packs-master-list">gallery</a> as well.</p>
<p>There’s some great posts about script packs covering topics like how to build them or even use them from the <a href="http://codebetter.com/glennblock/2013/05/07/scriptcs-gets-a-repl/">REPL</a> that you should really check out.</p>
<ul>
<li><a title="http://blog.martindoms.com/2013/05/14/building-scriptcs-script-pack/" href="http://blog.martindoms.com/2013/05/14/building-scriptcs-script-pack/">http://blog.martindoms.com/2013/05/14/building-scriptcs-script-pack/</a></li>
<li><a title="http://scottksmith.com/blog/2013/05/14/deeper-dive-into-scriptcs/" href="http://scottksmith.com/blog/2013/05/14/deeper-dive-into-scriptcs/">http://scottksmith.com/blog/2013/05/14/deeper-dive-into-scriptcs/</a></li>
</ul>
<p>Have fun exploring the new world of scripting in C# with scriptcs!</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/DPgX8Cv04nM" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/glennblock/2013/05/14/scripting-ease-with-script-packs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/d372d9c0ab35dbe84c6d0a6902ae0594?s=96&amp;d=&amp;r=G" medium="image">
            <media:title type="html">Glenn Block</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/glennblock/2013/05/14/scripting-ease-with-script-packs/</feedburner:origLink></item>
	<item>
		<title>@model and beyond</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/SvsjXrkkXz8/</link>
		<comments>http://codebetter.com/petervanooijen/2013/05/14/model-and-beyond/#comments</comments>
		<pubDate>Tue, 14 May 2013 09:07:44 +0000</pubDate>
		<dc:creator>Peter van Ooijen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/petervanooijen/?p=711]]></guid>
		<description><![CDATA[In my previous post I had been fiddling with the html helper used in Razor views. Since then our custom html-extensions have been doing great things for our project. To mention some: Standardizing the look and feel. It is far&#160;&#8230; <a href="http://codebetter.com/petervanooijen/2013/05/14/model-and-beyond/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>In my <a href="http://codebetter.com/petervanooijen/2013/02/03/html-and-beyond/">previous post</a> I had been fiddling with the html helper used in Razor views. Since then our custom html-extensions have been doing great things for our project. To mention some:</p>
<ol>
<li>Standardizing the look and feel. It is far more consistent and maintainable to set attributes (including a css class) and event handlers in one centralized place.
<li>Simplify the script. Often a part of the logic the script will follow is already known server side. Instead of writing everything out in javascript rendering the intended statements leads to a leaner client. There is an example in my <a href="http://codebetter.com/petervanooijen/2013/02/03/html-and-beyond/">previous post</a> on building post-data.
<li>Decoupling the libraries used. At the moment we are using the Telerik MVC suite. In my <a href="http://codebetter.com/petervanooijen/2013/02/03/html-and-beyond/">previous post</a> I described how our html helpers build standardized Telerik components for our views. In the not to far future we want to switch to the Telerik Kendo suite. Having wrapped up the library dependency in our Html helper will make this switch a lot easier to implement.</li>
</ol>
<p>What has evolved is the way we work with the model. In MVC the implementation of the controller and the view is clear. When it comes to the implementation of the model there are almost as many different styles of implementation as there are programmers. In general the model can bring any data to the view you can imagine. Not only the source of the data varies, from plain sql to a C# property, also the use of the model’s data varies. It can be a customers name from the database. Or it can be the string representation of some html attribute needed for a fancy picker. Here data and presentation start to get mixed up. Our extensions needed information for the Html-Id. The original Html helper had a custom constructor to get that specific data from the model into the helper. Which required to create our own htmlhelper when starting the view and use that one instead of the standard @html. As seen in the <a href="http://codebetter.com/petervanooijen/2013/02/03/html-and-beyond/">eposHtml in the previous story</a>. It would be cleaner if our extension methods could be satisfied with the default html helper. It would also be cleaner to keep a better separation between ‘real’ data and presentation. </p>
<p>The model is available in every HtmlHelper extension method.</p>
<div style="font-size: 10pt;font-family: courier;background: white;color: black">
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">static</span> PostDataBuilder&lt;TModel&gt; PostData&lt;TModel&gt;(<span style="color: blue">this</span> HtmlHelper&lt;TModel&gt; htmlHelper)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> <span style="color: blue">new</span> PostDataBuilder&lt;TModel&gt;(Id(<strong>htmlHelper.ViewData.Model</strong>));</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">&nbsp;</p>
</div>
<p>It’s a property of the ViewData.</p>
<p>In our case we needed something to give the control an unique Id. The <strong>Id</strong> method builds that Id. Previously we passed the Id-base in the constructor, which lead to the custom helper. A far more elegant solution is using a very basic IOC-DI pattern. As implemented By the Id method</p>
<div style="font-size: 10pt;font-family: courier;background: white;color: black">
<p style="margin: 0px"><span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">string</span> Id(<span style="color: blue">object</span> model)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> complex = model <span style="color: blue">as</span> IProvideCompositeId;</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (complex != <span style="color: blue">null</span>)</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> complex.CompositeId;</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> simple = model <span style="color: blue">as</span> IProvideId;</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> simple == <span style="color: blue">null</span> ? <span style="color: #a31515">&#8220;&#8221;</span> :&nbsp; simple.Id &lt; 0&nbsp; ? <span style="color: #2b91af">String</span>.Format(<span style="color: #a31515">&#8220;N{0}&#8221;</span>, <span style="color: #2b91af">Math</span>.Abs(simple.Id)) : simple.Id.ToString();</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">&nbsp;</p>
</div>
<p>The method queries the model first for the IProvideCompositeId interface, in case the model does not implement that it is queried for the IprovideId interface. Resulting in a string which can be safely used in an HtmlId. (A negative number would lead to a ‘–’ in the string, which is not accepted in an Html Id).</p>
<p>These interfaces are very straightforward</p>
<div style="font-size: 10pt;font-family: courier;background: white;color: black">
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">interface</span> <span style="color: #2b91af">IProvideCompositeId</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">string</span> CompositeId { <span style="color: blue">get</span>; }</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">&nbsp;</p>
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">interface</span> <span style="color: #2b91af">IProvideId</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">int</span> Id { <span style="color: blue">get</span>; }</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">&nbsp;</p>
</div>
<p>In case the model is going to be used in a view requiring unique Id’s the model has to implement one of these interfaces.</p>
<div style="font-size: 10pt;font-family: courier;background: white;color: black">
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">FactuurDefinitie</span> : IProvideCompositeId</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">readonly</span> <span style="color: blue">int</span> IdTraject;</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">readonly</span> <span style="color: blue">int</span> UZOVI;</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">readonly</span> <span style="color: blue">bool</span> Verzekerd;</p>
<p style="margin: 0px">&nbsp;</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> FactuurDefinitie(<span style="color: blue">int</span> idTraject, <span style="color: blue">int</span> uzovi, <span style="color: blue">bool</span> verzekerd)</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">// The usual stuff</span></p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px">&nbsp;</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; <strong><span style="color: blue">public</span> <span style="color: blue">string</span> CompositeId</strong></p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">get</span> { <span style="color: blue">return</span> <span style="color: #2b91af">String</span>.Format(<span style="color: #a31515">&#8220;{0}{1}{2}&#8221;</span>, IdTraject, UZOVI, Verzekerd); }</p>
<p style="margin: 0px">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">&nbsp;</p>
</div>
<p>Working this way:</p>
<ul>
<li>We can use our custom html extensions in the default html helper</li>
<li>Specific data from the model is available inside our extensions</li>
<li>The model and the view do not get entangled</li>
</ul>
<p>The code is no big deal. I know. But the model is something whose horizons are still not in sight.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/SvsjXrkkXz8" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/petervanooijen/2013/05/14/model-and-beyond/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/5cb0e972c5e405e6bff7e7f2da237c6d?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Peter van Ooijen</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/petervanooijen/2013/05/14/model-and-beyond/</feedburner:origLink></item>
	<item>
		<title>Don’t assign a field from many methods</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/BOXC6YmI2J4/</link>
		<comments>http://codebetter.com/patricksmacchia/2013/05/13/dont-assign-a-field-from-many-methods/#comments</comments>
		<pubDate>Mon, 13 May 2013 15:53:39 +0000</pubDate>
		<dc:creator>Patrick Smacchia</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[high cohesion]]></category>
		<category><![CDATA[Immutability]]></category>
		<category><![CDATA[Maintainability]]></category>
		<category><![CDATA[measurement]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/patricksmacchia/?p=792]]></guid>
		<description><![CDATA[For the next NDepend version, amongst plenty of cool stuff, a new default code rule will be added. It has been named Don&#8217;t assign a field from many methods. It falls into the category of Purity &#8211; Immutability &#8211; Side-Effects rules, one of my preferred set&#160;&#8230; <a href="http://codebetter.com/patricksmacchia/2013/05/13/dont-assign-a-field-from-many-methods/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>For the next NDepend version, amongst plenty of cool stuff, a new default code rule will be added. It has been named <strong>Don&#8217;t assign a field from many methods</strong>. It falls into the category of <strong>Purity &#8211; Immutability &#8211; Side-Effects</strong> rules, one of my preferred set of rules since often hard-to-find and to-fix bugs come from wrong state managements.</p>
<p><a href="http://codebetter.com/patricksmacchia/files/2013/05/Screenshot2.png"><img class="alignnone size-full wp-image-793" title="Purity - Immutability - Side-Effects code rules" alt="Screenshot2" src="http://codebetter.com/patricksmacchia/files/2013/05/Screenshot2.png" width="600" height="292" /></a></p>
<p>As its name suggests this rule matches fields assigned from multiple methods. Bugs due to corrupted state are often the consequence of fields anarchically assigned.</p>
<p>On many code bases tested, I found the threshold of 4 methods writer to be the best balanced number between too many false positives, and a decent amount of suspicious matches to look after at code-reviewing time. Of course this threshold is easily customizable.</p>
<p>Several parameters can be taken account.</p>
<ul>
<li>Is the field static? in which case it can be pretty serious if many methods assign it.</li>
<li>Does the field type is a value or a reference type? In the case of a reference type, such situation might reveal a potential <em>NullReferenceException</em> scenario luring.</li>
<li>Is the field assigned outside from its class. Since another rule prevents fields to be visible from outside its class, this case has been eliminated.</li>
<li>How many assigner methods of the parent class are visible outside the class? How many  methods calling directly or indirectly an assigner method are visible outside the class?</li>
<li>Can a particular class instance be accessed from multiple threads? in which case the situation sounds pretty alarming.</li>
</ul>
<p>Not all cases are taken account since static analysis have limits and for code review warning purposes the rule algorithm must be kept easily understandable. Here is the rule code and comments that contain insight about how to generally fix such issue.</p>
<p>I&#8217;d be curious to read your suggestions and comments on that.</p>
<script src="http://gist.github.com/5569350.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5569350" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L1" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L1">1</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L2" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L2">2</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L3" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L3">3</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L4" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L4">4</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L5" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L5">5</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L6" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L6">6</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L7" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L7">7</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L8" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L8">8</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L9" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L9">9</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L10" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L10">10</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L11" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L11">11</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L12" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L12">12</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L13" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L13">13</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L14" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L14">14</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L15" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L15">15</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L16" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L16">16</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L17" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L17">17</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L18" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L18">18</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L19" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L19">19</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L20" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L20">20</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L21" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L21">21</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L22" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L22">22</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L23" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L23">23</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L24" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L24">24</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L25" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L25">25</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L26" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L26">26</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L27" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L27">27</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L28" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L28">28</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L29" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L29">29</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L30" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L30">30</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L31" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L31">31</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L32" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L32">32</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L33" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L33">33</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L34" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L34">34</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L35" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L35">35</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L36" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L36">36</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L37" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L37">37</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L38" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L38">38</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L39" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L39">39</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L40" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L40">40</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L41" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L41">41</span>
          <span class="line-number" id="file-cqlinq-don-t-assign-a-field-from-many-methods-L42" rel="file-cqlinq-don-t-assign-a-field-from-many-methods-L42">42</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC1">// &lt;Name&gt;Don&#39;t assign a field from many methods&lt;/Name&gt;</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC2">warnif count &gt; 0 </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC3">from f in JustMyCode.Fields where </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC4">  !f.IsEnumValue &amp;&amp;</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC5">  !f.IsImmutable &amp;&amp; </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC6">  !f.IsInitOnly &amp;&amp;</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC7">  !f.IsGeneratedByCompiler &amp;&amp;</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC8">  !f.IsEventDelegateObject &amp;&amp;</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC9">   (f.IsPrivate || f.IsProtected)  // Don&#39;t match fields assigned outside their classes.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC10">&nbsp;</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC11">// The threshold 4 is arbitrary and it should avoid matching too many fields.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC12">// Threshold is even lower for static fields because this reveals situations even more complex.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC13">where f.MethodsAssigningMe.Count() &gt;= (!f.IsStatic ? 4 : 2)</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC14">select new { f, </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC15">             f.MethodsAssigningMe, </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC16">             f.MethodsReadingMeButNotAssigningMe, </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC17">             f.MethodsUsingMe,</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC18">             f.ParentType } </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC19">&nbsp;</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC20">// A field assigned from many methods is a symptom of bug-prone code.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC21">// This situation makes harder to anticipate the field state during runtime.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC22">// The code is then hard to read, hard to debug and hard to maintain.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC23">// Hard-to-solve bugs due to corrupted state are often the consequence of fields anarchically assigned.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC24">//</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC25">// The situation is even more complex if the field is static.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC26">// Indeed, this potentially involves global random accesses from different parts of the application.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC27">// This is why this rule provides a lower threshold for static fields.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC28">// </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC29">// If the object containing such field is meant to be used from multiple threads, </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC30">// there are alarming chances that the code is unmaintainable and bugged.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC31">// When multiple threads are involved, the rule of thumb is to use immutable objects.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC32">//</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC33">// If the field type is a reference type (interfaces, classes, strings, delegates) </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC34">// corrupted state might result in a NullReferenceException.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC35">// If the field type is a value type (number, boolean, structure) </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC36">// corrupted state might result in wrong result not even signaled by an exception sent.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC37">//</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC38">// There is no straight advice to refactor the number of methods responsible for assigning a field.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC39">// Solutions often involve rethinking and then rewriting a complex algorithm.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC40">// Such field can sometime become just a variable accessed locally by a method or a closure.</div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC41">// Sometime, just rethinking the life-time and the role of the parent object allows the field to become immutable </div><div class="line" id="file-cqlinq-don-t-assign-a-field-from-many-methods-LC42">// (i.e assigned only by the constructor).</div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/anonymous/5569350/raw/93594f85f15058434f2e75c50da25ec8450f73c1/CQLinq%3A+Don%27t+assign+a+field+from+many+methods" style="float:right">view raw</a>
          <a href="https://gist.github.com/anonymous/5569350#file-cqlinq-don-t-assign-a-field-from-many-methods" style="float:right; margin-right:10px; color:#666;">CQLinq: Don&#39;t assign a field from many methods</a>
          <a href="https://gist.github.com/anonymous/5569350">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>And here is what it looks like when we run the rules on the NUnit code base:</p>
<p><a href="http://codebetter.com/patricksmacchia/files/2013/05/Screenshot1.png"><img class="alignnone size-full wp-image-794" alt="NDepend CQLinq Rules" src="http://codebetter.com/patricksmacchia/files/2013/05/Screenshot1.png" width="576" height="829" /></a></p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/BOXC6YmI2J4" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/patricksmacchia/2013/05/13/dont-assign-a-field-from-many-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/aff180ba8312104219eb0c2529aa131e?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Patrick Smacchia</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/patricksmacchia/2013/05/13/dont-assign-a-field-from-many-methods/</feedburner:origLink></item>
	<item>
		<title>scriptcs gets a REPL!</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/ZWUD8pHnF4g/</link>
		<comments>http://codebetter.com/glennblock/2013/05/07/scriptcs-gets-a-repl/#comments</comments>
		<pubDate>Tue, 07 May 2013 18:15:04 +0000</pubDate>
		<dc:creator>Glenn Block</dc:creator>
				<category><![CDATA[scriptcs]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/glennblock/?p=732]]></guid>
		<description><![CDATA[Hello c# scripters! Before you go further, if you are wondering what all the scriptcs hype is about please check out Scott Hanselman’s great post and his new Tekpub video. Last few days I&#8217;ve been working on a new REPL&#160;&#8230; <a href="http://codebetter.com/glennblock/2013/05/07/scriptcs-gets-a-repl/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Hello c# scripters!</p>
<p><span style="text-decoration: underline">Before you go further</span>, if you are wondering what all the scriptcs hype is about please check out Scott Hanselman’s great <a href="http://www.hanselman.com/blog/ProjectlessScriptedCWithScriptCSAndRoslyn.aspx">post</a> and his new Tekpub <a href="http://tekpub.com/shows/the_source/6">video</a>.</p>
<p>Last few days I&#8217;ve been working on a new <a href="http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop">REPL</a> experience for scriptcs and now it&#8217;s in! REPLs are nothing new to dynamic languages but they have not really been available in C# with one exception, Mono has a great REPL. Roslyn introduces the Roslyn interactive window in VS which is also a REPL which runs in the editor.</p>
<p>This REPL is different than both in that it is specific for scriptcs, and like the rest of the scriptcs experience, there&#8217; s no IDE required. Basically it combines the goodness of scriptcs (nuget) with an interactive experience. You can just install some nuget packages and type code which instantly executes. For example imagine just pulling in HttpClient and then just doing some http requests!</p>
<p>Below you can see I am installing the mongo nuget package. Then running scriptcs by itself and typing in some simple code to work with the package.</p>
<p><a href="http://codebetter.com/glennblock/files/2013/05/clip_image001.jpg"><img style="border: 0px" title="clip_image001" alt="clip_image001" src="http://codebetter.com/glennblock/files/2013/05/clip_image001_thumb.jpg" width="534" height="570" border="0" /></a></p>
<p>And then we have pretty error handling.</p>
<p><a href="http://codebetter.com/glennblock/files/2013/05/clip_image002.jpg"><img style="border: 0px" title="clip_image002" alt="clip_image002" src="http://codebetter.com/glennblock/files/2013/05/clip_image002_thumb.jpg" width="554" height="285" border="0" /></a></p>
<p>Thanks to the Roslyn team&#8217;s efforts layering a REPL on top was AMAZINGLY easy. The REPL part itself was like 15 lines of code! And thanks to the nuget team for even making this a remote possibility through having an awesome package ecosystem. I look forward to ALSO seeing the mono version soon <img src='http://codebetter.com/glennblock/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>If you wanna try it, you can grab the latest from github at <a href="http://github.com/scriptcs/scriptcs">http://github.com/scriptcs/scriptcs</a> in the dev branch.</p>
<p>It will also be on our chocolately nightly builds tomorrow: <a href="http://www.myget.org/F/scriptcsnightly">http://www.myget.org/F/scriptcsnightly</a>. It should be on our public feed very soon there after.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/ZWUD8pHnF4g" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/glennblock/2013/05/07/scriptcs-gets-a-repl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/d372d9c0ab35dbe84c6d0a6902ae0594?s=96&amp;d=&amp;r=G" medium="image">
            <media:title type="html">Glenn Block</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/glennblock/2013/05/07/scriptcs-gets-a-repl/</feedburner:origLink></item>
	<item>
		<title>Relaunching SerialSeb – Practical ReST and then some</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/qkIUmK_J4Ow/</link>
		<comments>http://codebetter.com/sebastienlambla/2013/04/14/relaunching-serialseb-practical-rest-and-then-some/#comments</comments>
		<pubDate>Sun, 14 Apr 2013 06:30:25 +0000</pubDate>
		<dc:creator>Sebastien Lambla</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/sebastienlambla/?p=160]]></guid>
		<description><![CDATA[Well. After 5 months of soul-searching, ups and downs, I&#8217;m back, more focused than ever (think laser beam focus). This week has seen the launch of several important projects for me, and I&#8217;m very excited to share them with you,&#160;&#8230; <a href="http://codebetter.com/sebastienlambla/2013/04/14/relaunching-serialseb-practical-rest-and-then-some/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Well. After 5 months of soul-searching, ups and downs, I&#8217;m back, more focused than ever (think laser beam focus). This week has seen the launch of several important projects for me, and I&#8217;m very excited to share them with you, a year after my last blog post! The hiatus is over and Seb is back.</p>
<h1>Practical ReST &#8211; the book</h1>
<p>I&#8217;ve been talking for years about writing a brain dump of what I know of ReST. The project has started, you can pledge to <a href="http://kickstarter.com/projects/serialseb/practical-rest-building-hypermedia-systems">buy your copy today</a> (in various editions) and get content as early as next month!</p>
<p>The response has been amazing, with three quarters of the minimum funding pledged in 48 hours. Of course, the more contributors the more time I can allocate to the book, the quicker the book will be in your hands, so don&#8217;t hesitate!</p>
<p>Writing a book in itself is a big challenge, and the scope is very ambitious. But it&#8217;s also a foray into self-publishing, and I expect it to be an amazing opportunity for learning.</p>
<h1>Practical ReST &#8211; the class</h1>
<p>I&#8217;ve been giving a ReST class for a while, but I&#8217;m rewriting it so it follows the same structure as the book, and make it open to people with many technological backgrounds.</p>
<p>First date should be in <a href="http://serialseb.com/rest/2013/04/09/London-class-May-2013.html">May in London</a>, and I expect <a href="http://serialseb.com/rest/2013/04/12/Warsaw-class-planned.html">Warsaw</a>, Vilnius and other locations to pop up this year.</p>
<p>If you want to see a workshop organised in your city (or your company), pop me an email.</p>
<p>I&#8217;m also launching a referral program *and* group rebates, so if you&#8217;re a training company and you want to add the course to your books, you can too.</p>
<h1>Hanselminutes podcast</h1>
<p>Scott was nice enough to have me on his show this week, talking about Practical ReST. It&#8217;s <a href="http://www.hanselminutes.com/366/practical-rest-with-sebastien-lambla">published and ready to be listened to</a>, and while I was half-way through an asthma attack and having microphone problems, Scott saves the day by being a great host.</p>
<h1><a href="http://www.cancerresearchuk.org/home/">Cancer Research UK</a></h1>
<p>You may remember that I asked for your contributions to help me raise money for cancer research UK. I can now announced that we raised more than 700£, and that both my objectives of non-drinking were achieved. I cannot thank you all enough for your generosity.</p>
<h1><a href="http://serialseb.com">serialseb.com</a></h1>
<p>It had to happen. I now have my own web site. You cannot imagine how difficult it is for me to put work and effort in talking about what I did rather than what I want to do. But you will find on there a link to <a href="http://serialseb.com/speaker/">all my previous talks</a>, with videos and slides (where applicable), as well as where you&#8217;ll find me next, my future talks and where classes will be delivered next.</p>
<h1>What next?</h1>
<p>ReST will be my focus for the next few months. I have a couple of other projects up my sleeve, but this is enough announcements for now, don&#8217;t you think?</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/qkIUmK_J4Ow" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/sebastienlambla/2013/04/14/relaunching-serialseb-practical-rest-and-then-some/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/94060965b2b860ddb44fc13da0cae4c7?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Sebastien Lambla</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/sebastienlambla/2013/04/14/relaunching-serialseb-practical-rest-and-then-some/</feedburner:origLink></item>
	<item>
		<title>Debugging node.js errors in Windows Azure</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/383TA9m377E/</link>
		<comments>http://codebetter.com/glennblock/2013/04/01/debugging-node-js-errors-in-windows-azure/#comments</comments>
		<pubDate>Mon, 01 Apr 2013 03:44:34 +0000</pubDate>
		<dc:creator>Glenn Block</dc:creator>
				<category><![CDATA[azure]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[node.js]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/glennblock/?p=721]]></guid>
		<description><![CDATA[A common problem you might encounter in Windows Azure is seeing a big old “The page cannot be displayed” page due to an error occurring in your azure-deployed node app. If you haven’t seen it, it looks exactly like this:&#160;&#8230; <a href="http://codebetter.com/glennblock/2013/04/01/debugging-node-js-errors-in-windows-azure/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>A common problem you might encounter in Windows Azure is seeing a big old “The page cannot be displayed” page due to an error occurring in your azure-deployed node app.</p>
<p>If you haven’t seen it, it looks exactly like this:</p>
<p><a href="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.21.37PM.png"><img style="border-width: 0px" title="Screen Shot 2013-03-31 at 8.21.37 PM" alt="Screen Shot 2013-03-31 at 8.21.37 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.21.37PM_thumb.png" width="457" height="247" border="0" /></a></p>
<p>The reason this is happening is because by default we don’t allow errors to propagate back to the user. This is in order to prevent you publishing to production and leaking details of your system.</p>
<p>Let’s assume I just published a simple express app, but I made an error. Below you can see that instead of requiring winston, I required win$ton.</p>
<p><a href="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.29.21PM.png"><img style="border-width: 0px" title="Screen Shot 2013-03-31 at 8.29.21 PM" alt="Screen Shot 2013-03-31 at 8.29.21 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.29.21PM_thumb.png" width="455" height="331" border="0" /></a></p>
<p>When I publish, I’ll see the page cannot be displayed error.</p>
<h2>iisnode.yml to the rescue</h2>
<p>To find out what is going on, you can enable displaying errors using our YAML configuration file otherwise known as iisnode.yml. If you use our azure-cli tool, and create a site in a directory where there is a node app, then we automatically create it for you. If not, you can create one really easy with any text editor. The entries you need to put in the file / update are below.</p>
<script src="http://gist.github.com/5283112.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5283112" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-iisnode-yml-L1" rel="file-iisnode-yml-L1">1</span>
          <span class="line-number" id="file-iisnode-yml-L2" rel="file-iisnode-yml-L2">2</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-iisnode-yml-LC1"><span class="l-Scalar-Plain">loggingEnabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span></div><div class="line" id="file-iisnode-yml-LC2"><span class="l-Scalar-Plain">devErrorsEnabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/glennblock/5283112/raw/1b7938b40c9d679718da274c25a3f240b4ea78ed/iisnode.yml" style="float:right">view raw</a>
          <a href="https://gist.github.com/glennblock/5283112#file-iisnode-yml" style="float:right; margin-right:10px; color:#666;">iisnode.yml</a>
          <a href="https://gist.github.com/glennblock/5283112">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>Once you save that file, go republish to Windows Azure. If the file did not exist and this is an Azure Website, do an “azure site restart”. if the file already existed, you won’t need to do anything.</p>
<p>Now with debugger errors enabled I see the following:</p>
<p><a href="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.34.14PM.png"><img style="border-width: 0px" title="Screen Shot 2013-03-31 at 8.34.14 PM" alt="Screen Shot 2013-03-31 at 8.34.14 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.34.14PM_thumb.png" width="468" height="253" border="0" /></a></p>
<p><strong>Bingo!</strong></p>
<h2></h2>
<h2>Don’t go to production this way, but DO use tail for websites.</h2>
<p>Make sure to disable debugger errors when you go to production. You can leave logging enabled however, because another command you can still use is “azure site log tail” which will stream logs directly to your console realtime. Also if you are a cloud service, you can remote in to view the logs written locally.</p>
<p>Using “azure site log tail” watch what happens when I refresh the page.</p>
<p><a href="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.37.58PM.png"><img style="border-width: 0px" title="Screen Shot 2013-03-31 at 8.37.58 PM" alt="Screen Shot 2013-03-31 at 8.37.58 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.37.58PM_thumb.png" width="484" height="230" border="0" /></a></p>
<p>azure-log tail has many more uses. You can use it to capture any log output that your applications give you in a realtime manner. For example here’s a screenshot of me tailing an app using socket.io and Service Bus in Azure.</p>
<p><a href="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.40.42PM.png"><img style="border-width: 0px" title="Screen Shot 2013-03-31 at 8.40.42 PM" alt="Screen Shot 2013-03-31 at 8.40.42 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.40.42PM_thumb.png" width="488" height="256" border="0" /></a></p>
<p>Yes it is awesome!</p>
<p>PS: Today “tail” works only for node apps, but that is going to change VERY shortly.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/383TA9m377E" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/glennblock/2013/04/01/debugging-node-js-errors-in-windows-azure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/d372d9c0ab35dbe84c6d0a6902ae0594?s=96&amp;d=&amp;r=G" medium="image">
            <media:title type="html">Glenn Block</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/glennblock/2013/04/01/debugging-node-js-errors-in-windows-azure/</feedburner:origLink></item>
	<item>
		<title>azure-scripty – Azure CLI scripting made even easier</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/DKan_BACt3U/</link>
		<comments>http://codebetter.com/glennblock/2013/04/01/azure-scripty-azure-cli-scripting-made-even-easier/#comments</comments>
		<pubDate>Mon, 01 Apr 2013 01:06:13 +0000</pubDate>
		<dc:creator>Glenn Block</dc:creator>
				<category><![CDATA[azure]]></category>
		<category><![CDATA[node.js]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/glennblock/?p=699]]></guid>
		<description><![CDATA[Note: At any time if you want to just get it and jump in, “npm install azure-scripty” and start scripting If you are using our azure-cli then you might have though of creating automation scripts to package up common tasks.&#160;&#8230; <a href="http://codebetter.com/glennblock/2013/04/01/azure-scripty-azure-cli-scripting-made-even-easier/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p><strong>Note: At any time if you want to just get it and jump in, “npm install azure-scripty” and start scripting</strong></p>
<p>If you are using our azure-cli then you might have though of creating automation scripts to package up common tasks. A while ago I posted on how you can <a href="http://codebetter.com/glennblock/2012/12/25/simple-bash-scripting-for-azure-cli/">achieve</a> some script-ability just using bash tools. Basically the techniques I listed there involve piping text from command to command and using tools like grep and awk to parse the results in order to feed to the next command.</p>
<p>It turns out there’s another way, and one that is much closer to the kind of fidelity you an achieve with Powershell. Sound interesting? keep reading. It turns out the majority (like 99%) of our cmds can return JSON objects if you apply the –json switch.</p>
<p>For example if I do “azure site list –json” here’s what I get.</p>
<p><a href="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at5.35.57PM.png"><img title="Screen Shot 2013-03-31 at 5.35.57 PM" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px" border="0" alt="Screen Shot 2013-03-31 at 5.35.57 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at5.35.57PM_thumb.png" width="420" height="283"></a></p>
<p>That means that I can take that result and parse it into a JSON object which I can then easily manipulate. Potentially I could even pipe results in from one cmd to the other. I could even imagine being able to define cmds as JSON objects so that I could script out my tasks in a more object friendly fashion. I could then wrap that all up in a nice pretty box to be used by myself or others.</p>
<p><a href="http://codebetter.com/glennblock/files/2013/04/MP9004028941.jpg"><img title="MP900402894[1]" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px" border="0" alt="MP900402894[1]" src="http://codebetter.com/glennblock/files/2013/04/MP9004028941_thumb.jpg" width="240" height="180"></a></p>
<p>And <i>that</i> is what <a href="https://github.com/glennblock/azure-scripty">azure-scripty</a> is about. (Kudos to <a href="http://twitter.com/jpscripter">@JpScripter </a>for reminding me I need to post.)</p>
<p>azure-scripty gives you a JSON oriented API that you can use within a node script for automation tasks. It lets you combine the power of raw node with the capabilities of our azure-cli. One thing that is also really nice is it leverages the knowledge you already have of the CLI. As it says on the github page, “if you know the CLI you know scripty.”</p>
<p>azure-scripty offers you the following:</p>
<ul>
<li>Works anywhere node works i.e. Windows, Linux, Mac, Nodecopter <img src='http://codebetter.com/glennblock/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />
<li>Author using pure string command or JSON object command styles.
<li>Uses the standard node callback model
<li>Batching multiple commands together.
<li>Piping results from one command to the other </li>
</ul>
<p>Here’s a few examples to give you an idea:</p>
<h2>String command style</h2>
<script src="http://gist.github.com/5282664.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5282664" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-js-L1" rel="file-gistfile1-js-L1">1</span>
          <span class="line-number" id="file-gistfile1-js-L2" rel="file-gistfile1-js-L2">2</span>
          <span class="line-number" id="file-gistfile1-js-L3" rel="file-gistfile1-js-L3">3</span>
          <span class="line-number" id="file-gistfile1-js-L4" rel="file-gistfile1-js-L4">4</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-js-LC1"><span class="kd">var</span> <span class="nx">scripty</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;azure-scripty&#39;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-js-LC2"><span class="nx">scripty</span><span class="p">.</span><span class="nx">invoke</span><span class="p">(</span><span class="s1">&#39;site list&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">results</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-js-LC3">  <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;my sites\n&quot;</span> <span class="o">+</span> <span class="nx">results</span><span class="p">);</span></div><div class="line" id="file-gistfile1-js-LC4"><span class="p">});</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/glennblock/5282664/raw/da17bd9cad47373ab2f278e485fa3d827091085c/gistfile1.js" style="float:right">view raw</a>
          <a href="https://gist.github.com/glennblock/5282664#file-gistfile1-js" style="float:right; margin-right:10px; color:#666;">gistfile1.js</a>
          <a href="https://gist.github.com/glennblock/5282664">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>This will list out my websites in json format.</p>
<h2>Object command style</h2>
<script src="http://gist.github.com/5282673.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5282673" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-js-L1" rel="file-gistfile1-js-L1">1</span>
          <span class="line-number" id="file-gistfile1-js-L2" rel="file-gistfile1-js-L2">2</span>
          <span class="line-number" id="file-gistfile1-js-L3" rel="file-gistfile1-js-L3">3</span>
          <span class="line-number" id="file-gistfile1-js-L4" rel="file-gistfile1-js-L4">4</span>
          <span class="line-number" id="file-gistfile1-js-L5" rel="file-gistfile1-js-L5">5</span>
          <span class="line-number" id="file-gistfile1-js-L6" rel="file-gistfile1-js-L6">6</span>
          <span class="line-number" id="file-gistfile1-js-L7" rel="file-gistfile1-js-L7">7</span>
          <span class="line-number" id="file-gistfile1-js-L8" rel="file-gistfile1-js-L8">8</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-js-LC1"><span class="kd">var</span> <span class="nx">scripty</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;azure-scripty&#39;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-js-LC2"><span class="nx">cmd</span> <span class="o">=</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-js-LC3">  <span class="nx">command</span><span class="o">:</span> <span class="s1">&#39;mobile create&#39;</span><span class="p">,</span></div><div class="line" id="file-gistfile1-js-LC4">  <span class="nx">positional</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;mymobileservice&#39;</span><span class="p">,</span> <span class="s1">&#39;sqladmin&#39;</span><span class="p">,</span> <span class="s1">&#39;myP@ssw0rd!&#39;</span><span class="p">],</span></div><div class="line" id="file-gistfile1-js-LC5">  <span class="nx">sqlServer</span><span class="o">:</span> <span class="s1">&#39;VMF1ASD&#39;</span><span class="p">,</span></div><div class="line" id="file-gistfile1-js-LC6">  <span class="nx">sqlDb</span><span class="o">:</span> <span class="s1">&#39;mydb&#39;</span></div><div class="line" id="file-gistfile1-js-LC7"><span class="p">};</span></div><div class="line" id="file-gistfile1-js-LC8"><span class="nx">scripty</span><span class="p">.</span><span class="nx">invoke</span><span class="p">(</span><span class="nx">cmd</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{});</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/glennblock/5282673/raw/e6ec5be72beb6c6b3703a04545643e8424b2cdab/gistfile1.js" style="float:right">view raw</a>
          <a href="https://gist.github.com/glennblock/5282673#file-gistfile1-js" style="float:right; margin-right:10px; color:#666;">gistfile1.js</a>
          <a href="https://gist.github.com/glennblock/5282673">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>This sample creates a new mobile service using the object oriented style. Notice you can pass fixed position args, with all other named args being by convention.</p>
<h2></h2>
<h2></h2>
<h2>Batching</h2>
<script src="http://gist.github.com/5282679.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5282679" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-js-L1" rel="file-gistfile1-js-L1">1</span>
          <span class="line-number" id="file-gistfile1-js-L2" rel="file-gistfile1-js-L2">2</span>
          <span class="line-number" id="file-gistfile1-js-L3" rel="file-gistfile1-js-L3">3</span>
          <span class="line-number" id="file-gistfile1-js-L4" rel="file-gistfile1-js-L4">4</span>
          <span class="line-number" id="file-gistfile1-js-L5" rel="file-gistfile1-js-L5">5</span>
          <span class="line-number" id="file-gistfile1-js-L6" rel="file-gistfile1-js-L6">6</span>
          <span class="line-number" id="file-gistfile1-js-L7" rel="file-gistfile1-js-L7">7</span>
          <span class="line-number" id="file-gistfile1-js-L8" rel="file-gistfile1-js-L8">8</span>
          <span class="line-number" id="file-gistfile1-js-L9" rel="file-gistfile1-js-L9">9</span>
          <span class="line-number" id="file-gistfile1-js-L10" rel="file-gistfile1-js-L10">10</span>
          <span class="line-number" id="file-gistfile1-js-L11" rel="file-gistfile1-js-L11">11</span>
          <span class="line-number" id="file-gistfile1-js-L12" rel="file-gistfile1-js-L12">12</span>
          <span class="line-number" id="file-gistfile1-js-L13" rel="file-gistfile1-js-L13">13</span>
          <span class="line-number" id="file-gistfile1-js-L14" rel="file-gistfile1-js-L14">14</span>
          <span class="line-number" id="file-gistfile1-js-L15" rel="file-gistfile1-js-L15">15</span>
          <span class="line-number" id="file-gistfile1-js-L16" rel="file-gistfile1-js-L16">16</span>
          <span class="line-number" id="file-gistfile1-js-L17" rel="file-gistfile1-js-L17">17</span>
          <span class="line-number" id="file-gistfile1-js-L18" rel="file-gistfile1-js-L18">18</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-js-LC1"><span class="kd">var</span> <span class="nx">scripty</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;azure-scripty&#39;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-js-LC2"><span class="nx">cmds</span> <span class="o">=</span> <span class="p">[</span></div><div class="line" id="file-gistfile1-js-LC3">  <span class="p">{</span></div><div class="line" id="file-gistfile1-js-LC4">    <span class="nx">command</span><span class="o">:</span> <span class="s1">&#39;mobile create&#39;</span><span class="p">,</span></div><div class="line" id="file-gistfile1-js-LC5">    <span class="nx">positional</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;mymobileservice&#39;</span><span class="p">,</span> <span class="s1">&#39;sqladmin&#39;</span><span class="p">,</span> <span class="s1">&#39;myP@ssw0rd!&#39;</span><span class="p">],</span></div><div class="line" id="file-gistfile1-js-LC6">    <span class="nx">sqlServer</span><span class="o">:</span> <span class="s1">&#39;VMF1ASD&#39;</span><span class="p">,</span></div><div class="line" id="file-gistfile1-js-LC7">    <span class="nx">sqlDb</span><span class="o">:</span> <span class="s1">&#39;mydb&#39;</span></div><div class="line" id="file-gistfile1-js-LC8">  <span class="p">},</span></div><div class="line" id="file-gistfile1-js-LC9">  <span class="p">{</span></div><div class="line" id="file-gistfile1-js-LC10">    <span class="nx">command</span><span class="o">:</span> <span class="s1">&#39;site create&#39;</span><span class="p">,</span></div><div class="line" id="file-gistfile1-js-LC11">    <span class="nx">positional</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;site1&#39;</span><span class="p">],</span></div><div class="line" id="file-gistfile1-js-LC12">    <span class="nx">location</span><span class="o">:</span> <span class="s1">&#39;&quot;West US&quot;&#39;</span><span class="p">,</span></div><div class="line" id="file-gistfile1-js-LC13">    <span class="nx">subscription</span><span class="o">:</span> <span class="s1">&#39;foobar&#39;</span></div><div class="line" id="file-gistfile1-js-LC14">    <span class="nx">git</span><span class="o">:</span><span class="kc">true</span></div><div class="line" id="file-gistfile1-js-LC15">  <span class="p">}</span></div><div class="line" id="file-gistfile1-js-LC16"><span class="p">]</span></div><div class="line" id="file-gistfile1-js-LC17">&nbsp;</div><div class="line" id="file-gistfile1-js-LC18"><span class="nx">scripty</span><span class="p">.</span><span class="nx">invoke</span><span class="p">(</span><span class="nx">cmds</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{});</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/glennblock/5282679/raw/2bfd139d146f912fb7f97b278db8e3e39408efc3/gistfile1.js" style="float:right">view raw</a>
          <a href="https://gist.github.com/glennblock/5282679#file-gistfile1-js" style="float:right; margin-right:10px; color:#666;">gistfile1.js</a>
          <a href="https://gist.github.com/glennblock/5282679">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>This sample shows creating a web site and a mobile service using the object oriented style.</p>
<h2>Piping</h2>
<script src="http://gist.github.com/5282689.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5282689" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-js-L1" rel="file-gistfile1-js-L1">1</span>
          <span class="line-number" id="file-gistfile1-js-L2" rel="file-gistfile1-js-L2">2</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-js-LC1"><span class="kd">var</span> <span class="nx">scripty</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;azure-scripty&#39;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-js-LC2"><span class="nx">scripty</span><span class="p">.</span><span class="nx">invoke</span><span class="p">([</span><span class="s1">&#39;site list&#39;</span><span class="p">,</span> <span class="s1">&#39;site stop :Name&#39;</span><span class="p">],</span> <span class="kd">function</span><span class="p">(){});</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/glennblock/5282689/raw/80a8e0395659a74ce4659b82938e09afc3267c77/gistfile1.js" style="float:right">view raw</a>
          <a href="https://gist.github.com/glennblock/5282689#file-gistfile1-js" style="float:right; margin-right:10px; color:#666;">gistfile1.js</a>
          <a href="https://gist.github.com/glennblock/5282689">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>One of my favorites. This example shows using piping to pipe the list of sites into the stop command. Notice that :Name, that’s plugging in the Name parameter from the returned site.</p>
<h2></h2>
<h2>Get it and please give feedback</h2>
<h2></h2>
<ol>
<li>npm install azure-scripty
<li>go check the <a href="https://github.com/glennblock/azure-scripty/blob/master/README.md">README</a>.
<li>Start scripting! </li>
</ol>
<p>Looking forward to your feedback and your contributions!</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/DKan_BACt3U" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/glennblock/2013/04/01/azure-scripty-azure-cli-scripting-made-even-easier/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/d372d9c0ab35dbe84c6d0a6902ae0594?s=96&amp;d=&amp;r=G" medium="image">
            <media:title type="html">Glenn Block</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/glennblock/2013/04/01/azure-scripty-azure-cli-scripting-made-even-easier/</feedburner:origLink></item>
	<item>
		<title>DongleGate: A Legal Perspective and some social commentary</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/lMFZbIXzErE/</link>
		<comments>http://codebetter.com/johnvpetersen/2013/03/22/donglegate-a-legal-perspective-and-some-social-commentary/#comments</comments>
		<pubDate>Fri, 22 Mar 2013 21:45:26 +0000</pubDate>
		<dc:creator>johnvpetersen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[DongleGate]]></category>
		<category><![CDATA[Legal Issues]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/johnvpetersen/?p=576]]></guid>
		<description><![CDATA[Those of you that know me, know that I’m both a software developer and a lawyer. I’ve not commented on the #DongleGate issue – except to say that this issue has privacy, first amendment and civil litigation ramifications. Those of&#160;&#8230; <a href="http://codebetter.com/johnvpetersen/2013/03/22/donglegate-a-legal-perspective-and-some-social-commentary/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Those of you that know me, know that I’m both a software developer and a lawyer. I’ve not commented on the #DongleGate issue – except to say that this issue has privacy, first amendment and civil litigation ramifications. Those of us witnessing this escapade have seen at least 1 guy lose his job and this just in, the complainant Adria Richards (http://butyoureagirl.com/) has lost her job as a developer evangelist for SendGrid. Here’s the blog post from her former employer: <a href="http://blog.sendgrid.com/a-difficult-situation/">http://blog.sendgrid.com/a-difficult-situation/</a>.</p>
<p>One thing we can agree on, there is a massive lack of maturity in this business. At one time or another, including yours truly, has been guilty of an off-color joke. Most of the times, at community gatherings like conferences; we are typically amongst friends and feel comfortable that we can be ourselves, letting our guard down. At the end of the day, we must rely on the fact that in this business, we have to have a thick skin and that we are adults. That in no way is meant to justify offensive comments and that somebody like Adria didn’t have a right to be offended. She did have a right to be offended. And to that, it’s not for anybody else to question it. It’s enough for anybody to say they were offended – and others should respect that. That said, does it mean the offended have an open ended license to exact whatever retribution they want on the offenders? No…. In these community gatherings, there is a level of privacy, within the community cocoon; we have a reasonable expectation to.  </p>
<p>We see the t-shirt shirt = “Fork you”. We see on open source projects: “Fork me on GitHub”. Doesn’t take a rocket scientist to see the double entendre here. If one is to where that shirt in public, does that give anybody who is offended license to snap a picture, tweet it, and then hope that some misfortune befalls that person? I don’t think such license is granted. </p>
<p>Consider this YouTube video from Ms. Richard’s: <a href="http://www.youtube.com/watch?v=nMpJSKbsmgQ">http://www.youtube.com/watch?v=nMpJSKbsmgQ</a>. There’s a saying in the law that in matters of equity, you have to have “Clean Hands.” Is it permissible for her to be offended as she was when she makes a video that could be taken as offensive by others? At about 3:03 into the video, she talks about an incident that was done to her – that could very well be taken as offensive, and she let it pass. In this case, she decided to not let something pass…something that WAS NOT said directly to her. If I was prosecuting this case, and I was going to depose Ms. Richards, this is a line of questioning I would surly explore to great details. What was her real motivation here?</p>
<p> This gets to my first question:</p>
<p>Was there a reasonable expectation of privacy by these two gentlemen? </p>
<p>I believe there was. They were having a private conversation, which Ms. Richards overheard. Yes, this was a public place. Did she have the right to express her indignation at those comments to these two gentlemen? Absolutely yes. In fact, that would have been the more impactful thing to do. That would be a proportional response. Reporting the incident to the PyCon staff is not appropriate. They are not there to police what people say. Note, these two guys didn’t say the comment to her. She thrust herself into their conversation. By the same token, the two guys allowed her to confront them. She didn’t. Instead, she took their picture and posted a tweet. And from there, SHE took what was a private thing and made it public. She made the situation worse. In that regard, she violated the privacy rights of these two men, notwithstanding their comments. Speaking of those comments, only her, the two guys and maybe one or two others know what the precise words were. The first result, at least one of the guys lost his job.</p>
<p>Next question..<br />
Does the guy who got fired have a cause of action against Ms. Richards? </p>
<p>This is the part you want to pay attention to as you should think very carefully about the consequences of tweeting something that is private and further, identifying specific people where harm could come to them. First, did these two guys have a right to say what they said, no matter how stupid it was? Yes, they had a right. There is such a thing as a First Amendment last I checked. It’s also not illegal to be stupid. Did the guy who got fired, his employer, have a right to fire him? If he works in an employment at-will state, the answer is yes. Is he totally out of luck? No.. He can sue Ms. Richards for Tortious Interference with an Employment Relationship. She knew and intended a certain level of a negative outcome to these two gentlemen. That’s malice. While his employer may be on good ground to fire him, he can nevertheless sue Ms. Richards to recover damages. There may also be a cause of action on defamation grounds. These two guys are being labeled as sexists when all that may have happened was a joke, off color as it may have been, that offended this one person. That too may be the basis of a cause of action.</p>
<p>Next question..<br />
Is there any other entity that could be liable?</p>
<p>As SendGrid has already admitted, Ms. Richard’s was there in her capacity as a representative as a SendGrid Employee. Ms. Richard&#8217;s did not do SendGrid any favors when she tweeted that she had SendGrid&#8217;s full support &#8211; a claim that SendGrid didn&#8217;t dispute. In the law, there is the legal doctrine of “Respondeat Superior.” It effectively means that the master is liable for the actions of his agent. Ms. Richards has a large Twitter following and that is due in least in part to her former job as a developer evangelist for SendGrid. There’s a strong argument to be made that SendGrid is liable, at least in part,  for Ms. Richard’s actions &#8211; regardless of the fact that they terminated her services. </p>
<p>This whole episode illustrates again the importance of how we react emotionally and the legal consequences therein. If I’m the gentlemen who lost his job, I’m exploring my legal options – and there are legal options. Above all, this is a teachable moment. If you are offended at something somebody does, consider the context. 99.99% of the time, these matters are best handled privately. Takes more courage and is more impactful when you communicate your disdain to the offending party directly. If your goal is to change behavior that will more likely have the desired effect. Sure, you may be told to eff-off.  That’s a risk…a risk worth taking. </p>
<p>How about conference organizers?</p>
<p>I understand that PyCon has modified their code of condut&#8230; Didn&#8217;t know that such a thing existed. I would always suggest to any conference organizer to NOT get into the business of policing their attendees. Rather, I&#8217;d rely on the venue staff for that. Obviously, if somebody is disruptive, boot their tails out. These guys didn&#8217;t appear to be disruptive at all for the record &#8211; not that it really matters in this case.</p>
<p>A word about the “Brogrammer” culture..</p>
<p>You probably know about it. If not, look it up on our favorite search engine. The fact is, guys are often not the sharpest knives in the drawer socially and are often in need of an increase in maturity level. Women have a tough enough time in this business. I know several women that do a lot of work in getting more girls interested in software development. Sad as it is, Adria Richards did more to set that effort back than the two guys she was offended by. That’s a perfect example of irony!! It&#8217;s really a shame. Ms. Richards looks to be a pretty sharp individual &#8211; one who appears to have better common sense than she displayed here. Learn from it folks. </p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/lMFZbIXzErE" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/johnvpetersen/2013/03/22/donglegate-a-legal-perspective-and-some-social-commentary/feed/</wfw:commentRss>
		<slash:comments>54</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/545d3ad0823f1fc4431ff9521a8e74f1?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">johnvpetersen</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/johnvpetersen/2013/03/22/donglegate-a-legal-perspective-and-some-social-commentary/</feedburner:origLink></item>
	<item>
		<title>Node 0.10.x compat issues with the Azure SDK and CLI</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/iIRw1t8xZuc/</link>
		<comments>http://codebetter.com/glennblock/2013/03/18/node-0-10-compat-issues-with-the-azure-sdk-and-cli/#comments</comments>
		<pubDate>Mon, 18 Mar 2013 01:56:03 +0000</pubDate>
		<dc:creator>Glenn Block</dc:creator>
				<category><![CDATA[azure]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/glennblock/?p=691]]></guid>
		<description><![CDATA[Recently the node blog announced that node 0.10 has shipped. This release includes a bunch of exciting improvements to node core around several areas including streams, domains and performance. As soon as it shipped we started to get reports of issues using&#160;&#8230; <a href="http://codebetter.com/glennblock/2013/03/18/node-0-10-compat-issues-with-the-azure-sdk-and-cli/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Recently the node blog <a href="http://blog.nodejs.org/2013/03/11/node-v0-10-0-stable/">announced</a> that node 0.10 has shipped. This release includes a bunch of exciting improvements to node core around several areas including streams, domains and performance.</p>
<p>As soon as it shipped we started to get reports of issues using our SDK and CLI. We&#8217;ve investigated this and uncovered that there are some things we need to fix. In the meanwhile, node 0.10.x is not currently supported. We&#8217;d ask everyone using our SDK and CLI to stick to node 0.8.x for the time being.</p>
<p>If you are using our <a href="https://github.com/downloads/WindowsAzure/azure-sdk-downloads/azuresdk-v0.6.9.pkg">Mac</a> or <a href="http://go.microsoft.com/fwlink/?LinkID=275464&amp;clcid=0x409">Windows</a> installers you should be fine as they each include private copies of node with working versions.</p>
<p>We are on top of this and will be working on this in our next sprint. We&#8217;ll keep you posted and let you know as soon as we have it working which we expect to be very soon.</p>
<p>Thanks for your understanding and sorry for any inconvenience this has caused.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/iIRw1t8xZuc" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/glennblock/2013/03/18/node-0-10-compat-issues-with-the-azure-sdk-and-cli/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/d372d9c0ab35dbe84c6d0a6902ae0594?s=96&amp;d=&amp;r=G" medium="image">
            <media:title type="html">Glenn Block</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/glennblock/2013/03/18/node-0-10-compat-issues-with-the-azure-sdk-and-cli/</feedburner:origLink></item>
	<item>
		<title>Startups and TDD</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/NQcH27KZJW8/</link>
		<comments>http://codebetter.com/gregyoung/2013/03/06/startups-and-tdd/#comments</comments>
		<pubDate>Wed, 06 Mar 2013 14:21:39 +0000</pubDate>
		<dc:creator>gregyoung</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/gregyoung/?p=390]]></guid>
		<description><![CDATA[Yesterday Uncle Bob put up a post on using TDD in start up environments &#8220;The Startup Trap&#8221; its a good read. Check it out. Nate soon after posted: It&#8217;s funny, you never see someone with the title &#8220;Master Craftsman&#8221; at a startup.&#160;&#8230; <a href="http://codebetter.com/gregyoung/2013/03/06/startups-and-tdd/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Yesterday Uncle Bob put up a post on using TDD in start up environments <a href="http://t.co/DLE79YFpkc">&#8220;The Startup Trap&#8221;</a> its a good read. Check it out.</p>
<p>Nate soon after posted:</p>
<blockquote class="twitter-tweet" width="550"><p>It&#8217;s funny, you never see someone with the title &#8220;Master Craftsman&#8221; at a startup. I wonder why?</p>
<p>&mdash; Nate Kohari (@nkohari) <a href="https://twitter.com/nkohari/status/309001001761923072">March 5, 2013</a></p></blockquote>
<p><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>then</p>
<blockquote class="twitter-tweet" width="550"><p>I take it all back. I would strongly encourage startups to use TDD while developing any products that compete with ours. <img src='http://codebetter.com/gregyoung/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&mdash; Nate Kohari (@nkohari) <a href="https://twitter.com/nkohari/status/309005301766561792">March 5, 2013</a></p></blockquote>
<p><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>I wanted to write a few comments about TDD in startups. Good code is the least of the risks in a startup. Sorry but worrying about technical debt making us go slower when we have a two month runway and likely will pivot four times to quote Bob.</p>
<blockquote><p>Captain Sulu when the Klingon power moon of Praxis exploded and a young Lieutenant asked whether they should notify Star-Fleet: &#8220;Are you kidding?&#8221; ARE YOU KIDDING?</p></blockquote>
<p>One of the biggest mistakes in my career was building something appropriate&#8230;</p>
<p>It was just after Hurricane Katrina. I was living in a hotel. An acquaintance asked me if we could hack together this business idea they had for a trading system. He had the knowledge but not the know how. I said sure, hell I was living in a hotel!</p>
<p>In less than two weeks we had an algorithmic trading system. It was a monstrosity of a source base. It was literally a winforms app connected directly to the stock market. UI interactions happened off events directly from the feed! Everything was in code behinds (including the algos!) Due to the nature of the protocol if anything failed during the day and crashed the app (say bad parsing of a string?) the day for the trader was over as they could not restart.</p>
<p>But after two weeks we put it in front of a trader who started using it. We made about 70-80k$ the first month. We had blundered into the pit of success. A few months later I moved up with the company. We decided that we were going to &#8220;do things right&#8221;. While keeping the original version running and limping along as stable as we could keep it while adding just a few features.</p>
<p>We ended up with a redundant multi-user architecture nine months or so later, it was really quite a beautiful system. If a client/server crashed, no big deal just sign it back on, multiple clients? no problem. We moved from a third party provider to a direct exchange link (faster and more information!). We had &gt; 95% code coverage on our core stuff, integration suites including a fake stock exchange that actually sent packets over UDP so we could force various problems with retry reconnects etc/errors. We were very stable and had a proper clean architecture.</p>
<p>In fact you could say that we were dealing with what Bob describes in:</p>
<blockquote><p>As time passes your estimates will grow. You&#8217;ll find it harder and harder to add new features. You will find more and more bugs accumulating. You&#8217;ll start to parse the bugs into critical and acceptable (as if any bug is acceptable!) You&#8217;ll create modules that are so fragile you won&#8217;t trust yourself, or anyone else, to modify them; so you&#8217;ll work around them. You&#8217;ll build a festering pile of code that, with every passing week, requires more and more effort just to keep running. Forward progress will slow and falter. It may even reverse as each release becomes buggier and buggier, and less and less stable. Catastrophes will become more and more common as errors, that should never have happened, create corruptions and damage that take huge traunches of time to repair.</p></blockquote>
<p>We had built a production prototype and were suffering all the pain described by Bob. We were paying down our debt in an &#8220;intelligent&#8221; way much the way many companies that start with production prototypes do.</p>
<p>However this is still a naive viewpoint. What really mattered was that after our nine months of beautiful architecture and coding work we were making approximately 10k/month more than what our stupid production prototype made for all of its shortcomings.</p>
<p><strong>We would have been better off making 30 new production prototypes of different strategies and &#8220;throwing shit at the wall&#8221; to see what worked than spending any time beyond a bit of stabilization of the first. How many new business opportunities would we have found?</strong></p>
<p>There are some lessons here.</p>
<p>1) If we had started with a nine month project it never would have been done</p>
<p>2) A Production Prototype is common as a Minimum Viable Product. Yes testing, engineering, or properly architecting will likely slow you down on a production prototype.</p>
<p>3) Even if you succeed you are often better to stabilize your Production Prototype than to &#8220;build it right&#8221;. Be very careful about taking the &#8220;build it right&#8221; point of view.</p>
<p>4) Context is important!</p>
<p><strong>Never underestimate the value of working software.</strong></p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/NQcH27KZJW8" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/gregyoung/2013/03/06/startups-and-tdd/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/8a61736c3f6b3e02b173c9aa6ce6ca8e?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">gregyoung</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/gregyoung/2013/03/06/startups-and-tdd/</feedburner:origLink></item>
	<item>
		<title>Memo to Microsoft – If you want Windows 8 to succeed, among other things, get apps in the store that people want</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/-E6FefLIfCk/</link>
		<comments>http://codebetter.com/johnvpetersen/2013/03/04/memo-to-microsoft-if-you-want-windows-8-to-succeed-among-other-things-get-apps-in-the-store-that-people-want/#comments</comments>
		<pubDate>Tue, 05 Mar 2013 02:44:32 +0000</pubDate>
		<dc:creator>johnvpetersen</dc:creator>
				<category><![CDATA[Windows 8]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/johnvpetersen/?p=569]]></guid>
		<description><![CDATA[Let me first say I like Windows 8. As on OS, it performs well. I like the way the OS is essentially a first class citizen with the development environment. The consistency across apps, as to sharing, searching, etc. &#8211;&#160;&#8230; <a href="http://codebetter.com/johnvpetersen/2013/03/04/memo-to-microsoft-if-you-want-windows-8-to-succeed-among-other-things-get-apps-in-the-store-that-people-want/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Let me first say I like Windows 8. As on OS, it performs well. I like the way the OS is essentially a first class citizen with the development environment. The consistency across apps, as to sharing, searching, etc. &#8211; is a good thing. The WinRT device &#8211; very slick. Great battery life. For browsing and cranking out business documents, not a bad device. Some of the native apps &#8211; especially email &#8211; need to be way better.</p>
<p>BUT&#8230;&#8230;</p>
<p>Where are the apps? Granted, Words with Friends is finally in store. The new ESPN App is nice. But what about Taxi Magic and Pandora? How about a better FaceBook and Twitter app? Instagram? I was just at an event where somebody was showing Vine &#8211; a really cool iOS app. I looked for it on the Windows App Store&#8230;. <img src='http://codebetter.com/johnvpetersen/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  How about Instapaper???</p>
<p>I&#8217;ve taken the plunge to give the Windows Phone a fair shake. I love the UI. What is needed are apps&#8230;apps people want &#8211; which will drive the platform. Whether Microsoft wants to admit it, the Apple AppStore is the store by which the Windows Store is measured. There&#8217;s A LOT of noise on the Windows Store. Note &#8211; quantity is not quality. If there is a top app in iOS, Windows needs to have that app. Microsoft needs to be focused on those vendors to get these apps built.</p>
<p>Another nit is the difference between Windows 8 and Windows Phone. It would be great if those two worlds could come closer together from a development standpoint. On the plus side, the process by which apps are certified for the store is simple. The Windows App Certification Kit is a nice utility and easy to use. If your app fails, there is clear guidance on what to fix.</p>
<p>None of this is to say there are not useful apps on the Windows/Windows Phone Stores &#8211; there are. And when it comes to things like Live Tiles, Microsoft nailed that one. A very useful feature – which makes the negative things especially frustrating to deal with.</p>
<p>At the end of the day, like many, I want to see Windows 8 succeed. I think and believe there to be a great amount of potential. But to succeed, the public needs to see the apps that are available in other ecosystems. Until that day comes, Windows 8, and in particular Windows Phone, will continue to be third in a 3 horse race &#8211; which shouldn&#8217;t be the case.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/-E6FefLIfCk" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/johnvpetersen/2013/03/04/memo-to-microsoft-if-you-want-windows-8-to-succeed-among-other-things-get-apps-in-the-store-that-people-want/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/545d3ad0823f1fc4431ff9521a8e74f1?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">johnvpetersen</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/johnvpetersen/2013/03/04/memo-to-microsoft-if-you-want-windows-8-to-succeed-among-other-things-get-apps-in-the-store-that-people-want/</feedburner:origLink></item>
	<item>
		<title>scriptcs – Living on the edge in C# without a project on the wings of Roslyn and Nuget</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/3U8QpSDY7d8/</link>
		<comments>http://codebetter.com/glennblock/2013/02/28/scriptcs-living-on-the-edge-in-c-without-a-project-on-the-wings-of-roslyn-and-nuget/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 08:25:17 +0000</pubDate>
		<dc:creator>Glenn Block</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[rosyln]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/glennblock/?p=674]]></guid>
		<description><![CDATA[&#160; Disclaimer: I am not the first person to create a tool for C# scripting. There are a long list of projects from too many people to name, and I respect all of them A big part of why I&#160;&#8230; <a href="http://codebetter.com/glennblock/2013/02/28/scriptcs-living-on-the-edge-in-c-without-a-project-on-the-wings-of-roslyn-and-nuget/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p><a href="http://codebetter.com/glennblock/files/2013/02/MP9004306051.jpg"><img title="MP900430605[1]" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px" border="0" alt="MP900430605[1]" src="http://codebetter.com/glennblock/files/2013/02/MP9004306051_thumb.jpg" width="312" height="209"></a>&nbsp;</p>
<p>Disclaimer: I am not the first person to create a tool for C# scripting. There are a long list of projects from too many people to name, and I respect all of them <img src='http://codebetter.com/glennblock/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  A big part of why I did this was also to mess with Roslyn.</p>
<h2>Learnings from node</h2>
<p>For the past 18 months I’ve been living mostly in text editors and script getting fully absorbed in node.js. Recently I started to think a lot about my C# development experience and if there are things I could bring back from my learning’s with node / JavaScript</p>
<ul>
<li>No projects, just script- One of the things I love about node.js is you don’t need a project. You can just jump in a folder start creating js files and go to town.
<li>No IDE requirement, you can just use a text editor.
<li>Packages over assemblies &#8211; In node, when you want to get something you use npm to download the packages.It’s super simple. You just have your app and your local node_modules folder and you are good to go.
<li>No compilation &#8211; This is a big one. With node, I just run node.exe and my app and it works. I don’t have to first create an executable to run, I just run.</li>
</ul>
<p><font size="5"></font></p>
<p>On first glance it might seem like this is just oil and water with C#. </p>
<p>Thanks to Roslyn and Nuget however I no longer think that’s the case.</p>
<h2>What is Roslyn?</h2>
<p><a href="http://codebetter.com/glennblock/files/2013/02/image.png"><img title="image" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px" border="0" alt="image" src="http://codebetter.com/glennblock/files/2013/02/image_thumb.png" width="379" height="122"></a>&nbsp;</p>
<p>Roslyn is a compiler as a service. It gives you an API that lets you compile and analyze code on the fly. Additionally it gives you hooks to dynamically refactor and generate code. Beyond that it also includes really powerful scripting support allowing you to author applications and components as loose C# scripts. You don’t need a class if you don’t want one and you don’t need to compile. And you don’t need to use Visual Studio, you can host Roslyn in your own applications and components and it’s even got nuget <a href="http://nuget.org/packages?q=roslyn">packages</a>.. You can read more on Roslyn at <a href="http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx">MSDN</a> or in a nice <a href="http://www.strathweb.com/2012/09/scripting-web-api-self-host-with-roslyn-ctp-part-1/">post</a> from Filip on Roslyn and Web API</p>
<p>Roslyn is a breath of fresh air in terms of it’s simplicity. If you have worked with the existing <strike>horrendous</strike> mechanisms for doing this like the Codedom you are going to love Roslyn. You can literally be up and running with Roslyn having it compile scripts for you in a matter of minutes.</p>
<h2>How does Roslyn help?</h2>
<p>I can cross off three bullets <img src='http://codebetter.com/glennblock/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<ul>
<li><strike>No projects, just script- One of the things I love about node.js is you don’t need a project. You can just jump in a folder start creating js files and go to town.</strike>
<li><strike>No IDE requirement, you can just use a text editor.</strike>
<li>Packages over assemblies &#8211; In node, when you want to get something you use npm to download the packages.It’s super simple. You just have your app and your local node_modules folder and you are good to go.
<li><strike>No compilation &#8211; This is a big one. With node, I just run node.exe and my app and it works. I don’t have to first create an executable to run, I just run.</strike></li>
</ul>
<p>Now yes it does compile, but that’s all taken care of for me, I don’t have to think about it.</p>
<h2>Packages vs Assemblies</h2>
<p>For the last bullet I looked to <a href="http://nuget.org/">nuget</a>. The nuget command line provides an easy way to install packages right from the command line into the same folder as a set of scripts. However, the challenge is how to make those scripts see those packages? Today Nuget works great with a csproj and within Visual Studio or using MS Build. But what if you don’t have Visual Studio or a csproj? Well when you install packages using the cmd line you get folders for each package that at some level actually do contain binaries. So, if you can find those binaries and get them loaded up into Rosyln, you are golden. Yes this doesn’t get rid of assemblies, but I don’t have to manage them individually, I just install packages.</p>
<ul>
<li><strike>Packages over assemblies &#8211; In node, when you want to get something you use npm to download the packages.It’s super simple. You just have your app and your local node_modules folder and you are good to go.</strike></li>
</ul>
<h2>Roslyn + Nuget = scriptcs</h2>
<p>Having crossed off all my bullets, I then decided to spike a little with Roslyn and out came Scriptcs: <a title="https://github.com/glennblock/scriptcs" href="https://github.com/glennblock/scriptcs">https://github.com/glennblock/scriptcs</a></p>
<p>scriptcs is a little command line tool which lets you have the following work flow. </p>
<ul>
<li>You author your “app” as a .csx file or csharp script in your favorite editor. There’s no project.
<li>You add dependencies to your app by simply installing nuget packages from the command line. By convention the dlls within those packages will be loaded up. No need for references as the idea is if it’s there you want it.
<li>You add GAC references or other dll references (not nuget packages) by using the “r:” Roslyn syntax, i.e.”r: System.Net”.
<li>You run your app using “scriptcs” passing the csx file.</li>
</ul>
<p>For example here is a snippet of setting up a web api host.</p>
<script src="http://gist.github.com/5055156.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5055156" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-scriptcs-cs-L1" rel="file-scriptcs-cs-L1">1</span>
          <span class="line-number" id="file-scriptcs-cs-L2" rel="file-scriptcs-cs-L2">2</span>
          <span class="line-number" id="file-scriptcs-cs-L3" rel="file-scriptcs-cs-L3">3</span>
          <span class="line-number" id="file-scriptcs-cs-L4" rel="file-scriptcs-cs-L4">4</span>
          <span class="line-number" id="file-scriptcs-cs-L5" rel="file-scriptcs-cs-L5">5</span>
          <span class="line-number" id="file-scriptcs-cs-L6" rel="file-scriptcs-cs-L6">6</span>
          <span class="line-number" id="file-scriptcs-cs-L7" rel="file-scriptcs-cs-L7">7</span>
          <span class="line-number" id="file-scriptcs-cs-L8" rel="file-scriptcs-cs-L8">8</span>
          <span class="line-number" id="file-scriptcs-cs-L9" rel="file-scriptcs-cs-L9">9</span>
          <span class="line-number" id="file-scriptcs-cs-L10" rel="file-scriptcs-cs-L10">10</span>
          <span class="line-number" id="file-scriptcs-cs-L11" rel="file-scriptcs-cs-L11">11</span>
          <span class="line-number" id="file-scriptcs-cs-L12" rel="file-scriptcs-cs-L12">12</span>
          <span class="line-number" id="file-scriptcs-cs-L13" rel="file-scriptcs-cs-L13">13</span>
          <span class="line-number" id="file-scriptcs-cs-L14" rel="file-scriptcs-cs-L14">14</span>
          <span class="line-number" id="file-scriptcs-cs-L15" rel="file-scriptcs-cs-L15">15</span>
          <span class="line-number" id="file-scriptcs-cs-L16" rel="file-scriptcs-cs-L16">16</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-scriptcs-cs-LC1"><span class="k">using</span> <span class="nn">System</span><span class="p">;</span></div><div class="line" id="file-scriptcs-cs-LC2"><span class="k">using</span> <span class="nn">System.IO</span><span class="p">;</span></div><div class="line" id="file-scriptcs-cs-LC3"><span class="k">using</span> <span class="nn">System.Web.Http</span><span class="p">;</span></div><div class="line" id="file-scriptcs-cs-LC4"><span class="k">using</span> <span class="nn">System.Web.Http.SelfHost</span><span class="p">;</span></div><div class="line" id="file-scriptcs-cs-LC5">&nbsp;</div><div class="line" id="file-scriptcs-cs-LC6"><span class="kt">var</span> <span class="n">address</span> <span class="p">=</span> <span class="s">&quot;http://localhost:8080&quot;</span><span class="p">;</span></div><div class="line" id="file-scriptcs-cs-LC7"><span class="kt">var</span> <span class="n">conf</span> <span class="p">=</span> <span class="k">new</span> <span class="n">HttpSelfHostConfiguration</span><span class="p">(</span><span class="k">new</span> <span class="n">Uri</span><span class="p">(</span><span class="n">address</span><span class="p">));</span></div><div class="line" id="file-scriptcs-cs-LC8"><span class="n">conf</span><span class="p">.</span><span class="n">Routes</span><span class="p">.</span><span class="n">MapHttpRoute</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="s">&quot;DefaultApi&quot;</span><span class="p">,</span></div><div class="line" id="file-scriptcs-cs-LC9">   <span class="n">routeTemplate</span><span class="p">:</span> <span class="s">&quot;api/{controller}/{id}&quot;</span><span class="p">,</span></div><div class="line" id="file-scriptcs-cs-LC10">   <span class="n">defaults</span><span class="p">:</span> <span class="k">new</span> <span class="p">{</span> <span class="n">id</span> <span class="p">=</span> <span class="n">RouteParameter</span><span class="p">.</span><span class="n">Optional</span> <span class="p">}</span></div><div class="line" id="file-scriptcs-cs-LC11"><span class="p">);</span></div><div class="line" id="file-scriptcs-cs-LC12">&nbsp;</div><div class="line" id="file-scriptcs-cs-LC13"><span class="kt">var</span> <span class="n">server</span> <span class="p">=</span> <span class="k">new</span> <span class="n">HttpSelfHostServer</span><span class="p">(</span><span class="n">conf</span><span class="p">);</span></div><div class="line" id="file-scriptcs-cs-LC14"><span class="n">server</span><span class="p">.</span><span class="n">OpenAsync</span><span class="p">().</span><span class="n">Wait</span><span class="p">();</span></div><div class="line" id="file-scriptcs-cs-LC15"><span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">&quot;Listening...&quot;</span><span class="p">);</span></div><div class="line" id="file-scriptcs-cs-LC16"><span class="n">Console</span><span class="p">.</span><span class="n">ReadKey</span><span class="p">();</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/glennblock/5055156/raw/3fd0404ebad51ef7d550b95d5382608cd73594c4/scriptcs.cs" style="float:right">view raw</a>
          <a href="https://gist.github.com/glennblock/5055156#file-scriptcs-cs" style="float:right; margin-right:10px; color:#666;">scriptcs.cs</a>
          <a href="https://gist.github.com/glennblock/5055156">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<h2>Back to reality, though the future looks bright.</h2>
<p><a href="http://codebetter.com/glennblock/files/2013/02/MP9004031661.jpg"><img title="MP900403166[1]" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;border-top-width: 0px" border="0" alt="MP900403166[1]" src="http://codebetter.com/glennblock/files/2013/02/MP9004031661_thumb.jpg" width="240" height="161"></a> </p>
<p>At this point I would say this is just an experiment. I am not claiming you can build an enterprise app with this or anything like that. I am using this more as an exploration to understand what a c# script experience from outside VS could look like.</p>
<p>From here there’s a lot more places to go. One would be allowing you to have includes of other csx files as you probably don’t want your whole app in a single file! Beyond that Roslyn offers a ton of rewriting, AST analysis or even auto-refactoring capabilities that I am sure can be leveraged in scriptcs but are not. </p>
<p>Seeing this definitely makes me excited about where things can go in the future. I’d love to hear your thoughts.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/3U8QpSDY7d8" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/glennblock/2013/02/28/scriptcs-living-on-the-edge-in-c-without-a-project-on-the-wings-of-roslyn-and-nuget/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/d372d9c0ab35dbe84c6d0a6902ae0594?s=96&amp;d=&amp;r=G" medium="image">
            <media:title type="html">Glenn Block</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/glennblock/2013/02/28/scriptcs-living-on-the-edge-in-c-without-a-project-on-the-wings-of-roslyn-and-nuget/</feedburner:origLink></item>
	<item>
		<title>A Program to explore Code Diff</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/_nr3Ozre_bc/</link>
		<comments>http://codebetter.com/patricksmacchia/2013/02/21/a-program-to-explore-code-diff/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 11:35:43 +0000</pubDate>
		<dc:creator>Patrick Smacchia</dc:creator>
				<category><![CDATA[Change summary]]></category>
		<category><![CDATA[Changes]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Code Diff]]></category>
		<category><![CDATA[CQLinq]]></category>
		<category><![CDATA[LINQ]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/patricksmacchia/?p=780]]></guid>
		<description><![CDATA[Recently I answered the question Generating a diff report using NDepend during build on stackoverflow. As explained in my answer, the easy way to go is to follow the documentation on Reporting Code Diff. But for the user that wants something smarter&#160;&#8230; <a href="http://codebetter.com/patricksmacchia/2013/02/21/a-program-to-explore-code-diff/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Recently I answered the question <a href="http://stackoverflow.com/questions/14802373/generating-a-diff-report-using-ndepend-during-build/14814456#14814456" target="_blank">Generating a diff report using NDepend during build</a> on stackoverflow. As explained in my answer, the easy way to go is to follow the documentation on <a href="http://www.ndepend.com/Doc_CI_Diff.aspx" target="_blank">Reporting Code Diff</a>. But for the user that wants something smarter and more programatic, I propose a program based on <a href="http://www.ndepend.com/API/webframe.html?NDepend.API_introduction.html" target="_blank">NDepend.API</a> that:</p>
<ul>
<li><span style="line-height: 16px">explore two folders containing older and newer versions of assemblies to compare</span></li>
<li>create on-the-fly two NDepend projets and analyze them</li>
<li>compare the two older/newer code base snapshots, which lead to the creation of a <a href="http://www.ndepend.com/API/webframe.html?NDepend.API~NDepend.CodeModel.ICompareContext.html" target="_blank">ICompareContext</a> object</li>
<li>use this compare-context object to explore code diff and changes</li>
</ul>
<script src="http://gist.github.com/5003686.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5003686" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-cs-L1" rel="file-gistfile1-cs-L1">1</span>
          <span class="line-number" id="file-gistfile1-cs-L2" rel="file-gistfile1-cs-L2">2</span>
          <span class="line-number" id="file-gistfile1-cs-L3" rel="file-gistfile1-cs-L3">3</span>
          <span class="line-number" id="file-gistfile1-cs-L4" rel="file-gistfile1-cs-L4">4</span>
          <span class="line-number" id="file-gistfile1-cs-L5" rel="file-gistfile1-cs-L5">5</span>
          <span class="line-number" id="file-gistfile1-cs-L6" rel="file-gistfile1-cs-L6">6</span>
          <span class="line-number" id="file-gistfile1-cs-L7" rel="file-gistfile1-cs-L7">7</span>
          <span class="line-number" id="file-gistfile1-cs-L8" rel="file-gistfile1-cs-L8">8</span>
          <span class="line-number" id="file-gistfile1-cs-L9" rel="file-gistfile1-cs-L9">9</span>
          <span class="line-number" id="file-gistfile1-cs-L10" rel="file-gistfile1-cs-L10">10</span>
          <span class="line-number" id="file-gistfile1-cs-L11" rel="file-gistfile1-cs-L11">11</span>
          <span class="line-number" id="file-gistfile1-cs-L12" rel="file-gistfile1-cs-L12">12</span>
          <span class="line-number" id="file-gistfile1-cs-L13" rel="file-gistfile1-cs-L13">13</span>
          <span class="line-number" id="file-gistfile1-cs-L14" rel="file-gistfile1-cs-L14">14</span>
          <span class="line-number" id="file-gistfile1-cs-L15" rel="file-gistfile1-cs-L15">15</span>
          <span class="line-number" id="file-gistfile1-cs-L16" rel="file-gistfile1-cs-L16">16</span>
          <span class="line-number" id="file-gistfile1-cs-L17" rel="file-gistfile1-cs-L17">17</span>
          <span class="line-number" id="file-gistfile1-cs-L18" rel="file-gistfile1-cs-L18">18</span>
          <span class="line-number" id="file-gistfile1-cs-L19" rel="file-gistfile1-cs-L19">19</span>
          <span class="line-number" id="file-gistfile1-cs-L20" rel="file-gistfile1-cs-L20">20</span>
          <span class="line-number" id="file-gistfile1-cs-L21" rel="file-gistfile1-cs-L21">21</span>
          <span class="line-number" id="file-gistfile1-cs-L22" rel="file-gistfile1-cs-L22">22</span>
          <span class="line-number" id="file-gistfile1-cs-L23" rel="file-gistfile1-cs-L23">23</span>
          <span class="line-number" id="file-gistfile1-cs-L24" rel="file-gistfile1-cs-L24">24</span>
          <span class="line-number" id="file-gistfile1-cs-L25" rel="file-gistfile1-cs-L25">25</span>
          <span class="line-number" id="file-gistfile1-cs-L26" rel="file-gistfile1-cs-L26">26</span>
          <span class="line-number" id="file-gistfile1-cs-L27" rel="file-gistfile1-cs-L27">27</span>
          <span class="line-number" id="file-gistfile1-cs-L28" rel="file-gistfile1-cs-L28">28</span>
          <span class="line-number" id="file-gistfile1-cs-L29" rel="file-gistfile1-cs-L29">29</span>
          <span class="line-number" id="file-gistfile1-cs-L30" rel="file-gistfile1-cs-L30">30</span>
          <span class="line-number" id="file-gistfile1-cs-L31" rel="file-gistfile1-cs-L31">31</span>
          <span class="line-number" id="file-gistfile1-cs-L32" rel="file-gistfile1-cs-L32">32</span>
          <span class="line-number" id="file-gistfile1-cs-L33" rel="file-gistfile1-cs-L33">33</span>
          <span class="line-number" id="file-gistfile1-cs-L34" rel="file-gistfile1-cs-L34">34</span>
          <span class="line-number" id="file-gistfile1-cs-L35" rel="file-gistfile1-cs-L35">35</span>
          <span class="line-number" id="file-gistfile1-cs-L36" rel="file-gistfile1-cs-L36">36</span>
          <span class="line-number" id="file-gistfile1-cs-L37" rel="file-gistfile1-cs-L37">37</span>
          <span class="line-number" id="file-gistfile1-cs-L38" rel="file-gistfile1-cs-L38">38</span>
          <span class="line-number" id="file-gistfile1-cs-L39" rel="file-gistfile1-cs-L39">39</span>
          <span class="line-number" id="file-gistfile1-cs-L40" rel="file-gistfile1-cs-L40">40</span>
          <span class="line-number" id="file-gistfile1-cs-L41" rel="file-gistfile1-cs-L41">41</span>
          <span class="line-number" id="file-gistfile1-cs-L42" rel="file-gistfile1-cs-L42">42</span>
          <span class="line-number" id="file-gistfile1-cs-L43" rel="file-gistfile1-cs-L43">43</span>
          <span class="line-number" id="file-gistfile1-cs-L44" rel="file-gistfile1-cs-L44">44</span>
          <span class="line-number" id="file-gistfile1-cs-L45" rel="file-gistfile1-cs-L45">45</span>
          <span class="line-number" id="file-gistfile1-cs-L46" rel="file-gistfile1-cs-L46">46</span>
          <span class="line-number" id="file-gistfile1-cs-L47" rel="file-gistfile1-cs-L47">47</span>
          <span class="line-number" id="file-gistfile1-cs-L48" rel="file-gistfile1-cs-L48">48</span>
          <span class="line-number" id="file-gistfile1-cs-L49" rel="file-gistfile1-cs-L49">49</span>
          <span class="line-number" id="file-gistfile1-cs-L50" rel="file-gistfile1-cs-L50">50</span>
          <span class="line-number" id="file-gistfile1-cs-L51" rel="file-gistfile1-cs-L51">51</span>
          <span class="line-number" id="file-gistfile1-cs-L52" rel="file-gistfile1-cs-L52">52</span>
          <span class="line-number" id="file-gistfile1-cs-L53" rel="file-gistfile1-cs-L53">53</span>
          <span class="line-number" id="file-gistfile1-cs-L54" rel="file-gistfile1-cs-L54">54</span>
          <span class="line-number" id="file-gistfile1-cs-L55" rel="file-gistfile1-cs-L55">55</span>
          <span class="line-number" id="file-gistfile1-cs-L56" rel="file-gistfile1-cs-L56">56</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-cs-LC1"><span class="k">using</span> <span class="nn">System</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC2"><span class="k">using</span> <span class="nn">System.Collections.Generic</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC3"><span class="k">using</span> <span class="nn">System.Diagnostics</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC4"><span class="k">using</span> <span class="nn">System.Linq</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC5"><span class="k">using</span> <span class="nn">NDepend</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC6"><span class="k">using</span> <span class="nn">NDepend.Analysis</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC7"><span class="k">using</span> <span class="nn">NDepend.CodeModel</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC8"><span class="k">using</span> <span class="nn">NDepend.Path</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC9"><span class="k">using</span> <span class="nn">NDepend.Project</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC10">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC11">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC12"><span class="k">class</span> <span class="nc">FoldersDiff</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-cs-LC13">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC14">   <span class="k">private</span> <span class="k">static</span> <span class="k">readonly</span> <span class="n">NDependServicesProvider</span> <span class="n">s_NDependServicesProvider</span> <span class="p">=</span> <span class="k">new</span> <span class="n">NDependServicesProvider</span><span class="p">();</span></div><div class="line" id="file-gistfile1-cs-LC15">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC16">   <span class="k">internal</span> <span class="k">static</span> <span class="k">void</span> <span class="nf">Main</span><span class="p">()</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-cs-LC17">      <span class="kt">var</span> <span class="n">dirOld</span> <span class="p">=</span> <span class="s">@&quot;C:\MyProduct\OldAssembliesDir&quot;</span><span class="p">.</span><span class="n">ToAbsoluteDirectoryPath</span><span class="p">();</span></div><div class="line" id="file-gistfile1-cs-LC18">      <span class="kt">var</span> <span class="n">dirNew</span> <span class="p">=</span> <span class="s">@&quot;C:\MyProduct\NewAssembliesDir&quot;</span><span class="p">.</span><span class="n">ToAbsoluteDirectoryPath</span><span class="p">();</span></div><div class="line" id="file-gistfile1-cs-LC19">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC20">      <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">&quot;Analyzing assemblies in &quot;</span> <span class="p">+</span> <span class="n">dirOld</span><span class="p">.</span><span class="n">ToString</span><span class="p">());</span></div><div class="line" id="file-gistfile1-cs-LC21">      <span class="kt">var</span> <span class="n">codeBaseOld</span> <span class="p">=</span> <span class="n">GetCodeBaseFromAsmInDir</span><span class="p">(</span><span class="n">dirOld</span><span class="p">,</span> <span class="n">TemporaryProjectMode</span><span class="p">.</span><span class="n">TemporaryOlder</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC22">      <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">&quot;Analyzing assemblies in &quot;</span> <span class="p">+</span> <span class="n">dirNew</span><span class="p">.</span><span class="n">ToString</span><span class="p">());</span></div><div class="line" id="file-gistfile1-cs-LC23">      <span class="kt">var</span> <span class="n">codeBaseNew</span> <span class="p">=</span> <span class="n">GetCodeBaseFromAsmInDir</span><span class="p">(</span><span class="n">dirNew</span><span class="p">,</span> <span class="n">TemporaryProjectMode</span><span class="p">.</span><span class="n">TemporaryNewer</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC24">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC25">      <span class="kt">var</span> <span class="n">compareContext</span> <span class="p">=</span> <span class="n">codeBaseNew</span><span class="p">.</span><span class="n">CreateCompareContextWithOlder</span><span class="p">(</span><span class="n">codeBaseOld</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC26">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC27">      <span class="c1">// So much more can be done by exploring fine-grained diff in codeBases and compareContext</span></div><div class="line" id="file-gistfile1-cs-LC28">      <span class="n">Dump</span><span class="p">(</span><span class="s">&quot;Added assemblies&quot;</span><span class="p">,</span> <span class="n">codeBaseNew</span><span class="p">.</span><span class="n">Assemblies</span><span class="p">.</span><span class="n">Where</span><span class="p">(</span><span class="n">compareContext</span><span class="p">.</span><span class="n">WasAdded</span><span class="p">));</span></div><div class="line" id="file-gistfile1-cs-LC29">      <span class="n">Dump</span><span class="p">(</span><span class="s">&quot;Removed assemblies&quot;</span><span class="p">,</span> <span class="n">codeBaseOld</span><span class="p">.</span><span class="n">Assemblies</span><span class="p">.</span><span class="n">Where</span><span class="p">(</span><span class="n">compareContext</span><span class="p">.</span><span class="n">WasRemoved</span><span class="p">));</span></div><div class="line" id="file-gistfile1-cs-LC30">      <span class="n">Dump</span><span class="p">(</span><span class="s">&quot;Assemblies with modified code&quot;</span><span class="p">,</span> <span class="n">codeBaseNew</span><span class="p">.</span><span class="n">Assemblies</span><span class="p">.</span><span class="n">Where</span><span class="p">(</span><span class="n">compareContext</span><span class="p">.</span><span class="n">CodeWasChanged</span><span class="p">));</span></div><div class="line" id="file-gistfile1-cs-LC31">      <span class="n">Console</span><span class="p">.</span><span class="n">Read</span><span class="p">();</span></div><div class="line" id="file-gistfile1-cs-LC32">   <span class="p">}</span></div><div class="line" id="file-gistfile1-cs-LC33">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC34">   <span class="k">internal</span> <span class="k">static</span> <span class="k">void</span> <span class="nf">Dump</span><span class="p">(</span><span class="kt">string</span> <span class="n">title</span><span class="p">,</span> <span class="n">IEnumerable</span><span class="p">&lt;</span><span class="n">IAssembly</span><span class="p">&gt;</span> <span class="n">assemblies</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-cs-LC35">      <span class="n">Debug</span><span class="p">.</span><span class="n">Assert</span><span class="p">(!</span><span class="kt">string</span><span class="p">.</span><span class="n">IsNullOrEmpty</span><span class="p">(</span><span class="n">title</span><span class="p">));</span></div><div class="line" id="file-gistfile1-cs-LC36">      <span class="n">Debug</span><span class="p">.</span><span class="n">Assert</span><span class="p">(</span><span class="n">assemblies</span> <span class="p">!=</span> <span class="k">null</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC37">      <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">title</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC38">      <span class="k">foreach</span> <span class="p">(</span><span class="kt">var</span> <span class="n">@assembly</span> <span class="k">in</span> <span class="n">assemblies</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-cs-LC39">         <span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">&quot;   &quot;</span> <span class="p">+</span> <span class="n">@assembly</span><span class="p">.</span><span class="n">Name</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC40">      <span class="p">}</span></div><div class="line" id="file-gistfile1-cs-LC41">   <span class="p">}</span></div><div class="line" id="file-gistfile1-cs-LC42">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC43">   <span class="k">internal</span> <span class="k">static</span> <span class="n">ICodeBase</span> <span class="nf">GetCodeBaseFromAsmInDir</span><span class="p">(</span><span class="n">IAbsoluteDirectoryPath</span> <span class="n">dir</span><span class="p">,</span> <span class="n">TemporaryProjectMode</span> <span class="n">temporaryProjectMode</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-cs-LC44">      <span class="n">Debug</span><span class="p">.</span><span class="n">Assert</span><span class="p">(</span><span class="n">dir</span><span class="p">.</span><span class="n">Exists</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC45">      <span class="kt">var</span> <span class="n">dotNetManager</span> <span class="p">=</span> <span class="n">s_NDependServicesProvider</span><span class="p">.</span><span class="n">DotNetManager</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC46">      <span class="kt">var</span> <span class="n">assembliesPath</span> <span class="p">=</span> <span class="n">dir</span><span class="p">.</span><span class="n">ChildrenFilesPath</span><span class="p">.</span><span class="n">Where</span><span class="p">(</span><span class="n">dotNetManager</span><span class="p">.</span><span class="n">IsAssembly</span><span class="p">).</span><span class="n">ToArray</span><span class="p">();</span></div><div class="line" id="file-gistfile1-cs-LC47">      <span class="n">Debug</span><span class="p">.</span><span class="n">Assert</span><span class="p">(</span><span class="n">assembliesPath</span><span class="p">.</span><span class="n">Length</span> <span class="p">&gt;</span> <span class="m">0</span><span class="p">);</span> <span class="c1">// Make sure we found assemblies</span></div><div class="line" id="file-gistfile1-cs-LC48">      <span class="kt">var</span> <span class="n">projectManager</span> <span class="p">=</span> <span class="n">s_NDependServicesProvider</span><span class="p">.</span><span class="n">ProjectManager</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC49">      <span class="n">IProject</span> <span class="n">project</span> <span class="p">=</span> <span class="n">projectManager</span><span class="p">.</span><span class="n">CreateTemporaryProject</span><span class="p">(</span><span class="n">assembliesPath</span><span class="p">,</span> <span class="n">temporaryProjectMode</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC50">&nbsp;</div><div class="line" id="file-gistfile1-cs-LC51">      <span class="c1">// In PowerTool context, better call:</span></div><div class="line" id="file-gistfile1-cs-LC52">      <span class="c1">// var analysisResult = ProjectAnalysisUtils.RunAnalysisShowProgressOnConsole(project);</span></div><div class="line" id="file-gistfile1-cs-LC53">      <span class="kt">var</span> <span class="n">analysisResult</span> <span class="p">=</span> <span class="n">project</span><span class="p">.</span><span class="n">RunAnalysis</span><span class="p">();</span></div><div class="line" id="file-gistfile1-cs-LC54">      <span class="k">return</span> <span class="n">analysisResult</span><span class="p">.</span><span class="n">CodeBase</span><span class="p">;</span></div><div class="line" id="file-gistfile1-cs-LC55">   <span class="p">}</span></div><div class="line" id="file-gistfile1-cs-LC56"><span class="p">}</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/anonymous/5003686/raw/846c00ea8722fca2cfcfd1935ec2e9d8d44ada80/gistfile1.cs" style="float:right">view raw</a>
          <a href="https://gist.github.com/anonymous/5003686#file-gistfile1-cs" style="float:right; margin-right:10px; color:#666;">gistfile1.cs</a>
          <a href="https://gist.github.com/anonymous/5003686">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>The power offered by a compare-context object is barely exposed here. We only reports 3 lists of assemblies added/removed/changed, which can already be a useful information. But much more can be done with a compare-context object in hands. I wrote recently about <a href="http://codebetter.com/patricksmacchia/2013/02/07/ruling-code-quality-regression/" target="_blank">how Code Query LINQ can be used to write rules to detect code regression issue</a>. This post explains how code-diff can be used to detect regression, including API Breaking Changes, loss in code quality, recent code not well covered by tests&#8230; All CQLinq queries/rules exposed are based on <a href="http://www.ndepend.com/API/webframe.html?NDepend.API~NDepend.CodeModel_namespace.html" target="_blank">NDepend.CodeModel</a> API. And thus, they can all be integrated and combined into a program that starts like the one above, and then uses a compare-context object to explore code diff.</p>
<p>A subtle points is that when one writes a CQLinq rule involving code diff, one doesn&#8217;t deal with a compare-context object. This is an astute we use to make CQLinq rules/queries as fluent, concise and elegant as possible. Indeed, a CQLinq pre-compiling phase takes care to transform calls to extension methods, into calls involving the compare-context. Hence the following CQLinq rule that reports methods that were complex, and that became even more complex&#8230;.</p>
<script src="http://gist.github.com/5003795.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5003795" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-cs-L1" rel="file-gistfile1-cs-L1">1</span>
          <span class="line-number" id="file-gistfile1-cs-L2" rel="file-gistfile1-cs-L2">2</span>
          <span class="line-number" id="file-gistfile1-cs-L3" rel="file-gistfile1-cs-L3">3</span>
          <span class="line-number" id="file-gistfile1-cs-L4" rel="file-gistfile1-cs-L4">4</span>
          <span class="line-number" id="file-gistfile1-cs-L5" rel="file-gistfile1-cs-L5">5</span>
          <span class="line-number" id="file-gistfile1-cs-L6" rel="file-gistfile1-cs-L6">6</span>
          <span class="line-number" id="file-gistfile1-cs-L7" rel="file-gistfile1-cs-L7">7</span>
          <span class="line-number" id="file-gistfile1-cs-L8" rel="file-gistfile1-cs-L8">8</span>
          <span class="line-number" id="file-gistfile1-cs-L9" rel="file-gistfile1-cs-L9">9</span>
          <span class="line-number" id="file-gistfile1-cs-L10" rel="file-gistfile1-cs-L10">10</span>
          <span class="line-number" id="file-gistfile1-cs-L11" rel="file-gistfile1-cs-L11">11</span>
          <span class="line-number" id="file-gistfile1-cs-L12" rel="file-gistfile1-cs-L12">12</span>
          <span class="line-number" id="file-gistfile1-cs-L13" rel="file-gistfile1-cs-L13">13</span>
          <span class="line-number" id="file-gistfile1-cs-L14" rel="file-gistfile1-cs-L14">14</span>
          <span class="line-number" id="file-gistfile1-cs-L15" rel="file-gistfile1-cs-L15">15</span>
          <span class="line-number" id="file-gistfile1-cs-L16" rel="file-gistfile1-cs-L16">16</span>
          <span class="line-number" id="file-gistfile1-cs-L17" rel="file-gistfile1-cs-L17">17</span>
          <span class="line-number" id="file-gistfile1-cs-L18" rel="file-gistfile1-cs-L18">18</span>
          <span class="line-number" id="file-gistfile1-cs-L19" rel="file-gistfile1-cs-L19">19</span>
          <span class="line-number" id="file-gistfile1-cs-L20" rel="file-gistfile1-cs-L20">20</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-cs-LC1"><span class="c1">// &lt;Name&gt;Avoid making complex methods even more complex (Source CC)&lt;/Name&gt;</span></div><div class="line" id="file-gistfile1-cs-LC2"><span class="c1">// To visualize changes in code, right-click a matched method and select:</span></div><div class="line" id="file-gistfile1-cs-LC3"><span class="c1">//  - Compare older and newer versions of source file</span></div><div class="line" id="file-gistfile1-cs-LC4"><span class="c1">//  - Compare older and newer versions disassembled with Reflector</span></div><div class="line" id="file-gistfile1-cs-LC5"> </div><div class="line" id="file-gistfile1-cs-LC6"><span class="n">warnif</span> <span class="n">count</span> <span class="p">&gt;</span> <span class="m">0</span> </div><div class="line" id="file-gistfile1-cs-LC7"><span class="k">from</span> <span class="n">m</span> <span class="k">in</span> <span class="n">JustMyCode</span><span class="p">.</span><span class="n">Methods</span> <span class="k">where</span></div><div class="line" id="file-gistfile1-cs-LC8"> <span class="p">!</span><span class="n">m</span><span class="p">.</span><span class="n">IsAbstract</span> <span class="p">&amp;&amp;</span></div><div class="line" id="file-gistfile1-cs-LC9">  <span class="n">m</span><span class="p">.</span><span class="n">IsPresentInBothBuilds</span><span class="p">()</span> <span class="p">&amp;&amp;</span></div><div class="line" id="file-gistfile1-cs-LC10">  <span class="n">m</span><span class="p">.</span><span class="n">CodeWasChanged</span><span class="p">()</span></div><div class="line" id="file-gistfile1-cs-LC11"> </div><div class="line" id="file-gistfile1-cs-LC12"><span class="n">let</span> <span class="n">oldCC</span> <span class="p">=</span> <span class="n">m</span><span class="p">.</span><span class="n">OlderVersion</span><span class="p">().</span><span class="n">CyclomaticComplexity</span></div><div class="line" id="file-gistfile1-cs-LC13"><span class="k">where</span> <span class="n">oldCC</span> <span class="p">&gt;</span> <span class="m">6</span> <span class="p">&amp;&amp;</span> <span class="n">m</span><span class="p">.</span><span class="n">CyclomaticComplexity</span> <span class="p">&gt;</span> <span class="n">oldCC</span> </div><div class="line" id="file-gistfile1-cs-LC14"> </div><div class="line" id="file-gistfile1-cs-LC15"><span class="k">select</span> <span class="k">new</span> <span class="p">{</span> <span class="n">m</span><span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC16">    <span class="n">oldCC</span> <span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC17">    <span class="n">newCC</span> <span class="p">=</span> <span class="n">m</span><span class="p">.</span><span class="n">CyclomaticComplexity</span> <span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC18">    <span class="n">oldLoc</span> <span class="p">=</span> <span class="n">m</span><span class="p">.</span><span class="n">OlderVersion</span><span class="p">().</span><span class="n">NbLinesOfCode</span><span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC19">    <span class="n">newLoc</span> <span class="p">=</span> <span class="n">m</span><span class="p">.</span><span class="n">NbLinesOfCode</span><span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC20"><span class="p">}</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/anonymous/5003795/raw/62396fbae9d732a7d3d104f5b5c72b7c2f429892/gistfile1.cs" style="float:right">view raw</a>
          <a href="https://gist.github.com/anonymous/5003795#file-gistfile1-cs" style="float:right; margin-right:10px; color:#666;">gistfile1.cs</a>
          <a href="https://gist.github.com/anonymous/5003795">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>&#8230;is actually transformed into this expression, where the usage of the compare-context is made obvious.</p>
<script src="http://gist.github.com/5003799.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5003799" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-cs-L1" rel="file-gistfile1-cs-L1">1</span>
          <span class="line-number" id="file-gistfile1-cs-L2" rel="file-gistfile1-cs-L2">2</span>
          <span class="line-number" id="file-gistfile1-cs-L3" rel="file-gistfile1-cs-L3">3</span>
          <span class="line-number" id="file-gistfile1-cs-L4" rel="file-gistfile1-cs-L4">4</span>
          <span class="line-number" id="file-gistfile1-cs-L5" rel="file-gistfile1-cs-L5">5</span>
          <span class="line-number" id="file-gistfile1-cs-L6" rel="file-gistfile1-cs-L6">6</span>
          <span class="line-number" id="file-gistfile1-cs-L7" rel="file-gistfile1-cs-L7">7</span>
          <span class="line-number" id="file-gistfile1-cs-L8" rel="file-gistfile1-cs-L8">8</span>
          <span class="line-number" id="file-gistfile1-cs-L9" rel="file-gistfile1-cs-L9">9</span>
          <span class="line-number" id="file-gistfile1-cs-L10" rel="file-gistfile1-cs-L10">10</span>
          <span class="line-number" id="file-gistfile1-cs-L11" rel="file-gistfile1-cs-L11">11</span>
          <span class="line-number" id="file-gistfile1-cs-L12" rel="file-gistfile1-cs-L12">12</span>
          <span class="line-number" id="file-gistfile1-cs-L13" rel="file-gistfile1-cs-L13">13</span>
          <span class="line-number" id="file-gistfile1-cs-L14" rel="file-gistfile1-cs-L14">14</span>
          <span class="line-number" id="file-gistfile1-cs-L15" rel="file-gistfile1-cs-L15">15</span>
          <span class="line-number" id="file-gistfile1-cs-L16" rel="file-gistfile1-cs-L16">16</span>
          <span class="line-number" id="file-gistfile1-cs-L17" rel="file-gistfile1-cs-L17">17</span>
          <span class="line-number" id="file-gistfile1-cs-L18" rel="file-gistfile1-cs-L18">18</span>
          <span class="line-number" id="file-gistfile1-cs-L19" rel="file-gistfile1-cs-L19">19</span>
          <span class="line-number" id="file-gistfile1-cs-L20" rel="file-gistfile1-cs-L20">20</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-cs-LC1"><span class="c1">// &lt;Name&gt;Avoid making complex methods even more complex (Source CC)&lt;/Name&gt;</span></div><div class="line" id="file-gistfile1-cs-LC2"><span class="c1">// To visualize changes in code, right-click a matched method and select:</span></div><div class="line" id="file-gistfile1-cs-LC3"><span class="c1">//  - Compare older and newer versions of source file</span></div><div class="line" id="file-gistfile1-cs-LC4"><span class="c1">//  - Compare older and newer versions disassembled with Reflector</span></div><div class="line" id="file-gistfile1-cs-LC5"> </div><div class="line" id="file-gistfile1-cs-LC6"><span class="n">warnif</span> <span class="n">count</span> <span class="p">&gt;</span> <span class="m">0</span> </div><div class="line" id="file-gistfile1-cs-LC7"><span class="k">from</span> <span class="n">m</span> <span class="k">in</span> <span class="n">JustMyCode</span><span class="p">.</span><span class="n">Methods</span> <span class="k">where</span></div><div class="line" id="file-gistfile1-cs-LC8"> <span class="p">!</span><span class="n">m</span><span class="p">.</span><span class="n">IsAbstract</span> <span class="p">&amp;&amp;</span></div><div class="line" id="file-gistfile1-cs-LC9">  <span class="n">context</span><span class="p">.</span><span class="n">CompareContext</span><span class="p">.</span><span class="n">IsPresentInBothBuilds</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> <span class="p">&amp;&amp;</span></div><div class="line" id="file-gistfile1-cs-LC10">  <span class="n">context</span><span class="p">.</span><span class="n">CompareContext</span><span class="p">.</span><span class="n">CodeWasChanged</span><span class="p">(</span><span class="n">m</span><span class="p">)</span></div><div class="line" id="file-gistfile1-cs-LC11"> </div><div class="line" id="file-gistfile1-cs-LC12"><span class="n">let</span> <span class="n">oldCC</span> <span class="p">=</span> <span class="n">context</span><span class="p">.</span><span class="n">CompareContext</span><span class="p">.</span><span class="n">OlderVersion</span><span class="p">(</span><span class="n">m</span><span class="p">).</span><span class="n">CyclomaticComplexity</span></div><div class="line" id="file-gistfile1-cs-LC13"><span class="k">where</span> <span class="n">oldCC</span> <span class="p">&gt;</span> <span class="m">6</span> <span class="p">&amp;&amp;</span> <span class="n">m</span><span class="p">.</span><span class="n">CyclomaticComplexity</span> <span class="p">&gt;</span> <span class="n">oldCC</span> </div><div class="line" id="file-gistfile1-cs-LC14"> </div><div class="line" id="file-gistfile1-cs-LC15"><span class="k">select</span> <span class="k">new</span> <span class="p">{</span> <span class="n">m</span><span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC16">    <span class="n">oldCC</span> <span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC17">    <span class="n">newCC</span> <span class="p">=</span> <span class="n">m</span><span class="p">.</span><span class="n">CyclomaticComplexity</span> <span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC18">    <span class="n">oldLoc</span> <span class="p">=</span> <span class="n">context</span><span class="p">.</span><span class="n">CompareContext</span><span class="p">.</span><span class="n">OlderVersion</span><span class="p">(</span><span class="n">m</span><span class="p">).</span><span class="n">NbLinesOfCode</span><span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC19">    <span class="n">newLoc</span> <span class="p">=</span> <span class="n">m</span><span class="p">.</span><span class="n">NbLinesOfCode</span><span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC20"><span class="p">}</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/anonymous/5003799/raw/d018dea48b5f0b9c66033df97bcc8a796fd2e506/gistfile1.cs" style="float:right">view raw</a>
          <a href="https://gist.github.com/anonymous/5003799#file-gistfile1-cs" style="float:right; margin-right:10px; color:#666;">gistfile1.cs</a>
          <a href="https://gist.github.com/anonymous/5003799">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>Thus the logic of this query could be easily integrated into our program this way:</p>
<script src="http://gist.github.com/5003895.js"></script><noscript><link rel="stylesheet" href="https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css"><div id="gist5003895" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-cs-L1" rel="file-gistfile1-cs-L1">1</span>
          <span class="line-number" id="file-gistfile1-cs-L2" rel="file-gistfile1-cs-L2">2</span>
          <span class="line-number" id="file-gistfile1-cs-L3" rel="file-gistfile1-cs-L3">3</span>
          <span class="line-number" id="file-gistfile1-cs-L4" rel="file-gistfile1-cs-L4">4</span>
          <span class="line-number" id="file-gistfile1-cs-L5" rel="file-gistfile1-cs-L5">5</span>
          <span class="line-number" id="file-gistfile1-cs-L6" rel="file-gistfile1-cs-L6">6</span>
          <span class="line-number" id="file-gistfile1-cs-L7" rel="file-gistfile1-cs-L7">7</span>
          <span class="line-number" id="file-gistfile1-cs-L8" rel="file-gistfile1-cs-L8">8</span>
          <span class="line-number" id="file-gistfile1-cs-L9" rel="file-gistfile1-cs-L9">9</span>
          <span class="line-number" id="file-gistfile1-cs-L10" rel="file-gistfile1-cs-L10">10</span>
          <span class="line-number" id="file-gistfile1-cs-L11" rel="file-gistfile1-cs-L11">11</span>
          <span class="line-number" id="file-gistfile1-cs-L12" rel="file-gistfile1-cs-L12">12</span>
          <span class="line-number" id="file-gistfile1-cs-L13" rel="file-gistfile1-cs-L13">13</span>
          <span class="line-number" id="file-gistfile1-cs-L14" rel="file-gistfile1-cs-L14">14</span>
          <span class="line-number" id="file-gistfile1-cs-L15" rel="file-gistfile1-cs-L15">15</span>
          <span class="line-number" id="file-gistfile1-cs-L16" rel="file-gistfile1-cs-L16">16</span>
          <span class="line-number" id="file-gistfile1-cs-L17" rel="file-gistfile1-cs-L17">17</span>
          <span class="line-number" id="file-gistfile1-cs-L18" rel="file-gistfile1-cs-L18">18</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-cs-LC1">      <span class="c1">//...</span></div><div class="line" id="file-gistfile1-cs-LC2">      <span class="kt">var</span> <span class="n">compareContext</span> <span class="p">=</span> <span class="n">codeBaseNew</span><span class="p">.</span><span class="n">CreateCompareContextWithOlder</span><span class="p">(</span><span class="n">codeBaseOld</span><span class="p">);</span></div><div class="line" id="file-gistfile1-cs-LC3">      <span class="c1">//...</span></div><div class="line" id="file-gistfile1-cs-LC4">      <span class="kt">var</span> <span class="n">methodsThatBecameMoreComplex</span> <span class="p">=</span> <span class="k">from</span> <span class="n">m</span> <span class="k">in</span> <span class="n">compareContext</span><span class="p">.</span><span class="n">NewerCodeBase</span><span class="p">.</span><span class="n">Methods</span> <span class="k">where</span></div><div class="line" id="file-gistfile1-cs-LC5">       <span class="p">!</span><span class="n">m</span><span class="p">.</span><span class="n">IsAbstract</span> <span class="p">&amp;&amp;</span></div><div class="line" id="file-gistfile1-cs-LC6">        <span class="n">compareContext</span><span class="p">.</span><span class="n">IsPresentInBothBuilds</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> <span class="p">&amp;&amp;</span></div><div class="line" id="file-gistfile1-cs-LC7">        <span class="n">compareContext</span><span class="p">.</span><span class="n">CodeWasChanged</span><span class="p">(</span><span class="n">m</span><span class="p">)</span></div><div class="line" id="file-gistfile1-cs-LC8"> </div><div class="line" id="file-gistfile1-cs-LC9">      <span class="n">let</span> <span class="n">oldCC</span> <span class="p">=</span> <span class="n">compareContext</span><span class="p">.</span><span class="n">OlderVersion</span><span class="p">(</span><span class="n">m</span><span class="p">).</span><span class="n">CyclomaticComplexity</span></div><div class="line" id="file-gistfile1-cs-LC10">      <span class="k">where</span> <span class="n">oldCC</span> <span class="p">&gt;</span> <span class="m">6</span> <span class="p">&amp;&amp;</span> <span class="n">m</span><span class="p">.</span><span class="n">CyclomaticComplexity</span> <span class="p">&gt;</span> <span class="n">oldCC</span> </div><div class="line" id="file-gistfile1-cs-LC11"> </div><div class="line" id="file-gistfile1-cs-LC12">      <span class="k">select</span> <span class="k">new</span> <span class="p">{</span> <span class="n">m</span><span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC13">          <span class="n">oldCC</span> <span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC14">          <span class="n">newCC</span> <span class="p">=</span> <span class="n">m</span><span class="p">.</span><span class="n">CyclomaticComplexity</span> <span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC15">          <span class="n">oldLoc</span> <span class="p">=</span> <span class="n">compareContext</span><span class="p">.</span><span class="n">OlderVersion</span><span class="p">(</span><span class="n">m</span><span class="p">).</span><span class="n">NbLinesOfCode</span><span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC16">          <span class="n">newLoc</span> <span class="p">=</span> <span class="n">m</span><span class="p">.</span><span class="n">NbLinesOfCode</span><span class="p">,</span></div><div class="line" id="file-gistfile1-cs-LC17">      <span class="p">};</span></div><div class="line" id="file-gistfile1-cs-LC18">      <span class="c1">//...</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/anonymous/5003895/raw/945234487550c7ee7b93e2521a698bf65dfd28c9/gistfile1.cs" style="float:right">view raw</a>
          <a href="https://gist.github.com/anonymous/5003895#file-gistfile1-cs" style="float:right; margin-right:10px; color:#666;">gistfile1.cs</a>
          <a href="https://gist.github.com/anonymous/5003895">This Gist</a> brought to you by <a href="https://github.com">GitHub</a>.
        </div>
      </div>
</div>
</noscript>
<p>In the real-world, for companies that have build servers and that care for the quality of code delivered, this ability to write custom programs that can be included into the build process chain to focus on the quality of new or refactored code can certainly be a nice option.</p>
<p>But one can also see value in writing a custom-tooling program to be ran on the developer desktop. Such program could also use the special method <a href="http://www.ndepend.com/API/webframe.html?NDepend.API~NDepend.CodeModel.ExtensionMethodsTooling~TryCompareSourceWith.html" target="_blank">TryCompareSourceWith()</a> that can open a source file diff tool on the right location of two versions of the same source file (the source file diff tool is the one configured in <em>NDepend &gt; Tools &gt; Options &gt; Source Files Compare Tool</em>). For example the open-source <em>PowerTool</em> <strong>Code Review Methods Changed</strong> uses this <em>TryCompareSourceWith()</em> method to show diff in code during a code review session. Certainly a more sophisticated program could help reviewing code diff, for example with the ability to assign some users to approve some diff, and persist in a DB such approval or disapproval actions.</p>
<p>Enjoy!</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/_nr3Ozre_bc" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/patricksmacchia/2013/02/21/a-program-to-explore-code-diff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
            <media:content url="http://www.gravatar.com/avatar/aff180ba8312104219eb0c2529aa131e?s=96&amp;d=http%3A%2F%2Fwww.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&amp;r=G" medium="image">
            <media:title type="html">Patrick Smacchia</media:title>
        </media:content>
    		<feedburner:origLink>http://codebetter.com/patricksmacchia/2013/02/21/a-program-to-explore-code-diff/</feedburner:origLink></item>
</channel>
</rss><!-- 170 queries 6.269 seconds. -->
