<?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>Fri, 17 May 2013 14:04:45 +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>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 this 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 this 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.  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.</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 motive 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 country, 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 a new 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 programmers has the potential to create its own ISV business and become a millionaire. A programmer can also decide to make more money by coding for the financial industry, or even bet on a startup and potential 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="http://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="http://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 title="Screen Shot 2013-03-31 at 8.21.37 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 8.21.37 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.21.37PM_thumb.png" width="457" height="247"></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 title="Screen Shot 2013-03-31 at 8.29.21 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 8.29.21 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.29.21PM_thumb.png" width="455" height="331"></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="http://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, when I see the following:</p>
<p><a href="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.34.14PM.png"><img title="Screen Shot 2013-03-31 at 8.34.14 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 8.34.14 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.34.14PM_thumb.png" width="468" height="253"></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 title="Screen Shot 2013-03-31 at 8.37.58 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 8.37.58 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.37.58PM_thumb.png" width="484" height="230"></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 title="Screen Shot 2013-03-31 at 8.40.42 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 8.40.42 PM" src="http://codebetter.com/glennblock/files/2013/04/ScreenShot20130331at8.40.42PM_thumb.png" width="488" height="256"></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="http://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="http://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="http://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="http://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="http://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="http://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="http://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="http://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="http://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>
	<item>
		<title>Projections 4: Event Matching</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/beWB7eLQLnQ/</link>
		<comments>http://codebetter.com/gregyoung/2013/02/18/projections-4-event-matching/#comments</comments>
		<pubDate>Mon, 18 Feb 2013 00:36:09 +0000</pubDate>
		<dc:creator>gregyoung</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/gregyoung/?p=381]]></guid>
		<description><![CDATA[In the &#8220;intermission&#8221; post we jumped ahead quite a bit in terms of the complexity of the projection we were building. Let&#8217;s jump back into our progression of learning bits. The projections we have used so far have used a&#160;&#8230; <a href="http://codebetter.com/gregyoung/2013/02/18/projections-4-event-matching/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>In the <a href="http://geteventstore.com/blog/20130217/projections-intermission/">&#8220;intermission&#8221; post</a> we jumped ahead quite a bit in terms of the complexity of the projection we were building. Let&#8217;s jump back into our progression of learning bits.</p>
<p>The projections we have used so far have used a method called when(). This method allows you to match functions back to types of events. Up until now that has been a single match but you can also use more than one.</p>
<pre class="brush: jscript; title: ; notranslate" title="">
fromStream('test').when({
                           Event1: f1,
                           Event2: f2
                        });
</pre>
<p>This defines that every time an event of type Event1 is seen the function f1 should be called with that event and function f2 for events of type Event2. This is a very useful construct when trying to build out projections that require the ability to handle many different types of events.</p>
<p>There are also some special matches defined.</p>
<p>$any: $any will match all events to your function. This is useful for example when you want to build an index for all events. We will get into how this works later but you can imagine if I wanted to build an index based upon the user that created the event (stream per user) then the function would want to look at all events in the system.</p>
<p><em>It is important to remember that as of now $any cannot be under in conjunction with other filters.</em></p>
<p>$init: $init gets called before any other handler. The job of $init is to return the initial state that will be passed to the rest of your functions. In the intermission post this handler was used to set up initial state so the other handlers did not have to. The usage can also be seen in looking at the post from the <a href="http://geteventstore.com/blog/20130215/projections-3-using-state/">Projections 3</a></p>
<pre class="brush: jscript; title: ; notranslate" title="">
fromStream('$stats-127.0.0.1:2113').
    when({
        &quot;$stats-collected&quot; : function(s,e) {
              var currentCpu = e.body[&quot;sys-cpu&quot;];
              if(currentCpu &gt; 40) {
                   if(!s.count) s.count = 0;
                   s.count += 1;
                   if(s.count &gt;= 3)
                        emit(&quot;heavycpu&quot;, &quot;heavyCpuFound&quot;, {&quot;level&quot; : currentCpu,
                                                           &quot;count&quot; : s.count});
              }
              else
                   s.count = 0;
         }
    });
</pre>
<p>In this projection the line if(!s.count) s.count = 0 is being used to initialize the state if its the first time into the function. This could also be implemented as</p>
<pre class="brush: jscript; title: ; notranslate" title="">
fromStream('$stats-127.0.0.1:2113').
    when({
        &quot;$init&quot; : function(s,e) { return {&quot;count&quot;:0},
        &quot;$stats-collected&quot; : function(s,e) {
              var currentCpu = e.body[&quot;sys-cpu&quot;];
              if(currentCpu &gt; 40) {
                   s.count += 1;
                   if(s.count &gt;= 3)
                        emit(&quot;heavycpu&quot;, &quot;heavyCpuFound&quot;, {&quot;level&quot; : currentCpu,
                                                           &quot;count&quot; : s.count});
              }
              else
                   s.count = 0;
         }
    });
</pre>
<p>The two will work in the same way. In our next post we will start looking at how indexing works in the event store.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/beWB7eLQLnQ" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/gregyoung/2013/02/18/projections-4-event-matching/feed/</wfw:commentRss>
		<slash:comments>2</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/02/18/projections-4-event-matching/</feedburner:origLink></item>
	<item>
		<title>Spring-&gt;Summer</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/rkxX4_KebDk/</link>
		<comments>http://codebetter.com/gregyoung/2013/02/18/spring-summer/#comments</comments>
		<pubDate>Mon, 18 Feb 2013 00:11:00 +0000</pubDate>
		<dc:creator>gregyoung</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/gregyoung/?p=378]]></guid>
		<description><![CDATA[Wow it feels weird to have a schedule that is pretty much completely locked in between now and August. I guess things change when you don&#8217;t only have your own schedule to worry about. A friend tells me that soon&#160;&#8230; <a href="http://codebetter.com/gregyoung/2013/02/18/spring-summer/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Wow it feels weird to have a schedule that is pretty much completely locked in between now and August. I guess things change when you don&#8217;t only have your own schedule to worry about. A friend tells me that soon I will be planning nine months in advance.</p>
<p>I have updated from now through the summer most of my schedule on the <a href="http://goodenoughsoftware.net/where-am-i/">&#8220;where am I page&#8221;</a>. I have not included everything but most is up there. </p>
<p>One big change we made is that we are going to spend a month in Australia. She seems to have this crazy idea of driving through the outback with kangaroos jumping everywhere (might be the movie!). While there I will stop in <a href="http://sydmessaging.eventbrite.com/">Sydney</a> to teach the new class and Perth to go through the <a href="http://perthcqrs.eventbrite.com/">CQRS + ES class</a>.</p>
<p>But the next six months looks pretty crazy! Hopefully we can make the best of it.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/rkxX4_KebDk" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/gregyoung/2013/02/18/spring-summer/feed/</wfw:commentRss>
		<slash:comments>2</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/02/18/spring-summer/</feedburner:origLink></item>
	<item>
		<title>Projections 3: Using State</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/irnNYmihBHA/</link>
		<comments>http://codebetter.com/gregyoung/2013/02/15/projections-3-using-state/#comments</comments>
		<pubDate>Fri, 15 Feb 2013 08:52:27 +0000</pubDate>
		<dc:creator>gregyoung</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/gregyoung/?p=375]]></guid>
		<description><![CDATA[In Projections 2 we looked at creating a very simple projection that would analyze our statistics inside of the Event Store. The projection was: This is a very common type of scenario we will find in event based systems. We&#160;&#8230; <a href="http://codebetter.com/gregyoung/2013/02/15/projections-3-using-state/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>In <a href="http://geteventstore.com/blog/20130213/projections-2-a-simple-sep-projection/">Projections 2</a> we looked at creating a very simple projection that would analyze our statistics inside of the Event Store. The projection was:</p>
<pre class="brush: jscript; title: ; notranslate" title="">

fromStream('$stats-127.0.0.1:2113').
    when({
        &quot;$stats-collected&quot; : function(s,e) {
              var currentCpu = e.body[&quot;sys-cpu&quot;];
              if(currentCpu &gt; 40) {
                   emit(&quot;heavycpu&quot;, &quot;heavyCpuFound&quot;, {&quot;level&quot; : currentCpu})
              }
         }
    });

</pre>
<p>This is a very common type of scenario we will find in event based systems. We can describe this as</p>
<p>&#8220;When this event happens and this information is on the event, trigger a new event to a different stream.&#8221;</p>
<p>Very often however its not just one event that will cause something to trigger. This is why the state variable exists. Very often we want to handle a question that is more akin to:</p>
<p>&#8220;When this event happens, then this event happens, then this event happens trigger an event to a different stream&#8221;.</p>
<p>Let&#8217;s try to change our problem from Projections 2 into one like this. I am only interested in highcpu scenarios where the cpu is over 40% for more that 3 samplings in a row. A single one could just be a fluke that happened. In order to do this type of query we will have to use our state variable to tie together multiple function calls.</p>
<pre class="brush: jscript; title: ; notranslate" title="">

fromStream('$stats-127.0.0.1:2113').
    when({
        &quot;$stats-collected&quot; : function(s,e) {
              var currentCpu = e.body[&quot;sys-cpu&quot;];
              if(currentCpu &gt; 40) {
                   if(!s.count) s.count = 0;
                   s.count += 1;
                   if(s.count &gt;= 3)
                        emit(&quot;heavycpu&quot;, &quot;heavyCpuFound&quot;, {&quot;level&quot; : currentCpu,
                                                           &quot;count&quot; : s.count});
              }
              else
                   s.count = 0;
         }
    });
</pre>
<p>Note: if you are trying this at home you may want to change how often statistics are sampled. You can set this with &#8211;stats-period-sec=SECONDS.</p>
<p>Now we use our state that gets passed from call to call to correlate multiple events together. If we get three or more samples with a CPU usage greater than 40% in a row then we will produce a message to the heavycpu stream that looks like:</p>
<pre class="brush: jscript; title: ; notranslate" title="">
{
  &quot;eventStreamId&quot;: &quot;heavycpu&quot;,
  &quot;eventNumber&quot;: 3,
  &quot;eventType&quot;: &quot;heavyCpuFound&quot;,
  &quot;data&quot;: {
    &quot;level&quot;: 41.896265,
    &quot;count&quot;: 6
  },
  &quot;metadata&quot;: {
    &quot;streams&quot;: {
      &quot;$stats-127.0.0.1:2113&quot;: 8
    }
  }
}
</pre>
<p>This is a very powerful paradigm as the state variable allows me to bring state from one call to the next allowing me to correlate multiple events together. Another example of this might be I am looking for users in twitter that said the word &#8220;coffee&#8221; and &#8220;happy&#8221; within 5 minutes of mentioning &#8220;starbucks&#8221;. This query would be implemented in the same one as the one we just tried.</p>
<p>As food for thought. Could I now write another projection off of &#8220;heavycpu&#8221; that then looked for items with 5 measurements&gt;80 and counts &gt;10? You wouldn&#8217;t probably do this in practice as you could put that logic in the first projection but you can compose projections as well!</p>
<p>In our next post we will look at having multiple types of events.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/irnNYmihBHA" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/gregyoung/2013/02/15/projections-3-using-state/feed/</wfw:commentRss>
		<slash:comments>3</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/02/15/projections-3-using-state/</feedburner:origLink></item>
	<item>
		<title>Windows 8: Be a good sharing citizen</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/4-8KrKkN5VY/</link>
		<comments>http://codebetter.com/johnvpetersen/2013/02/13/windows-8-be-a-good-sharing-citizen/#comments</comments>
		<pubDate>Wed, 13 Feb 2013 18:44:35 +0000</pubDate>
		<dc:creator>johnvpetersen</dc:creator>
				<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WinJS]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/johnvpetersen/?p=553]]></guid>
		<description><![CDATA[Note: Code samples are WinJS I&#8217;ve been working with Windows 8 and building Windows Store Apps more and more. Building native Windows Apps with HTML/JS/CSS is, in a word, awesome. I&#8217;ve mentioned before how the OS is a first class&#160;&#8230; <a href="http://codebetter.com/johnvpetersen/2013/02/13/windows-8-be-a-good-sharing-citizen/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Note: Code samples are WinJS</p>
<p>I&#8217;ve been working with Windows 8 and building Windows Store Apps more and more. Building native Windows Apps with HTML/JS/CSS is, in a word, awesome. I&#8217;ve mentioned before how the OS is a first class citizen in the development space. Having standard API&#8217;s in the dev environment to handle common tasks like searching and sharing is another nice feature in Windows 8 Development. I wanted to take a quick moment to talk about the sharing contract. You can download a full working example of how to implement the sharing contract <a href="http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Target-App-e2689782" target="_blank">here</a>.</p>
<p>This example does a great job of dealing with situations where you can and want to share. But what about times when sharing is not appropriate? A good user experience means the user not having to guess as to whether encountered functionality is intended or a bug. By default, when the share contract is not implemented you get a pretty blunt message back: &#8220;This app can&#8217;t share.&#8221;</p>
<p><a href="http://codebetter.com/johnvpetersen/files/2013/02/cantShare.png"><img class="alignleft size-full wp-image-554" alt="cantShare" src="http://codebetter.com/johnvpetersen/files/2013/02/cantShare.png" width="343" height="176" /></a></p>
<p>Looks pretty, but it&#8217;s not all that informative.  Fortunately, it&#8217;s very simple to provide your users with enough information so they know what they see is what you, as the app developer intended. The following code is a basic and typical share contract data request function:</p>
<pre class="brush: jscript; title: ; notranslate" title="">
  function dataRequested(e) {
        var request = e.request;

        // Title is required
        var dataPackageTitle = document.querySelector(&quot;article .item-title&quot;).textContent
        if ((typeof dataPackageTitle === &quot;string&quot;) &amp;&amp; (dataPackageTitle !== &quot;&quot;)) {
            var dataPackageText = document.querySelector(&quot;article .item-content&quot;).innerHTML
            if ((typeof dataPackageText === &quot;string&quot;) &amp;&amp; (dataPackageText !== &quot;&quot;)) {
                request.data.properties.title = dataPackageTitle;
                request.data.setText(dataPackageText);
            } else {
                request.failWithDisplayText(&quot;A problem occurred with this sharing request&quot;);
            }
        } else {
            request.failWithDisplayText(&quot;A problem occurred with this sharing request&quot;);
        }
    }
</pre>
<p>This still doesn&#8217;t do everything we need. For example, using the Grid Template as an example, this code would only work on the item detail page. If you happen to invoke the Share Contract from the Group Items or Group Details page, you will either get an error or the necessary data won&#8217;t be found. In most cases, it&#8217;s an individual item you are looking to share.  With that in mind, consider adding code like this to your common share data request function:</p>
<pre class="brush: jscript; title: ; notranslate" title="">
if (WinJS.Navigation.history.current.location != &quot;/pages/itemDetail/itemDetail.html&quot;) {
   request.failWithDisplayText(&quot;Please note, you must navigate to an individual item in order to share.&quot;);
   return;
}
</pre>
<p>Now, when the user wants to share something in a context that does not account for that functionality, the user will know two things:<br />
1. It&#8217;s not intended to be used in this context and;<br />
2. The user knows where the sharing context is</p>
<p>This yields much better results:</p>
<p><a href="http://codebetter.com/johnvpetersen/files/2013/02/cantShareGridDemo.gif"><img class="alignleft size-full wp-image-556" alt="cantShareGridDemo" src="http://codebetter.com/johnvpetersen/files/2013/02/cantShareGridDemo.gif" /></a></p>
<p><a href="http://codebetter.com/johnvpetersen/files/2013/02/canShareItem.gif"><img class="alignleft size-full wp-image-559" alt="canShareItem" src="http://codebetter.com/johnvpetersen/files/2013/02/canShareItem.gif" /></a></p>
<p><a href="http://codebetter.com/johnvpetersen/files/2013/02/canShareItem2.gif"><img class="alignleft size-full wp-image-558" alt="canShareItem2" src="http://codebetter.com/johnvpetersen/files/2013/02/canShareItem2.gif" /></a></p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/4-8KrKkN5VY" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/johnvpetersen/2013/02/13/windows-8-be-a-good-sharing-citizen/feed/</wfw:commentRss>
		<slash:comments>2</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/02/13/windows-8-be-a-good-sharing-citizen/</feedburner:origLink></item>
	<item>
		<title>Projections 2: A Simple SEP Projection</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/3mOGMOis0sU/</link>
		<comments>http://codebetter.com/gregyoung/2013/02/13/projections-2-a-simple-sep-projection/#comments</comments>
		<pubDate>Wed, 13 Feb 2013 14:19:14 +0000</pubDate>
		<dc:creator>gregyoung</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/gregyoung/?p=372]]></guid>
		<description><![CDATA[In the first post on projections we talked a bit about the theory behind projections. In this post we are going to try to create a very simple projection and talk about how it actually works. To start with there&#160;&#8230; <a href="http://codebetter.com/gregyoung/2013/02/13/projections-2-a-simple-sep-projection/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>In the <a href="http://goodenoughsoftware.net/2013/02/12/projections-1-the-theory/">first post on projections</a> we talked a bit about the theory behind projections. In this post we are going to try to create a very simple projection and talk about how it actually works.</p>
<p>To start with there is a very special stream inside of the event store. This stream represents statistics measurements that are happening internally. You can control how often they are taken via config. To find this stream in your system you can assuming you are bringing up a brand new node look at the &#8220;streams&#8221; tab when going to whatever port you set for http.</p>
<p><em>Hint: as projections are experimental as of the last release you need to enable them on the command line or in configuration when bringing up the Event Store. The command line is &#8211;run-projections.</em></p>
<p>For me (the default) stream for statistics is $stats-127.0.0.1:2113. If you want to see statistics data you can point your browser to 127.0.0.1:2113/streams/$stats-127.0.0.1:2113 and view the data in the stream. You should see something that looks like this:</p>
<p>&nbsp;</p>
<p style="text-align:center"><a href="http://gregfyoung.files.wordpress.com/2013/02/streamviewed.png"><img class="size-medium wp-image-493 aligncenter" alt="streamviewed" src="http://gregfyoung.files.wordpress.com/2013/02/streamviewed.png?w=300" width="300" height="114" /></a></p>
<p style="text-align:center">
<p>If you click on one of the events you should be able to see the actual data from a statistics event entry. If you want to save some time you can see it <a href="https://gist.github.com/gregoryyoung/4944753">on my gist</a>. This is a json encoding of what the statistics measurement looks like. We are going to write a basic projection against that stream.</p>
<pre class="brush: jscript; title: ; notranslate" title="">

fromStream('$stats-127.0.0.1:2113').
    when({
        &quot;$stats-collected&quot; : function(s,e) {
              var currentCpu = e.body[&quot;sys-cpu&quot;];
              if(currentCpu &gt; 40) {
                   emit(&quot;heavycpu&quot;, &quot;heavyCpuFound&quot;, {&quot;level&quot; : currentCpu})
              }
         }
    });

</pre>
<p><em>If you want to test this projection. Go to new projection and paste it in. Give it a name and select &#8220;emit enabled&#8221; and for mode put &#8220;continuous&#8221;. We will discuss in a later post what these things mean. The UI around this is currently being changed as well, we see its not the most intuitive.</em></p>
<p>This is a very simple projection. Its not very interesting. We will get to doing more interesting ones shortly. What it does is it listens to your statistics stream. This is setup when it says &#8220;fromStream&#8221; this is says &#8220;listen to all events in stream s&#8221;. It then defines a function that will be passed all $stats-collected events which happen to be the ones we saw in the statistics stream above.</p>
<p>The function declared checks the &#8220;sys-cpu&#8221; field of the event. If the cpu is higher than 40% it emits a new event out to another stream called &#8220;heavycpu&#8221;. If you are running the projection you can bring up your CPU usage then try navigating to the stream 127.0.0.1:2113/streams/heavycpu. You will see an event there of the form.</p>
<pre class="brush: jscript; title: ; notranslate" title="">
EventStreamId: heavycpu, EventNumber: 2, EventType: heavyCpuFound, Data: {
  &quot;level&quot;: 40.9823952
}, Metadata: {
  &quot;streams&quot;: {
    &quot;$stats-127.0.0.1:2113&quot;: 49
  }
}
</pre>
<p>This is a very basic projection that is emitting a new event based on some criteria that is found. This is a very common pattern in event based systems (SEP). In the next post we will introduce state into our projection to look at how we can alert not just off a single event but off some group of events that are correlated which is another very common pattern in projections (CEP).</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/3mOGMOis0sU" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/gregyoung/2013/02/13/projections-2-a-simple-sep-projection/feed/</wfw:commentRss>
		<slash:comments>1</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/02/13/projections-2-a-simple-sep-projection/</feedburner:origLink></item>
	<item>
		<title>Projections 1: The Theory</title>
		<link>http://feedproxy.google.com/~r/CodeBetter/~3/-xYh08PuFHo/</link>
		<comments>http://codebetter.com/gregyoung/2013/02/13/projections-1-the-theory/#comments</comments>
		<pubDate>Wed, 13 Feb 2013 10:31:54 +0000</pubDate>
		<dc:creator>gregyoung</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
        
		<guid isPermaLink="false"><![CDATA[http://codebetter.com/gregyoung/?p=365]]></guid>
		<description><![CDATA[Cross Posted from geteventstore.com/blog Over at http://geteventstore we have 1.0&#8242;ed the Event Store as an Event Store (eg storing/retreiving events/multinode version/etc) but in the process we did not release projections. They are still marked as experimental. Projections are however getting close to ready&#160;&#8230; <a href="http://codebetter.com/gregyoung/2013/02/13/projections-1-the-theory/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
		<content:encoded><![CDATA[<p>Cross Posted from <a href="geteventstore.com/blog">geteventstore.com/blog</a></p>
<p>Over at <a href="http://geteventstore">http://geteventstore</a> we have 1.0&#8242;ed the Event Store as an Event Store (eg storing/retreiving events/multinode version/etc) but in the process we did not release projections. They are still marked as experimental. Projections are however getting close to ready so its time to write a bit about them as the official documentation takes shape.</p>
<p>Through the series we will get fairly deep into their usage but for many the best way to understand them to understand the underlying theory so let&#8217;s start there.</p>
<h2>Functions</h2>
<p>When we talk about a projection off of an event stream basically what we are describing is running a series of functions over the stream. We could as our simplest possible projection have a projection that runs through all of the events in the system (in order) passing current state from one function to the next. The simplest of these could be to count how many events there are.</p>
<p>var count = function(state, event) {<br />
return state + 1;<br />
}</p>
<p>Then to run it across all of the events (let&#8217;s imagine we had three) in our system we would end up with a pattern like:</p>
<p>var result = count(count(count(count, 0), event1), event2), event3)</p>
<p>This operation is known in the functional world as a <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">higher order function -&gt; left-fold</a>. It is a very powerful construct that is useful in solving many problems. When we talk about Event Sourcing, current state is a left-fold of previous beahviours.</p>
<p>Projections at their heart allow for the specializing of a generalized function. Their underlying model is that of a left-fold. Looking at the above left fold there are a couple of pieces that we could possibly change. The generic version of this function would look something like:</p>
<p><code>var result = transform(f(f(f(initial()), e), e), e)</code></p>
<p>Let&#8217;s discuss briefly what the three main parts of this function are.</p>
<p>f(state, event) =&gt; state &#8211; is the function that is run over the series of events.</p>
<p>transform(state) =&gt; result &#8211; is a function that can transform the state to the form of result you want to receive</p>
<p>initial() =&gt; state &#8211; returns the initial state you want passed into your left-fold.</p>
<p>Taking one example (don&#8217;t worry we will go through more in later posts!): f(state, event) =&gt; state &#8211; gets specialized through a pattern match:</p>
<p><code>var f1 = function(state,event) {}</code></p>
<p>when({<br />
$any : f //runs for all<br />
})</p>
<p>or<br />
<code><br />
var f1 = function(state,event) {}<br />
</code>var f2 = function(state,event) {}</p>
<p>when({<br />
Something : f1, //match all Something<br />
SomethingElse f2: //match all SomethingElse<br />
}<em id="__mceDel">)</em></p>
<p>To see the differences between the two, let&#8217;s imagine that we had a stream of events.</p>
<p>Something<br />
SomethingElse<br />
Something</p>
<p>The first would call as:</p>
<p>f1(f1(f1(nil, Something), SomethingElse),Something)</p>
<p>The second would call as</p>
<p>f1(f2(f1(nil, Something), SomethingElse),Something)</p>
<p>If we were to change the stream to:</p>
<p>Something<br />
SomethingElse<br />
SomethingElse</p>
<p>The second would end up as</p>
<p>f2(f2(f1(nil, Something), SomethingElse),SomethingElse)</p>
<p>Again don&#8217;t worry too much about the details. We will have a whole post on &#8220;when&#8221; and pattern matching</p>
<h3>Event Selection</h3>
<p>The second part of how projections work theoretically is the controlling of which events get passed to which definition. In our first example we passed all events in the system through a single left-fold. While many projections due in fact work exactly this way many are only interested in certain events not all events in the entire event store.</p>
<p>fromAll() would read all of the events in the entire event store. fromStream(&#8216;stream&#8217;) tells projections to take whatever definition you have and run it against only the events within the stream &#8216;stream&#8217;. Where as fromStreams(&#8216;s1&#8242;, &#8216;s2&#8242;, &#8216;s3&#8242;) joins the events from three streams and then runs the left-fold of the resulting stream.</p>
<p>Don&#8217;t worry if you don&#8217;t completely &#8220;get&#8221; projections after this post, there is a lot to them and we will be delving into a lot more detail and use cases of them. Overall however projections have a relatively simple underlying theory associated with them. Hopefully by understanding the underlying theory it will make the rest of the posts in the series easier to understand.</p>
<img src="http://feeds.feedburner.com/~r/CodeBetter/~4/-xYh08PuFHo" height="1" width="1"/>]]></content:encoded>
		<wfw:commentRss>http://codebetter.com/gregyoung/2013/02/13/projections-1-the-theory/feed/</wfw:commentRss>
		<slash:comments>1</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/02/13/projections-1-the-theory/</feedburner:origLink></item>
</channel>
</rss><!-- 167 queries 6.347 seconds. -->
