<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>carlfurrow.com</title>
	<atom:link href="http://carlfurrow.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://carlfurrow.com</link>
	<description></description>
	<lastBuildDate>Wed, 27 Jan 2010 21:39:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascript HTML Templating: EJS vs JAML</title>
		<link>http://carlfurrow.com/2010/01/javascript-html-templating-ejs-vs-jaml/</link>
		<comments>http://carlfurrow.com/2010/01/javascript-html-templating-ejs-vs-jaml/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 18:48:09 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/?p=132</guid>
		<description><![CDATA[Now that I&#8217;ve played around with EJS for a while, I can say I&#8217;m fairly comfortable with it, and love the syntax. It just makes sense to me. But recently, I came across another templating framework, called JAML, or HAML for Javascript (GitHub Page), and it addresses one of my main concerns with EJS. I&#8217;ll get [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Now that I&#8217;ve played around with <a href="http://embeddedjs.com">EJS</a> for a while, I can say I&#8217;m fairly comfortable with it, and love the syntax. It just makes sense to me. But recently, I came across another templating framework, called <a href="http://edspencer.net/2009/11/jaml-beautiful-html-generation-for-javascript.html">JAML</a>, or <a href="http://haml-lang.com/">HAML</a> for Javascript (<a href="http://github.com/edspencer/jaml">GitHub Page</a>), and it addresses one of my main concerns with EJS. I&#8217;ll get to what that was in a little bit. First, let&#8217;s look at some JAML syntax:</p>
<div id="attachment_148" class="wp-caption alignnone" style="width: 282px">
	<a href="http://carlfurrow.com/wp-content/uploads/2010/01/2010-01-27_1626.png"><img class="size-full wp-image-148" title="JAML Syntax" src="http://carlfurrow.com/wp-content/uploads/2010/01/2010-01-27_1626.png" alt="JAML Syntax" width="282" height="225" /></a>
	<p class="wp-caption-text">Example of JAML syntax</p>
</div>
<p><span id="more-132"></span>Pretty nice, eh? And it&#8217;s still easily tucked-away separate from your functional Javascript code. You could create a JS file for each template object, i.e. &#8220;Products.jaml.js&#8221;, &#8220;Orders.jaml.js&#8221;, etc, then include them on the page before you require the rendered output/HTML in your functional code.</p>
<p>One of the problems I was running into with EJS was that I needed to make sure the paths to my .ejs files were always correct, regardless of the page the user was looking at. So I had to create absolute URL references to the EJS file via directly, &#8220;/somepath/someotherpath/products.ejs&#8221;. And that&#8217;s fine, but I had more than a few issues while debugging since my production environment was at http://somesite.com and my local site was at http://localhost/myproject/. So when my code asked for &#8220;/somepath/someotherpath/product.ejs&#8221; it would work fine in production, but it would fail in JS. I came up with ways to use a variable that would get me to the right path, so it&#8217;s wasn&#8217;t insurmountable, but it was something to keep in mind.  Obviously, JAML fixes that by keeping your templates as regular Javascript that can be put into .js files and included in regular &lt;script/&gt; blocks. Nice.</p>
<p>Now let&#8217;s do the same comparison I did for <a href="http://carlfurrow.com/2010/01/javascript-html-templating-ejs-vs-jquery/#example">jQuery vs EJS</a>. First we start off with a products array.</p>
<pre class="brush: js">
var products = [
{
id:0,
desc:&quot;product 0&quot;,
price: 10.50
},
{
id:1,
desc:&quot;product 1&quot;,
price: 1.25
},
{
id:2,
desc:&quot;product 2&quot;,
price: 5.60
}
];
</pre>
<p>And since you&#8217;ve already seen what EJS looks like, here&#8217;s the JAML syntax:</p>
<pre class="brush: js">
Jaml.register(&#039;product&#039;,function(pProduct){
li({cls:&quot;product&quot;},
a({href:&quot;/product/&quot;+pProduct.id},&quot;product &quot;+pProduct.id+&quot; ($&quot;+pProduct.price+&quot;)&quot;)
);
});

Jaml.register(&#039;products&#039;,function(pProducts){
ul({cls:&#039;products&#039;},Jaml.render(&#039;product&#039;,pProducts.products));
});
</pre>
<p>You&#8217;ll notice that I had to do this in a two-step process (i.e. two calls to the register() method). This is a limitation of how the collections/partials process works. I created a template for what an individual product looks like, then I created a template to how a collection of products works; inside of a UL tag, with a product partial for each product object inside of pProducts.products. Not too bad, but it&#8217;s a little more work vs EJS, but, if you think about it in the &#8220;partials&#8221; methodology, it&#8217;s not a bad mental-leap.</p>
<p>And the output is as it should be:</p>
<pre class="brush: html">
&lt;ul class=&quot;products&quot;&gt;&lt;li class=&quot;product&quot;&gt;
  &lt;a href=&quot;/product/0&quot;&gt;product 0 ($10.5)&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;product&quot;&gt;
  &lt;a href=&quot;/product/1&quot;&gt;product 1 ($1.25)&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;product&quot;&gt;
  &lt;a href=&quot;/product/2&quot;&gt;product 2 ($5.6)&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>Definitely going to have to try out JAML on some of my larger projects to see how it fairs. I imagine it&#8217;ll do very well. Thanks to Ed Spencer for this cool product!</p>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2010/01/javascript-html-templating-ejs-vs-jaml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaScript HTML Templating: EJS vs jQuery</title>
		<link>http://carlfurrow.com/2010/01/javascript-html-templating-ejs-vs-jquery/</link>
		<comments>http://carlfurrow.com/2010/01/javascript-html-templating-ejs-vs-jquery/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 13:00:38 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ejs]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/?p=102</guid>
		<description><![CDATA[Had a little time to kill between tasks a few weeks ago, and Googled to see if I could find a solution to all these dreaded string-concatenations I was finding throughout pieces of our Javascript codebase at work. They were piecing together HTML code (in strings) and attaching objects&#8217; data into the HTML. I stumbled [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Had a little time to kill between tasks a few weeks ago, and Googled to see if I could find a solution to all these dreaded string-concatenations I was finding throughout pieces of our Javascript codebase at work. They were piecing together HTML code (in strings) and attaching objects&#8217; data into the HTML. I stumbled upon EJS (<a href="http://embeddedjs.com">http://embeddedjs.com</a>) and fell in love instantly!</p>
<p>It allows you to create HTML templates, with Javascript placeholders, not unlike Ruby on Rails or ASP.Net. Their main page has a great, little interactive demo. Go check it out, and come back. I&#8217;ll probably still be here.<br />
&#8230;</p>
<p><span id="more-102"></span></p>
<p>Back? Great! So now you&#8217;re probably a little excited if you haven&#8217;t seen that before. Otherwise, humor me for a bit while I stay geeked-out over this.</p>
<p>It is such a simple, and elegant solution to the problems I was griping to myself about, that I couldn&#8217;t wait to test it out for myself. And at the same time, I thought I&#8217;d write up this little post about it, comparing jQuery as a templating medium, vs EJS. Here we go.</p>
<p><a name="example"></a><br />
To start, we need some Javascript objects, so I&#8217;ve created a simple array of three simple &#8220;product&#8221; objects.</p>
<p><strong>products:</strong></p>
<pre class="brush: js">
var products = [
{
id:0,
desc:&quot;product 0&quot;,
price: 10.50
},
{
id:1,
desc:&quot;product 1&quot;,
price: 1.25
},
{
id:2,
desc:&quot;product 2&quot;,
price: 5.60
}
];
</pre>
<p>Now that I&#8217;ve got some data to work with, let&#8217;s create a list to show off the data in HTML. First, we&#8217;ll use jQuery. This example is really trivial, but it&#8217;s just an example, so I&#8217;m not going to split-hairs here. First I grab the UL that will hold the HTML once I&#8217;m through adding my product data, then for each product in my products array, I create an LI, and add some attributes/text to them.</p>
<p><strong>jQuery:</strong></p>
<pre class="brush: js">
var jquery_products = $(&quot;#jquery_products&quot;);
$.each(products,function(){
var li = $(&quot;&lt;li/&gt;&quot;).addClass(&quot;product&quot;);
var a = $(&quot;&lt;a/&gt;&quot;).appendTo(li);
a.attr(&quot;href&quot;,&quot;/product/&quot;+this.id);
a.html(this.desc + &quot; ($&quot;+this.price+&quot;)&quot;);
jquery_products.append(li);
});
</pre>
<p>Pretty simple, eh? And that will output the following HTML:</p>
<pre class="brush: html">
&lt;ul id=&quot;jquery_products&quot;&gt;
&lt;li class=&quot;product&quot;&gt;
&lt;a href=&quot;/product/0&quot;&gt;product 0 ($10.5)&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;product&quot;&gt;
&lt;a href=&quot;/product/1&quot;&gt;product 1 ($1.25)&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;product&quot;&gt;
&lt;a href=&quot;/product/2&quot;&gt;product 2 ($5.6)&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>Now, let&#8217;s see how EJS stacks up. First, I grab the UL that will hold the HTML that will be output from my EJS template, then, I create a new EJS template, pointing to my template file, product.ejs, and then render the contents using the array of products.</p>
<p><strong>EJS:</strong></p>
<pre class="brush: js">
var ejs_products = document.getElementById(&quot;ejs_products&quot;);
var html = new EJS({url: &#039;scripts/templates/product.ejs&#039;}).render(products);
ejs_products.innerHTML = html;
</pre>
<p>But we&#8217;re only half-done. We now need to define product.ejs, which is below:</p>
<p><strong>product.ejs:</strong></p>
<pre class="brush: html">

&lt;% for(var i=0; i &lt; this.length; i++) {%&gt;
&lt;!-- Get the current product, &quot;this&quot; is the products array that was passed in--&gt;
&lt;% var product = this[i]; %&gt;
&lt;li class=&quot;product&quot;&gt;
&lt;%= link_to(product.desc + &quot; ($&quot;+product.price+&quot;)&quot;, &quot;/product/&quot;+product.id) %&gt;
&lt;/li&gt;
&lt;% } %&gt;</pre>
<p>Nice and clean. And very maintainable. The output is the same as the jQuery output:</p>
<pre class="brush: html">
&lt;ul id=&quot;ejs_products&quot;&gt;
&lt;li class=&quot;product&quot;&gt;
&lt;a href=&quot;/product/0&quot;&gt;product 0 ($10.5)&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;product&quot;&gt;
&lt;a href=&quot;/product/1&quot;&gt;product 1 ($1.25)&lt;/a&gt;
&lt;/li&gt;
&lt;li class=&quot;product&quot;&gt;
&lt;a href=&quot;/product/2&quot;&gt;product 2 ($5.6)&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>I definitely will be using EJS from now on as my Javascript templating framework. jQuery works just fine, but I believe for maintainability&#8217;s sake, I will keep my HTML separate from my Javascript as much as possible. It just &#8220;feels&#8221; right.</p>
<p>The only caveat I have is that you need to make sure you&#8217;ve got the right path to your EJS template file. Since your Javascript runs on the current page, and therefore, that current page&#8217;s URL, you&#8217;ll need to make sure you&#8217;ve got the right absolute, or relative path specified to reach the EJS template file. The best thing you can probably do is either always use the absolute path, &#8220;/scripts/path_to_template_files/my_template.ejs&#8221;, or, create a javascript variable in your page somewhere that always points to the root of your website, and append your template file directory from there.</p>
<pre class="brush: javascript">
var base_url = &quot;http://mywebsite.com&quot;;
//...snip
var html = new EJS({url:base_url+&quot;/scripts/templates/my_template.ejs&quot;}).render(data);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2010/01/javascript-html-templating-ejs-vs-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Book Review: Rails for .NET Developers</title>
		<link>http://carlfurrow.com/2009/09/book-review-rails-for-net-developers/</link>
		<comments>http://carlfurrow.com/2009/09/book-review-rails-for-net-developers/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 04:00:00 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/2009/09/book-review-rails-for-net-developers/</guid>
		<description><![CDATA[I few weeks ago I picked up “Rails for .NET Developers”,by Jeff Cohen and Brian Eng, and practically read it from cover-to-cover in about a week and a half’s time. It was a very informative read, and I was looking for a jumping-off point to really get into Rails, and I figured a book supposedly [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I few weeks ago I picked up <a href="http://www.pragprog.com/titles/cerailn/rails-for-net-developers">“Rails for .NET Developers”</a>,by Jeff Cohen and Brian Eng, and practically read it from cover-to-cover in about a week and a half’s time. It was a very informative read, and I was looking for a jumping-off point to really get into Rails, and I figured a book supposedly written for “my kind” would be a great way to start.</p>
<p>After reading through the book, I realized that all I really needed was an intermediate to advanced guide for Rails, and didn’t necessarily need any correlation to .NET. The book did a fine job presenting most of what I wanted, but as a programmer I just need to learn syntax, guidelines and cool tricks and I can begin to write in any language—that’s typical for most any programmer. If I had to do it all over again, I may have chosen a different book that just focused on Rails and not one that compared it to another language in an effort to ease the transition.</p>
<p>Now that I’ve got a handle on Rails, I’ve been digging into the Ruby language, and trying to pick up more tips on that front. It was beyond the scope of the book to go into a lot of depth on Ruby, so I’m not docking it points because of that.</p>
<p><strong>The Good</strong>: Great introduction to developing Rails apps. Straightforward examples and nice side-by-side comparisons of .NET code vs the Ruby/Rails equivalent (you honestly save many lines of code going the Rails way, being that Ruby is such an opinionated language).</p>
<p><strong>The Bad</strong>: None really, just a personal critique that I should have picked up a book that was only focused on Rails.</p>
<p><strong>The Ugly</strong>: Reminders of how horrible development in .NET webforms can be. From now on, I only want to develop in MVC platforms. Clean, testable separation of concerns.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2009/09/book-review-rails-for-net-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting my feet wet with Drupal</title>
		<link>http://carlfurrow.com/2009/09/getting-my-feet-wet-with-drupal/</link>
		<comments>http://carlfurrow.com/2009/09/getting-my-feet-wet-with-drupal/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 15:19:24 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[drupal]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/2009/09/getting-my-feet-wet-with-drupal/</guid>
		<description><![CDATA[Some side projects of mine have led me down the path of getting more familiar with Drupal (http://drupal.org) and I have to say that it’s a wonderful and powerful CMS. It definitely has a lot of features that provide the convention or configuration mantra that I’m growing to love the more I use Ruby on [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Some side projects of mine have led me down the path of getting more familiar with Drupal (<a href="http://drupal.org">http://drupal.org</a>) and I have to say that it’s a wonderful and powerful CMS. It definitely has a lot of features that provide the convention or configuration mantra that I’m growing to love the more I use Ruby on Rails.</p>
<p>Theme creation from scratch was a bit of a hurdle, but I think I’m over the hardest learning curves, and it only took a few hours to pick up and run with. I was creating a menu using Drupal’s menu system, and was thinking to myself, “Ok, I’m going to have to figure out how to dig into the backend of Drupal and set some ‘active’ flags when this menu item is clicked, so I can add a nice background to visually show the user where they are in the menu.” But, to my surprise, and delight, Drupal had me covered. If the menu item points to content on the site you’re building, it automagically looks at the current URL, and matches it with the menu item, and adds an “active-trail” class to the menu item’s LI. </p>
<p>Anyway, I just wanted to say a few words, sharing my excitement for Drupal. I may post more on it as time goes on, but if you’re looking for a free CMS to try out, with an expansive community of supporters and module writers, you should really check out Drupal.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2009/09/getting-my-feet-wet-with-drupal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rolling my own blog engine, part 3</title>
		<link>http://carlfurrow.com/2009/06/rolling-my-own-blog-engine-part-3/</link>
		<comments>http://carlfurrow.com/2009/06/rolling-my-own-blog-engine-part-3/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 01:05:47 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[automapping]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[conventions]]></category>
		<category><![CDATA[fluent]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/?p=78</guid>
		<description><![CDATA[Part 1     Part 2
This post is going to go over Automapping using Fluent NHibernate with regards to my blogging engine.&#160; If you’re unfamiliar with the concept of automapping, you should browse James Gregory’s introductory post. Basically, we gained the benefit of XML-less configuration when mapping our data transfer objects (DTO) to [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://carlfurrow.com/2009/05/rolling-my-own-blog-engine-part-1/">Part 1</a>     <br /><a href="http://carlfurrow.com/2009/05/rolling-my-own-blog-engine-part-2/">Part 2</a></p>
<p>This post is going to go over Automapping using Fluent NHibernate with regards to my blogging engine.&#160; If you’re unfamiliar with the concept of automapping, you should browse <a href="http://blog.jagregory.com/2009/01/10/fluent-nhibernate-auto-mapping-introduction/">James Gregory’s introductory post</a>. Basically, we gained the benefit of XML-less configuration when mapping our data transfer objects (DTO) to database tables and columns with Fluent NHibernate over plain old NHibernate. Mapping was achieved through “mapping” classes, one per DTO, so if you had a “User” class, you’d also need a “UserMap” class that told FluentNHibernate how to map each property in your class to the column in a database table.&#160; Automapping removes the requirement of creating mapping classes and relies on conventions over configuration. Here we go.</p>
</p>
<p> <span id="more-78"></span>
</p>
<p>First off, in order to get automapping to work, you’ll need to generate an AutoPersistenceModel object that encompasses your automapping parameters.&#160; I’ll post the code and then I’ll go through it step by step.</p>
<pre name="code" class="c-sharp">public AutoPersistenceModel GetPersistenceModel()
{
    return AutoPersistenceModel.MapEntitiesFromAssemblyOf&lt;Blog&gt;()
        .WithSetup(a =&gt; a.IsBaseType = type =&gt; type == typeof (DomainEntity))
        .Where(type =&gt;
               type.Namespace.EndsWith(&quot;Domain.Model&quot;) &amp;&amp;
               !type.IsAbstract &amp;&amp;
               type.IsClass &amp;&amp;
               type.GetProperty(&quot;Id&quot;) != null)
        .ConventionDiscovery.AddFromAssemblyOf&lt;IdConvention&gt;();
}</pre>
<p>As you can see, this class has only one responsibility at the end of the day, to generate an AutoPersistenceModel.&#160; The AutoPersistenceModel class is the heart of the automapping configuration.&#160; Let’s go through it.</p>
<pre class="c-sharp" name="code">return AutoPersistenceModel.MapEntitiesFromAssemblyOf&lt;Blog&gt;()</pre>
<p>This line lets FluentNHibernate’s automapping framework know where to find the DTOs.&#160; The framework will look through the assembly and attempt to map each class to a table in the database.&#160; How does it know <em>not</em> to map a particular class, such as a base class? Read on <img src='http://carlfurrow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre name="code" class="c-sharp">.WithSetup(a =&gt; a.IsBaseType = type =&gt; type == typeof (DomainEntity))</pre>
<p>This line lets the automapping framework “know’ that DomainEntity is a base type, and not a type or class that needs to be mapped to a table in the database.</p>
<pre name="code" class="c-sharp">.Where(type =&gt;
    type.Namespace.EndsWith(&quot;Domain.Model&quot;) &amp;&amp;
    !type.IsAbstract &amp;&amp;
    type.IsClass &amp;&amp;
    type.GetProperty(&quot;Id&quot;) != null)</pre>
<p>Here’s where it gets a little more interesting.&#160; The above code is where we tell the framework exactly which classes we’d like to map to a database table.&#160; We first let it know that the class should be in the Domain.Model namespace, should <strong>not</strong> be abstract, should be a class, and that there should be a property named “Id” that should not be null.</p>
<pre name="code" class="c-sharp">.ConventionDiscovery.AddFromAssemblyOf&lt;IdConvention&gt;();</pre>
<p>A simplistic line of code, but it actually does quite a bit as we’ll soon find out.&#160; Now that we’ve told Fluent NHibernate Automapping <em>how</em> to find DTOs to map to database tables, we now would like to tell it <em>what</em> to do with them by defining some conventions.&#160; <a href="http://blog.jagregory.com/2009/03/11/fluent-nhibernate-conventions-rewrite/">See James Gregory’s quick overview to the convention framework by visiting his blog</a>.</p>
<p>To see why I have the above line of code, maybe it would make sense to see inside of my “Core” solution and its architecture/topology:</p>
<p><a href="http://carlfurrow.com/wp-content/uploads/2009/06/image.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://carlfurrow.com/wp-content/uploads/2009/06/image-thumb.png" width="332" height="386" /></a></p>
<p>I just want to focus in on the Conventions folder/namespace and go through each of those convention classes to see what is going on in each, and why they are needed.</p>
<pre name="code" class="c-sharp">public class HasManyConvention : IHasManyConvention
{
    public bool Accept(IOneToManyPart target)
    {
        return true;
    }

    public void Apply(IOneToManyPart target)
    {
        Type t = target.GetType();
        if(t == typeof(OneToManyPart&lt;Blog&gt;))
            target.KeyColumnNames.Add(&quot;OwnerId&quot;);
        if(t == typeof(OneToManyPart&lt;Post&gt;))
            target.KeyColumnNames.Add(&quot;AuthorId&quot;);
        target.Cascade.All();
    }
}</pre>
<p>This class is responsible for handling the HasMany convention, which is used for all OneToMany relationship mappings. In our case, we have a few of these mappings: </p>
<p><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://carlfurrow.com/wp-content/uploads/2009/06/image-thumb1.png" width="489" height="218" /> </p>
<ul>
<li>User <em>has many</em> Blogs (via User’s property IList&lt;Blog&gt; Blogs) </li>
<li>User <em>has many</em> Posts (via User’s property IList&lt;Post&gt; Posts) </li>
<li>Blog <em>has many</em> Posts (via Blog’s property IList&lt;Post&gt; Posts) </li>
</ul>
<p>As you can see the Accept() function simply returns true, which in turn is letting the automapping framework know to apply this convention to all classes being mapped.&#160; And what is being applied? Well everything happening inside of the Apply() function, of course <img src='http://carlfurrow.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>First off, I’m getting the type of the target, which is of type IOneToManyPart. The target parameter is automagically in the form of OneToManyPart&lt;Blog&gt; or OneToManyPart&lt;Post&gt; depending on which OneToMany relationship is being mapped (User.Blogs, User.Posts or Blog.Posts).&#160; Now that I have the type of OneToMany relationship, I compare it to the current target’s mapping.</p>
<p>If the type is OneToMany&lt;Blog&gt;, then I need to tell the FluentNHibernate Automapping framework to use column “OwnerId”.&#160; This may seem weird, but maybe this SQL query generated by NHibernate will help a little.&#160; The code is getting a User with Id 1, and returning all the Blogs owned by that user.</p>
<pre name="code" class="c-sharp">NHibernate: SELECT user0_.Id as Id1_0_, user0_.Password as Password1_0_, user0_.Email as Email1_0_ FROM &quot;User&quot; user0_ WHERE user0_.Id=@p0; @p0 = '1'
NHibernate: SELECT blogs0_.OwnerId as OwnerId1_, blogs0_.Id as Id1_, blogs0_.Id as Id0_0_, blogs0_.LastUpdated as LastUpda2_0_0_, blogs0_.Title as Title0_0_, blogs0_.Description as Descript4_0_0_, blogs0_.OwnerId as OwnerId0_0_ FROM &quot;Blog&quot; blogs0_ WHERE blogs0_.OwnerId=@p0; @p0 = '1'</pre>
<p>If I did not tell FluentNHibernate to use the column “OwnerId”, it would instead use “User_Id” by convention, since in the Blog class, Owner is of type User.&#160; I do not want this convention, so I must override it in order for the mapping to work successfully.&#160; Yes, it’s more work for me to not use the convention, but, I wanted to illustrate the point.&#160; </p>
<p>The same idea goes for a target of type OneToMany&lt;Post&gt;.&#160; I tell the framework to use column “AuthorId” instead of it’s normal “User_Id” convention.</p>
<p>The last convention added to a OneToMany relationship is how to cascade updates/deletes/etc, by letting the framework know to cascade all.&#160; So now when I delete an object through NHibernate, NHibernate will run a SQL query to cascade the delete properly.</p>
<p>Let’s move on to the next convention:</p>
<pre name="code" class="c-sharp">public class HasManyToManyConvention : IHasManyToManyConvention
{
    public bool Accept(IManyToManyPart target)
    {
        return true;
    }

    public void Apply(IManyToManyPart target)
    {
        target.Cascade.All();
    }
}</pre>
<p>This convention is much simpler as it just states that for every ManyToMany relationship, I only want the cascade all behavior. The same goes for a HasOne relationship, but for full-disclosure’s sake, I’ll post the code below:</p>
<pre name="code" class="sql">public class HasOneConvention : IHasOneConvention
{
    public bool Accept(IOneToOnePart target)
    {
        return true;
    }

    public void Apply(IOneToOnePart target)
    {
        target.Cascade.All();
    }
}</pre>
<p>Another simple, but important convention to my database model, is my IdConvention:</p>
<pre name="code" class="c-sharp">public class IdConvention : IIdConvention
{
    public bool Accept(IIdentityPart target)
    {
        return true;
    }

    public void Apply(IIdentityPart target)
    {
        target.ColumnName(&quot;Id&quot;);
    }
}</pre>
<p>I believe that by convetion, FluentNHibernate’s AutoMapping framework looks for the ID column in a database by using the DTO class name and appending “Id” to it.&#160; I do not want this behavior, so I’m letting the framework know that I want it to know that when looking for the identity column in the database for each table, look for a column named “Id”.</p>
<p>The last custom convention that I laid out was the ManyToOne relationship convention.</p>
<pre name="code" class="c-sharp">public class ReferencesConvention : IReferenceConvention
{
    public bool Accept(IManyToOnePart target)
    {
        return true;
    }

    public void Apply(IManyToOnePart target)
    {
        target.ColumnName(target.Property.Name + &quot;Id&quot;);
    }
}</pre>
<p>Again, I’m apply this convention to all mapped classes that have a ManyToOne relationship and then I’m letting the framework know that the column names will be in the format of Property name + “Id”.&#160; An example of a ManyToOne relationship in my database model is between Blogs and Users.&#160; A blog has an Owner property (which is a user), so to map this relationship, we’re telling FluentNHibernate to look for a column named “OwnerId” in the Blog table.&#160; And that does it for my conventions.</p>
<p>Alright, let’s figure out where we are right now.</p>
<ul>
<li>I’ve got a class, BlogAutoPersistenceModelConfig, that creates an AutoPersistenceModel object</li>
<ul>
<li>The class also let’s the FluentNHibernate framework know that each of my DTOs have a base class of DomainEntity</li>
<li>The class also adds some criteria to the framework to let it know which DTOs to map, and which ones to ignore.</li>
<li>The last step is to add conventions to the mapped classes to determine how to handle different relationship types, and where to find the ID column in a table.</li>
</ul>
</ul>
<p>Now that we’ve got an AutoPersistenceModel configured, we can proceed to create an ISessionFactory as part of the NHibernate framework.&#160; That’ll be a topic for the next post, and it should be quite a bit shorter.</p>
<p>Hope this was a little helpful in your automapping ventures. </p>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2009/06/rolling-my-own-blog-engine-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rolling my own blog engine, part 2</title>
		<link>http://carlfurrow.com/2009/05/rolling-my-own-blog-engine-part-2/</link>
		<comments>http://carlfurrow.com/2009/05/rolling-my-own-blog-engine-part-2/#comments</comments>
		<pubDate>Fri, 22 May 2009 00:00:45 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[fluent]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/2009/05/rolling-my-own-blog-engine-part-2/</guid>
		<description><![CDATA[
Rolling my own blog engine, part 1 

Initially I was going to jump into my tests that I had written to exercise my data access layer via FluentNHibernate, but, I’ve decided that I wanted to get to AutoMapping first before I move ahead. Before I get to that though, I have to do a little [...]]]></description>
			<content:encoded><![CDATA[<p></p><ul>
<li><a href="http://carlfurrow.com/2009/05/rolling-my-own-blog-engine-part-1/">Rolling my own blog engine, part 1</a> </li>
</ul>
<p>Initially I was going to jump into my tests that I had written to exercise my data access layer via FluentNHibernate, but, I’ve decided that I wanted to get to AutoMapping first before I move ahead. Before I get to <em>that </em>though, I have to do a little housekeeping.</p>
<p> <span id="more-75"></span>
</p>
<p>I wanted to get rid of the “RegisteredUser” class, and just have a “User” class. At the same time I saw a place to abstract a little code through inheritence, so I created a DomainEntity class (code is below).&#160; While I was at it, I made my other classes, Blog and Post, inherit from DomainEntity as well.</p>
<pre class="brush: csharp;">public class User : DomainEntity
{
    public virtual IList&lt;Blog&gt; Blogs { get; set; }
    public virtual IList&lt;Post&gt; Posts { get; set; }
    public virtual string Email { get; set; }
    public virtual string Username { get; set; }
    public virtual string Password { get; set; }

    public User()
    {
        Blogs = new List&lt;Blog&gt;();
        Posts = new List&lt;Post&gt;();
        Email = string.Empty;
        Username = string.Empty;
        Password = string.Empty;
    }

}</pre>
<pre class="brush: csharp;">public class DomainEntity : IEquatable&lt;DomainEntity&gt;
{
    public virtual Guid Id { get; set; }

    public virtual bool Equals(DomainEntity other)
    {
        if (ReferenceEquals(null, other))
        {
            return false;
        }

        if (ReferenceEquals(this, other))
        {
            return true;
        }

        return other.Id.Equals(Id);
    }

    public override bool Equals(object obj)
    {
        if (ReferenceEquals(null, obj))
        {
            return false;
        }

        if (ReferenceEquals(this, obj))
        {
            return true;
        }

        if (obj.GetType() != GetType())
        {
            return false;
        }

        return Equals((DomainEntity)obj);
    }

    public override int GetHashCode()
    {
        return Id.GetHashCode();
    }

    public static bool operator ==(DomainEntity left, DomainEntity right)
    {
        return Equals(left, right);
    }

    public static bool operator !=(DomainEntity left, DomainEntity right)
    {
        return !Equals(left, right);
    }
}</pre>
<p>Now we’ve got a more simply named class (User) and I added a layer of abstraction by inheriting from a DomainEntity class.&#160; The DomainEntity will become the base class of our other classes; Blog and Post and will handle things such as the Id property, as well as equality validation.&#160; Their new code makeover, is as follows:</p>
<pre class="brush: csharp;">public class Blog : DomainEntity
{
    public virtual IList&lt;Post&gt; Posts { get; set; }
    public virtual string Title { get; set; }
    public virtual string Description { get; set; }
    public virtual DateTime LastUpdate { get; set; }
    public virtual User Owner { get; set; }

    public Blog()
    {
        Posts = new List&lt;Post&gt;();
        Title = string.Empty;
        Description = string.Empty;
        LastUpdate = DateTime.MinValue;
        Owner = new User();
    }
}</pre>
<pre class="brush: csharp;">public class Post : DomainEntity
{
    public virtual string Title { get; set; }
    public virtual string Body { get; set; }
    public virtual DateTime LastUpdate { get; set; }
    public virtual DateTime PublishDate { get; set; }
    public virtual User Author { get; set; }

    public Post()
    {
        Author=new User();
        Title = string.Empty;
        Body = string.Empty;
        LastUpdate = DateTime.MinValue;
        PublishDate = DateTime.MinValue;
    }
}</pre>
<p>Great, now things are setup in a way that we can move on to AutoMapping these classes to the database using a convention over configuration.&#160; Last time I had a lot of code that I had to generate by hand in order to map each class to the database, and in turn, a table in that database.&#160; It wasn’t terribly backbreaking work, but, there’s a simpler way, especially when you have more and more classes that need mapping to tables in the database.</p>
<p>I’ll go over my AutoMapping solution next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2009/05/rolling-my-own-blog-engine-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More TDD Fun: String manipulation</title>
		<link>http://carlfurrow.com/2009/05/more-tdd-fun-string-manipulation/</link>
		<comments>http://carlfurrow.com/2009/05/more-tdd-fun-string-manipulation/#comments</comments>
		<pubDate>Tue, 12 May 2009 15:21:03 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[TDD]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[mbunit]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/2009/05/more-tdd-fun-string-manipulation/</guid>
		<description><![CDATA[I had another programming problem dawn on me the other day; 
Given a string of words, separated by spaces, reverse each words’ letters, but not the order of the words in the string.

Sounds simple enough. If you were to have the string “abc defg”, the output would be “cba gfed”. A simplistic brain puzzle, but [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I had another programming problem dawn on me the other day; </p>
<blockquote><p><font color="#111111">Given a string of words, separated by spaces, reverse each words’ letters, but not the order of the words in the string.</font></p>
</blockquote>
<p>Sounds simple enough. If you were to have the string “abc defg”, the output would be “cba gfed”. A simplistic brain puzzle, but I admittedly took more time than I thought necessary to solve it.&#160; </p>
<p> <span id="more-72"></span>
<p>&#160;</p>
<p>Assumptions:</p>
<ul>
<li>I’d need a method that can reverse a given string </li>
<li>I’d be manipulating arrays of characters, not actual “strings” </li>
</ul>
<p>I wrote my first test using those assumptions:</p>
<pre class="brush: csharp">
public void CanReverseCharactersOfAString()
{
    string testString = &quot;abcdefg&quot;;
    string expectedOutcome = &quot;gfedcba&quot;;

    string reversedString = Manipulator.ReverseString(testString);

    Assert.AreEqual(expectedOutcome, reversedString);
}
</pre>
<p>So I wrote this test without writing any other code, and as you can see, it’s expecting a class called “<font face="Courier New">Manipulator</font>” that has a static method “<font face="Courier New">ReverseString</font>”.&#160; Yes, I suppose I could have written a string extension method, but I chose not to. No reasoning behind that decision.</p>
<p>Of course, this test will fail because the project won’t build. Let’s go fill in the blanks.</p>
<pre class="brush: csharp">
public class Manipulator
{
    public static string ReverseString(string s)
    {
        char[] chars = s.ToCharArray();

        ReverseAtIndices(ref chars, 0, chars.Length);

        return new string(chars);
    }

    private static void ReverseAtIndices(ref char[] chars, int low, int high)
    {
        char temp;
        int i = 0; // &#039;i&#039; will help us get from one side of the string to the other, working backwards
        for (int j = low; j &lt; high; j++)
        {
            int end = high - 1 - i++;   // &#039;end&#039; is the other index to swap letters with
            if (j &amp;amp;amp;gt;= end)               // if the current index &#039;j&#039; is greater than or equal to &#039;end&#039;, we can stop swapping
                break;                      //Why? Because we&#039;ve reached the half-way point in the string.
            temp = chars[j];
            chars[j] = chars[end];
            chars[end] = temp;
        }
    }

}
</pre>
<p>I realized I’d need a helper method, <font face="Courier New">ReverseAtIndices</font>, that takes a reference to a character array and then a low and high integer.&#160; The character array is the string to be reversed. Low and high are the indices in the array to start and stop the reversing, respectively (so I guess I could refactor and call them “start” and “stop”, eh?)</p>
<p>The method loops through the array and swaps letters at opposite ends of the array. For instance, in the array of <font face="Courier New">[a,b,c]</font>, ‘a’ would get swapped with ‘c’, and ‘b’ would get swapped with itself. If we allowed the loop to go just one step further, it would swap ‘a’ and ‘c’ again, outputting <font face="Courier New">[a,b,c]</font> instead of the desired <font face="Courier New">[c language=",b,a"][/c]</font>.</p>
<p>Running the test <font face="Courier New">CanReverseCharactersOfAString()</font> passes, so on to the next challenge; reversing letters of words in a string while not changing the order of the words.&#160; Let’s write a test for it:</p>
<pre class="brush: csharp">
[Row(&quot;abc def&quot;, &quot;cba fed&quot;, &#039; &#039;)]
[Row(&quot;abc&quot;, &quot;cba&quot;, &#039; &#039;)]
[Row(&quot;abc defg hij kl&quot;, &quot;cba gfed jih lk&quot;, &#039; &#039;)]
[Row(&quot;hello world!&quot;, &quot;olleh !dlrow&quot;, &#039; &#039;)]
public void CanReverseLettersInStringOfWords(string input, string expected, char delimiter)
{
    Assert.AreEqual(expected, Manipulator.ReverseLettersInAStringOfWords(input, delimiter));
}
</pre>
<p>I decided to use MbUnit’s row-testing capabilities so that I could run the same test with differing inputs without having to write more tests.</p>
<p>As you’ll note, I’ve assumed I’m going to have a new static method in the <font face="Courier New">Manipulator</font> class called <font face="Courier New">ReverseLettersInAStringOfWords</font>. Admittedly, not a great name, but, it’s fairly descriptive for this exercise.&#160; The method takes just two parameters, a string and a character.&#160; The string is, of course, the string of words we want to reverse some letters in, and the character is the delimiter between words.&#160; In this exercise, the delimiter will always be a space, but, we could use this method in the future and easily pass in any delimiter we wanted, such as a comma.&#160; </p>
<p>When writing the actual method, ReverseLettersInAStringOfWords, I had some difficulty getting it to work in the manner I wanted.&#160; I’m pretty sure there are dozens of Google answers out there on this very problem, but, I wanted to solve it without them first. I’ll probably go back and refactor once I see some other solutions.&#160; Here’s the code. It’s a little verbose for my liking, but, again, it hasn’t be refactored yet (basically I’m asking for you to turn a blind eye just this once <img src='http://carlfurrow.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ):</p>
<pre class="brush: csharp">
public static string ReverseLettersInAStringOfWords(string s, char delimiter)
{
    char[] chars = s.ToCharArray();
    char temp;
    int i=0;
    int low, high;
    low = high = i;
    for (i = 0; i &amp;amp;amp;lt; chars.Length; i++)
    {
        // Move the &#039;high&#039; index up if the delimiter hasn&#039;t been found yet
        if(chars[i] != delimiter)
            high = i + 1;
        else
        {
            ReverseAtIndices(ref chars, low, high);
            // Move up the low index now that we&#039;ve found a delimiter
            //  and reversed some characters
            low = i + 1;
        }
    }
    // The end of the string may not contain a delimiter, so make sure
    //  we reverse the last set of characters
    if(high == chars.Length)
        ReverseAtIndices(ref chars, low, high);
    return new string(chars);
}
</pre>
<p>With this method written, all the tests pass (thankfully) and we’ve satisfied the guidelines of the problem statement.</p>
<p>Now I’m off to Google some better alternatives <img src='http://carlfurrow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2009/05/more-tdd-fun-string-manipulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TDD Fun(?) : Creating a linked list in C#</title>
		<link>http://carlfurrow.com/2009/05/tdd-fun-creating-a-linked-list-in-c/</link>
		<comments>http://carlfurrow.com/2009/05/tdd-fun-creating-a-linked-list-in-c/#comments</comments>
		<pubDate>Mon, 11 May 2009 23:15:23 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[TDD]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[linked-list]]></category>
		<category><![CDATA[mbunit]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/?p=62</guid>
		<description><![CDATA[I was reminded just today that it’s been a while since I’ve implemented a linked list from scratch, and it sounded kind of fun.  I also thought that I should create it via a TDD (test-driven development) strategy to give myself an additional +1 to my good-little-coder attribute.
 To begin, I’ll do a quick overview [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I was reminded just today that it’s been a while since I’ve implemented a linked list from scratch, and it sounded kind of fun.  I also thought that I should create it via a TDD (test-driven development) strategy to give myself an additional +1 to my good-little-coder attribute.</p>
<p><span id="more-62"></span> To begin, I’ll do a quick overview of what I needed in order to create a linked list. First, I needed a Node class to hold three values: Next, Previous and Value.  “Next” is a Node-type that holds, you guessed it, the next Node in the list, adjacent to the current Node.  “Previous” is the same concept, except it of course holds the value of the node “in front of” the current node, and “Value” is the currently held value of that node.  For this little demo, I’m not going to use generics, so the LinkedList will be un-typed, so to speak, and therefore Value will actually be an object so that it can old any type.</p>
<p>Next, I’d need a LinkedList class to keep track of the root node, and handle the adding and deleting of nodes in the list. More on that in a bit, we’ve got to write some tests before we delve into this any further!</p>
<pre class="brush: csharp">
[Test]
public void CanCreateNewList()
{
    string testValue = &amp;amp;quot;root&amp;amp;quot;;
    LinkedList linkedList = new LinkedList(testValue);

    Assert.AreEqual(testValue, linkedList.CurrentNode.Value);
}

[Test]
public void CanAddNodeWhereNextNodeIsNull()
{
    string rootValue = &amp;amp;quot;root&amp;amp;quot;;
    string childValue = &amp;amp;quot;child&amp;amp;quot;;

    LinkedList linkedList = new LinkedList(rootValue);

    linkedList.AddNode(childValue);

    Assert.AreEqual(linkedList.CurrentNode.Value, childValue);
    Assert.AreEqual(linkedList.CurrentNode.Prev.Value, rootValue);
    Assert.AreEqual(linkedList.Length, 2);
}

[Test]
public void CanAddNodeWhereNextNodeIsNotNull()()
{
    string rootValue = &amp;amp;quot;root&amp;amp;quot;;
    string childValue = &amp;amp;quot;child1&amp;amp;quot;;
    string newChildValue = &amp;amp;quot;child2&amp;amp;quot;;

    LinkedList linkedList = new LinkedList(rootValue);
    linkedList.AddNode(childValue);
    linkedList.Previous(); // root
    linkedList.AddNode(newChildValue);

    Assert.AreEqual(linkedList.CurrentNode.Value, newChildValue);
    Assert.AreEqual(linkedList.CurrentNode.Prev.Value, childValue);
    Assert.AreEqual(linkedList.Length,3);
}

[Test]
public void CannotUsePrevOnRoot()
{
    string rootValue = &amp;amp;quot;root&amp;amp;quot;;
    LinkedList linkedList = new LinkedList(rootValue);
    var prevNode = linkedList.Previous();
    var prevPrevNode = linkedList.Previous();

    Assert.AreEqual(rootValue, linkedList.CurrentNode.Value);
    Assert.AreEqual(rootValue, prevNode.Value);
    Assert.AreEqual(rootValue, prevPrevNode.Value);
}

[Test]
public void CannotUseNextOnLastElement()
{
    string rootValue = &amp;amp;quot;root&amp;amp;quot;;
    LinkedList linkedList = new LinkedList(rootValue);

}

[Test]
public void CanDeleteNode()
{

    int oldLength, newLength;
    LinkedList linkedList = new LinkedList(&amp;amp;quot;root&amp;amp;quot;);
    linkedList.AddNode(&amp;amp;quot;child&amp;amp;quot;);
    oldLength = linkedList.Length;
    linkedList.Delete(1);
    newLength = linkedList.Length;
    Assert.GreaterThan(oldLength, newLength);
}

[Test]
[ExpectedException(typeof(IndexOutOfRangeException))]
public void CannotDeleteNodeWithInvalidIndex()
{
    int oldLength, newLength;
    LinkedList linkedList = new LinkedList(&amp;amp;quot;root&amp;amp;quot;);
    linkedList.AddNode(&amp;amp;quot;child&amp;amp;quot;);
    oldLength = linkedList.Length;
    linkedList.Delete(99);
    newLength = linkedList.Length;
    Assert.GreaterThan(oldLength, newLength);
}

[Test]
public void CanGetNodeByGoto()
{
    string rootValue = &amp;amp;quot;root&amp;amp;quot;;
    string child1Value = &amp;amp;quot;child1&amp;amp;quot;;
    string child2Value = &amp;amp;quot;child2&amp;amp;quot;;
    string child3Value = &amp;amp;quot;child3&amp;amp;quot;;
    string child4Value = &amp;amp;quot;child4&amp;amp;quot;;
    LinkedList linkedList = new LinkedList(rootValue);
    linkedList.AddNode(child1Value);
    linkedList.AddNode(child2Value);
    linkedList.AddNode(child3Value);
    linkedList.AddNode(child4Value);

    Assert.AreEqual(linkedList.Goto(2).Value,child2Value);
}

[Test]
[ExpectedException(typeof(IndexOutOfRangeException))]
public void CannotGetNodeWithInvalidIndex()
{
    string rootValue = &amp;amp;quot;root&amp;amp;quot;;
    LinkedList linkedList = new LinkedList(rootValue);

    var node = linkedList.Goto(99);

    Assert.IsNotNull(node);
}
</pre>
<p>The above tests are the product of my TDD. I created the test, ran the test (they failed), then wrote supporting code to make the test pass. Refactored, repeated, then wrote the next test.</p>
<p>So, what do they do?  The above tests test for the following (if you don’t want to sort through the code):</p>
<ul>
<li>Tests that I can successfully create a new LinkedList object</li>
<li>Tests that I can add a node to a LinkedList object</li>
<li>Tests that I can delete a node from a LinkedList object</li>
<li>Tests that I cannot delete a node that doesn’t exist</li>
<li>Tests that I can quickly “jump to” a node by passing its index</li>
<li>Tests that I cannot “jump to” a node that doesn’t exist</li>
</ul>
<p>The code for the Node class:</p>
<pre class="brush: csharp">
public class Node
{
    public Node Next { get; set; }
    public Node Prev { get; set; }
    public object Value { get; set; }
}
</pre>
<p>The code for the LinkedList class:</p>
<pre class="brush: csharp">
public class LinkedList
{
    private Node _CurrentNode;
    private int _Count;
    private int _CurrentPosition;

    public Node CurrentNode
    {
        get { return _CurrentNode; }
    }

    public int Count
    {
        get { return _Count; }
    }

    public int CurrentPosition
    {
        get { return _CurrentPosition; }
    }

    public LinkedList(object value)
    {
        _Count = 1;
        _CurrentPosition = 0;

        _CurrentNode = new Node() { Next = null, Prev = null, Value = value };
    }

    public void AddNode(object value)
    {
        if(CurrentNode.Next==null)
        {
            CurrentNode.Next = new Node() {Next = null, Prev = CurrentNode, Value = value};
            _CurrentPosition++;
            _Count++;
            _CurrentNode = _CurrentNode.Next;
        }
        else
        {
            _CurrentNode = _CurrentNode.Next;
            _CurrentPosition++;
            AddNode(value);
        }
    }

    public Node Next()
    {
        if(_CurrentNode.Next != null)
        {
            _CurrentNode = _CurrentNode.Next;
            _CurrentPosition++;
        }
        return _CurrentNode;
    }
    public Node Previous()
    {
        if(_CurrentNode.Prev != null)
        {
            _CurrentNode = _CurrentNode.Prev;
            _CurrentPosition--;
        }
        return _CurrentNode;
    }

    public void Delete(int i)
    {
        var node = this.Goto(i);
        var prevNode = node.Prev;
        var nextNode = node.Next;

        if (prevNode != null)
        {
            prevNode.Next = nextNode;
            if (nextNode != null) nextNode.Prev = prevNode;
        }
        _Count--;
        _CurrentPosition = i - 1;
    }

    public Node Goto(int i)
    {
        if(i&amp;gt;Count-1)
            throw new IndexOutOfRangeException(&amp;amp;quot;Index out of range: &amp;amp;quot; + i);
        if(CurrentPosition &amp;gt; i)
        {
            Previous();
            return Goto(i);
        }
        if(CurrentPosition &amp;lt; i)
        {
            Next();
            return Goto(i);
        }
        return CurrentNode;
    }
</pre>
<p>And that’s really it. I can create a new linked list, add, delete and jump to a specific node.
</pre>
</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2009/05/tdd-fun-creating-a-linked-list-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Investment in your developers</title>
		<link>http://carlfurrow.com/2009/05/investment-in-your-developers/</link>
		<comments>http://carlfurrow.com/2009/05/investment-in-your-developers/#comments</comments>
		<pubDate>Mon, 11 May 2009 12:00:09 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/?p=23</guid>
		<description><![CDATA[It is far too common that companies are not investing enough in their coders, and I don’t mean strictly monetary compensation.  Developers need to learn and network with other developers about new projects, technologies and methodologies in order to stay fresh and current.  Developers need to know that they’re not alone in their concerns, and [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>It is far too common that companies are not investing enough in their coders, and I don’t mean strictly monetary compensation.  Developers need to learn and network with other developers about new projects, technologies and methodologies in order to stay fresh and current.  Developers need to know that they’re not alone in their concerns, and that there is a larger network out there that has either been through what they’ve been through, or has a suggested road map to completion.  I believe there is a strong need to utilize conferences, community involvement, and/or inter-company learning sessions to effectively invest in your developers.</p>
<p><span id="more-23"></span></p>
<p>Equipment, equipment, equipment!  It is beyond me why some companies do not put a higher emphasis on high-performing, current equipment for their developers.  Economic reasons aside, laptops should be replaced every two years, I believe, in order to keep up to pace with the newest developer environments, especially when your developer environment is virtualized via <a href="http://www.vmware.com/">VMWare</a>, or <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=04D26402-3199-48A3-AFA2-2DC0B40A73B6&amp;displaylang=en">Microsoft’s Virtual PC</a> (or even <a href="http://www.parallels.com/">Parallels</a> if developing Windows software on a Mac).  When visiting a local software shop recently, I noticed more than a handful of Dell laptops that were 4 to 5 years old, and the developers were constantly groaning at how long it would take to build.  Regular equipment replacement should be considered a given when your company relies on your developers to turn a profit.</p>
<p>Conferences are an easy fix to a lack of developer investment in a company.  Let the devs pick a yearly conference to go, and listen to the conversations that begin to happen when they return.  Conferences like <a href="http://www.codemash.org/">CodeMash</a>, <a href="http://www.devlink.net/">DevLink</a>, <a href="http://www.microsoft.com/events/TechEd2009/">TechEd</a> or the <a href="http://developer.apple.com/WWDC/">Apple  Worldwide Developers Conference</a> are some great ones, to name a few.</p>
<p>Another way to invest in your developers is to encourage community involvement.  Attending user groups, or volunteering to speak at a conference like <a href="http://kalamazoox.org/">KalamazooX</a> or the <a href="http://dodn.org/WestMichiganDotNetU/">West Michigan’s .Net University</a> can go a long way in not only improving your developers’ public speaking skills, but it’s also a way to let the community know about your company’s human assets.</p>
<p>One of the development teams I came across on my travels met weekly in a conference room, and discussed a chapter from <a href="http://cc2e.com/">“Code Complete 2nd Edition”</a> that they had read the week before.  An educated and collaborative discussion of what each developer understood and took from the chapter went a long way in getting every dev on the same proverbial page (gah, pun!).  I thought this was an excellent practice to have, and that was almost five years ago now. I imagine you could even save the expense of buying a book for each developer, and instantiate a weekly web-article review, or find a few problems on <a href="http://stackoverflow.com">StackOverflow.com</a>, or <a href="http://projecteuler.net/">ProjectEuler.com</a> for the team to solve collaboratively.</p>
<p>Investing in your developers can go a long way in helping the team dynamic by getting them to work more closely together as they find each others’ strengths and weaknesses, and not see them as barriers but opportunities for learning.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2009/05/investment-in-your-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Investment in a process</title>
		<link>http://carlfurrow.com/2009/05/investment-in-a-process/</link>
		<comments>http://carlfurrow.com/2009/05/investment-in-a-process/#comments</comments>
		<pubDate>Sat, 09 May 2009 12:00:38 +0000</pubDate>
		<dc:creator>Carl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[scrum]]></category>

		<guid isPermaLink="false">http://carlfurrow.com/?p=20</guid>
		<description><![CDATA[There is definitely such a thing as having too much process in a development cycle, and, of course, conversely there is definitely such as thing as having too little process.
I like to surround myself with people (well, mostly developers) that believe that a little time investing in a lean process goes a long way. Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>There is definitely such a thing as having too much process in a development cycle, and, of course, conversely there is <em>definitely</em> such as thing as having too little process.</p>
<p>I like to surround myself with people (well, mostly developers) that believe that a little time investing in a lean process goes a long way. Let&#8217;s take, for example, implementing <a href="http://en.wikipedia.org/wiki/Scrum_(development)#Meetings">SCRUM meetings,</a> not the entire SCRUM methodology, just the daily meeting.<span id="more-20"></span></p>
<p>I was once told that a daily meeting, lasting 5-10 minutes was asking too much, and that the development team would rather just code.  Unfortunately, it turns out that we ended up having one to two hour long meetings every few days to &#8220;sync-up&#8221; and reorganize with what could have been accomplished in a fraction of that time.</p>
<p>To be honest, I&#8217;ve never been a part of a SCRUM meeting, YET! But I can whole-heartedly see the value in it.</p>
<ul>
<li>Everyone knows what everyone is working on</li>
<li>Everyone knows where the &#8220;trouble spots&#8221; are</li>
<li>It is not a witch-hunt or a blame-game when problems arise</li>
<li>No one is stuck &#8220;churning&#8221; on a particular piece of functionality</li>
</ul>
<p>SCRUM meetings can be such a simple process, and they don&#8217;t (really) have to involve any management intervention. It could be taken upon the developers alone, so that they can all benefit from its outcomes.  With SCRUM, individual failures reflect on the team, and if you start blaming one developer, the team has failed.  I believe that under SCRUM the success or failure of the project is on the team as a whole, so it’s less about pointing fingers and more about solving problems collaboratively.</p>
<p>On the flip side, I&#8217;ve had experience in which there was too much process in a developer cycle.  Where the dev team would spend more time in meetings, Monday through Wednesday, than coding.  Every decision had to be deliberated with the core/senior development team, who would then hash it up, and deliver it to the management team, who would then package it and hand it over to the CIO, who would then add notes and pass it back down through the chain.  And the decisions were trivial, such as should we use a drop-down list, or a checkbox group.  These decisions can and sometimes <em>should </em>be left up to the development and user-experience team members, and shouldn&#8217;t involve more people than absolutely necessary.</p>
<p>There is a time and place for a process that <em>works </em>for your development team, and finding and implementing that process should definitely be a collaborative effort.  At a minimum a SCRUM-type daily meeting doesn&#8217;t add much additional time to your normal routine, but, I believe it will strike up the right kind of collaboration and conversations afterward to keep the project&#8217;s momentum going.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlfurrow.com/2009/05/investment-in-a-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
