<?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/"
	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/"
	>

<channel>
	<title>The Cockney Coder</title>
	<atom:link href="http://cockneycoder.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cockneycoder.wordpress.com</link>
	<description>Spreading the Gospel of Isaac</description>
	<lastBuildDate>Wed, 25 Jan 2012 23:33:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='cockneycoder.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>The Cockney Coder</title>
		<link>http://cockneycoder.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://cockneycoder.wordpress.com/osd.xml" title="The Cockney Coder" />
	<atom:link rel='hub' href='http://cockneycoder.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Let there be LINQ</title>
		<link>http://cockneycoder.wordpress.com/2012/01/25/let-there-be-linq/</link>
		<comments>http://cockneycoder.wordpress.com/2012/01/25/let-there-be-linq/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 23:27:39 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/?p=732</guid>
		<description><![CDATA[Just a quick post regarding use of the let keyword in LINQ, which I find to be somewhat under-used by many people. Whilst one benefit of it can be readability (i.e. aliasing sections of complex queries to aid understanding of the query), the other benefit can be performance. There is indeed a cost associated with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=732&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just a quick post regarding use of the let keyword in LINQ, which I find to be somewhat under-used by many people. Whilst one benefit of it can be readability (i.e. aliasing sections of complex queries to aid understanding of the query), the other benefit can be performance.</p>
<p>There is indeed a cost associated with using it i.e. every time you use it, you’re effectively creating a new anonymous type to hold that plus whatever the previous result in your query pipeline. So if you chain up lots of lets in a query, that’ll have an impact on the query. However, there is a case where let can give large performance benefits: -</p>
<p><a href="http://cockneycoder.files.wordpress.com/2012/01/image16.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2012/01/image_thumb16.png?w=660&#038;h=176" width="660" height="176" /></a></p>
<p>Compare that code with the following: -</p>
<p><a href="http://cockneycoder.files.wordpress.com/2012/01/image17.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2012/01/image_thumb17.png?w=660&#038;h=219" width="660" height="219" /></a></p>
<p>This will eliminate a massive number of calls to <strong>Convert.ToInt32()</strong> and reduce the time taken to process that query by around <strong>40%</strong>; the former sample took ~1400ms to run whereas the latter took only around 800ms.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/732/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=732&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2012/01/25/let-there-be-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2012/01/image_thumb16.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2012/01/image_thumb17.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Unity&#8217;s [OptionalDependency] &#8211; don&#8217;t do it</title>
		<link>http://cockneycoder.wordpress.com/2012/01/09/optionaldependency-dont-do-it/</link>
		<comments>http://cockneycoder.wordpress.com/2012/01/09/optionaldependency-dont-do-it/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 22:58:16 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/?p=722</guid>
		<description><![CDATA[Just a quick tip – when using Unity for DI &#8211; DON’T use the [OptionalDependency] attribute unless you absolutely have to. Why? Because it can be incredibly unslow. I’ve not had a look at the source code so can’t know exactly, but as I recall, the way that Unity deals with OptionalDependencies when they are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=722&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Just a quick tip – when using Unity for DI &#8211; DON’T use the [OptionalDependency] attribute unless you absolutely have to.</p>
<p align="justify">Why? Because it can be incredibly unslow. I’ve not had a look at the source code so can’t know exactly, but as I recall, the way that Unity deals with OptionalDependencies when they are not available is by throwing an exception, which is then caught and supressed by itself.</p>
<p align="justify">Performance varies depending on the type of object and the number of constructors it has (among other things), but, for example, missing Strings that are marked optional are incredibly slow if not available – sometimes upto 50x slower to construct an object.</p>
<p align="justify">This might not be noticeable if you just create the odd object here and there – but if you start doing anything heavyweight, you’ll soon notice it – so avoid it wherever possible.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/722/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/722/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/722/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/722/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/722/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/722/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/722/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/722/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/722/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/722/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/722/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/722/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/722/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/722/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=722&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2012/01/09/optionaldependency-dont-do-it/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>
	</item>
		<item>
		<title>Generic type factories</title>
		<link>http://cockneycoder.wordpress.com/2012/01/01/generic-type-factories/</link>
		<comments>http://cockneycoder.wordpress.com/2012/01/01/generic-type-factories/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 21:16:40 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[generics]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/?p=691</guid>
		<description><![CDATA[Happy new year to everyone! I’ve really got the blog bug over this Christmas period… today, I want to talk a little about how to create easily-consumable generic classes. Generic Types and Composition Generics in C# are great. They give so many elegant ways to solve common problems and to implement certain design patterns that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=691&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Happy new year to everyone! I’ve really got the blog bug over this Christmas period… today, I want to talk a little about how to create easily-consumable generic classes.</p>
<h3 align="justify">Generic Types and Composition</h3>
<p align="justify">Generics in C# are great. They give so many elegant ways to solve common problems and to implement certain design patterns that without generics would involve lots of boilerplate code. One of the things that they are great at is writing <a href="http://en.wikipedia.org/wiki/Object_composition">composed objects</a>. For example, let’s say we wanted to represent a binary tree structure in C#. It might look something like this: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2012/01/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2012/01/image_thumb.png?w=382&#038;h=231" width="382" height="231"></a></p>
<p align="justify">Seems logical, doesn’t it? We have our properties which represent the data of a tree node, and a constructor that takes in the item that the node holds. Great &#8211; you can now have a tree node for any type e.g. Node&lt;String&gt;, Node&lt;Int32&gt; etc.! However, when you try to start using it and creating nodes in code, you’ll immediately come across a small problem: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2012/01/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2012/01/image_thumb1.png?w=464&#038;h=80" width="464" height="80"></a></p>
<p align="justify">See the issue? Every time you want to create a Node of type T, you have to explicitly specify T in the type definition, even though we’re passing in an object of type T into the constructor. Seems a bit pointless, doesn’t it? Can’t the compiler “figure out” the definition from the constructor argument?</p>
<h3 align="justify">Generic methods</h3>
<p align="justify">Luckily, there is indeed a way to achieve this effect through a generic <strong>method</strong> which acts as a factory &#8211; as long as it does <em>not</em> belong in the generic Node&lt;T&gt; class! Check this guy out: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2012/01/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2012/01/image_thumb2.png?w=491&#038;h=158" width="491" height="158"></a></p>
<p align="justify">This method lives in the non-generic Node class. We can easily consume it as follows and thus create nodes much more succinctly: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2012/01/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2012/01/image_thumb3.png?w=405&#038;h=79" width="405" height="79"></a></p>
<p align="justify">Sure enough, the nodes are correctly typed just like before e.g. Node&lt;String&gt;, Node&lt;Employee&gt; etc., but now a lot of the fluff has been removed – based on the type of the constructor argument, the return type will be inferred by the compiler. C#’s type inference perhaps isn’t as powerful as F#, but it’s really not that bad <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://cockneycoder.files.wordpress.com/2012/01/wlemoticon-smile.png?w=600"></p>
<p align="justify">Also notice that we’ve put the factory method in a class called Node – again, this aids the developer in terms of discoverability as it sits alongside Node&lt;TItem&gt;.</p>
<h3 align="justify">Conclusion</h3>
<p align="justify">You might often find yourself putting generic methods into non-generic classes that themselves return generic objects.</p>
<p align="justify">There are many occasions when you may find that you need a non-generic base / sibling class for your generic classes in order to easily construct them, or deal with a set objects of a particular generic type that differ only by their type parameters e.g. Node&lt;String&gt;, Node&lt;Int32&gt; and Node&lt;Employee&gt; – having a non-generic base class called Node with common properties or methods allows you to deal with all instances of all Nodes in one go.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/691/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/691/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/691/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/691/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/691/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/691/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/691/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/691/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/691/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/691/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/691/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/691/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/691/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/691/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=691&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2012/01/01/generic-type-factories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2012/01/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2012/01/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2012/01/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2012/01/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2012/01/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>Over-egging a Framework</title>
		<link>http://cockneycoder.wordpress.com/2011/12/29/over-egging-a-framework/</link>
		<comments>http://cockneycoder.wordpress.com/2011/12/29/over-egging-a-framework/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 23:16:19 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[framework design]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/?p=680</guid>
		<description><![CDATA[I was holding off on posting this, but read some other good blog posts which sort of went along similar lines to this so decided to post it now… What is a framework? Whenever you write a reasonably-sized application, you’ll probably end up writing some sort of bespoke “framework” in your application. When you start [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=680&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">I was holding off on posting this, but read some other good blog posts which sort of went along similar lines to this so decided to post it now…</p>
<h3 align="justify">What is a framework?</h3>
<p align="justify">Whenever you write a reasonably-sized application, you’ll probably end up writing some sort of bespoke “framework” in your application. When you start writing it, the idea sounds great up-front – you’ll write something that will save hours in future! No-one will have to worry about anything, the “framework” will take care of it all! You’ll talk about abstraction and encapsulation etc. etc.. and tell yourself it’s best practice to do it.</p>
<h3 align="justify">Developing Horizontally</h3>
<p align="justify">There’s just one problem with writing generic, catch-all frameworks – and that’s that more often than you think, it’ll be completely unnecessary. You’ll start by writing some business code. Then you’ll think to yourself, “Hmm, this bit of code seems like it’ll be useful to the team at some point in the future. Let’s write some helper classes and integrate it with our framework so other people can reuse this bit of code.”.</p>
<p align="justify">This is what is known as “horizontal development” i.e. developing frameworks and cross cutting concerns rather than developing business functionality.</p>
<p align="justify">The biggest problem with horizontal development is that often this code reuse never happens; you end up with abstract factories with just one or two types being returned, or whole class hierarchies being written when it would have been ten times quicker just to manually compose some classes together a few times. Even worse, sometimes you’ll guess wrongly how you’ll end up using the framework and end up boxing yourself into a corner and having rigid and viscous designs i.e. the framework blocks you from doing what you want, and you end up having to work around it.</p>
<h3 align="justify">Developing Vertically</h3>
<p align="justify">Developing vertically is the idea of developing features end-to-end that cut across all tiers, and developing just the part of every tier that you need to fulfil that feature; as you develop more features, your framework should naturally and organically evolve. You’ll refactor existing business logic to take advantage of your improved framework to make your code more succinct and easy to understand within the context of the domain. Your unit tests will protect you from breaking changes in your framework as you refactor and enhance it.</p>
<p align="justify">How do we go about doing this? I tend to strongly follow the Uncle Bob school of thought here, plus the 80/20 rule. This boils down to the following: -</p>
<p align="justify">Do you <em>know for a fact </em>that this bit of code is going to be reused, right now, somewhere else? If the answer is “no” – don’t do it. Wait until you need it the second time and then consider doing it then. You’ll be surprised with how many times you end up leaving things as-is. Obviously, it’s not black and white – if it’s fifty lines of code I’d be more inclined to refactor it into a reusable method / class than if it were one or two lines.</p>
<p align="justify">There are many examples of this sort of situation that you might come up against every day: -</p>
<ul>
<li>
<div align="justify">Having a constant in a method / class versus having a shared constants class / enum</div>
<li>
<div align="justify">Hard-coding something versus making some sort of generic / abstract factory</div>
<li>
<div align="justify">Using explicit / hard-coded values or classes versus abstracting it to the database (do you really need run-time configurability?)</div>
<li>
<div align="justify">Writing some screens that look similar versus writing a generic “control factory” that generates UI for you etc.</div>
</li>
</ul>
<p align="justify">In all these cases I would choose the simplest, cheapest option and only if I could prove through the codebase that we would benefit from abstracting the code away would I do it.</p>
<p align="justify">There’s one exception to this rule: when the cost of doing it later will be excessively high and would require a lot of effort to do retrospectively. Obviously this decision requires a judgement call on your part on an instance-by-instance basis as to whether it’s a real risk or not, and what the likelihood of it happening is. In such situations, I would either absorb the cost up front, or try to protect myself against this sort of thing where possible e.g. in the example above relating to a factory, a decent halfway-house might be to make a factory class but hard-code the implementation to always return the same type of object, so that you can easily expand it later without impacting lots of places.</p>
<h3 align="justify">Conclusion</h3>
<p align="justify">Whenever you are faced with this sort of situation, I always ask myself questions like: -</p>
<ul>
<li>
<div align="justify">What’s the cost/benefit of doing this?</div>
<li>
<div align="justify">Are we ever actually going to use this in the future, or is it just “in case”?</div>
<li>
<div align="justify">How discoverable will my framework classes be?</div>
<li>
<div align="justify">Am I going to document the framework and make it easily available to the rest of the team – otherwise there’s little point in having it.</div>
</li>
</ul>
<p align="justify">There’s always a cost of having duplicate code everywhere – but there’s also a cost of having a framework that’s unnecessarily complex.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/680/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/680/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/680/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/680/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/680/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/680/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/680/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/680/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/680/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/680/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/680/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/680/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/680/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/680/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=680&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2011/12/29/over-egging-a-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting creative with IDisposable Part 2</title>
		<link>http://cockneycoder.wordpress.com/2011/12/28/getting-creative-with-idisposable-part-2/</link>
		<comments>http://cockneycoder.wordpress.com/2011/12/28/getting-creative-with-idisposable-part-2/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 16:26:27 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aop]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[idisposable]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/?p=671</guid>
		<description><![CDATA[In my last post, I gave some examples of how we can use the IDisposable interface in conjunction with the using statement to implement an on/off pattern wrapping around some critical region of code, even though there is no “disposable resource” involved. Problems with using IDisposable In this post I want to expand on the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=671&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">In my last post, I gave some examples of how we can use the IDisposable interface in conjunction with the using statement to implement an on/off pattern wrapping around some critical region of code, even though there is no “disposable resource” involved.</p>
<h3 align="justify">Problems with using IDisposable</h3>
<p align="justify">In this post I want to expand on the previous examples to illustrate a more general solution to that problem. In the previous post, all the examples implemented IDisposable directly in order to participate in the using statement. However, there are reasons why you might not wish to have this coupling: -</p>
<ol>
<li>
<div align="justify">Having a type implement IDisposable that has nothing to do with reclaiming of resources is somewhat misleading e.g. changing the console colour or the cursor icon. This is not what IDisposable was created for and can lead to confusion.</div>
<li>
<div align="justify">We may not always want to call the “on” action on construction of the object; perhaps we want to use it in other scenarios.</div>
<li>
<div align="justify">Compile-time tools such as Code Analysis and Coderush etc. may complain if you do not implement IDisposable in the “proper” way (with the Boolean overload) etc.</div>
</li>
</ol>
<h3 align="justify">ISwitchable</h3>
<p align="justify">There’s a way around this by making a new interface which I call ISwitchable, which is implemented by any classes that we want to use within the Using statement yet don’t want to implement IDisposable on (for the reasons outlined above).</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image11.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;margin-left:0;margin-right:0;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb11.png?w=273&#038;h=123" width="273" height="123"></a></p>
<p align="justify">Obviously, when we call “On” we’ll do the “on construction” action, and “off” will do the equivalent of the “Dispose()” call.</p>
<h3>
<ul>The DisposableAdapter</ul>
</h3>
<p>So, how do we use ISwitchable within the context of the Using statement? Well, we can’t directly &#8211; obviously the using statement only works with IDisposable &#8211; so we use the <a href="http://en.wikipedia.org/wiki/Adapter_pattern">Adapter pattern</a>. This pattern shows how we can “massage” an object implementing one interface into another interface – in our case, from ISwitchable to IDisposable. We therefore create an adapter class which takes in an object that is of type ISwitchable and adapts it to work with IDisposable: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/classdiagram11.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="ClassDiagram1" border="0" alt="ClassDiagram1" src="http://cockneycoder.files.wordpress.com/2011/12/classdiagram1_thumb1.png?w=660&#038;h=418" width="660" height="418"></a></p>
<p align="justify">And here’s a (cut-down) version of the code for the adapter. All it does it delegate calls from the constructor to On, and Dispose to Off: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image14.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image14_thumb.png?w=607&#038;h=427" width="607" height="427"></a></p>
<p align="justify">Then we use it as follows, with the results below: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image13.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb13.png?w=456&#038;h=270" width="456" height="270"></a></p>
<ul>
<li>
<div align="justify"><strong>CodeTimer</strong> simply starts a Stopwatch on On, and stops it (and outputs the time) when Off is called.</div>
<li>
<div align="justify"><strong>ConsoleColourInverter</strong> swaps the foreground and background console colours whenever On and Off are called.</div>
</li>
</ul>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image101.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image10_thumb.png?w=215&#038;h=125" width="215" height="125"></a></p>
<p align="justify">So, we get two of these switchable “behaviours” applied onto our code; they start automatically, and then remove themselves once the using statement goes out of scope (as can be seen by the timer finishing and the console colour resetting itself). We don’t have to worry about exceptions either in the sense that because this is in a using statement, the finally block will automatically call dispose on both DisposableAdapter instances, which in turn delegate to the ISwitchable’s Off() method.</p>
<h3 align="justify">Conclusion</h3>
<p align="justify">This is kind of reminiscent of aspect-oriented programming i.e. we’re applying a set of behaviours around some code and letting them do the work without us getting involved. Through the use of the Adapter pattern we have completely decoupled ourselves from IDispose, and with some use of generics are able to use these switchable objects within the context of a using statement pretty succinctly.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/671/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/671/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/671/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/671/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/671/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/671/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/671/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/671/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/671/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/671/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/671/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/671/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/671/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/671/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=671&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2011/12/28/getting-creative-with-idisposable-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb11.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/classdiagram1_thumb1.png" medium="image">
			<media:title type="html">ClassDiagram1</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image14_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb13.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image10_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting creative with IDisposable Part 1</title>
		<link>http://cockneycoder.wordpress.com/2011/12/27/getting-creative-with-idisposable-part-1/</link>
		<comments>http://cockneycoder.wordpress.com/2011/12/27/getting-creative-with-idisposable-part-1/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 11:59:43 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aop]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[idisposable]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/?p=647</guid>
		<description><![CDATA[It occurred to me it might be interesting to describe some of the more unconventional uses of IDisposable that can help to make your code more readable, and even apply a kind of AOP-style coding to your code. MSDN describes IDisposable as follows: - Defines a method to release allocated resources. In the remarks section [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=647&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It occurred to me it might be interesting to describe some of the more unconventional uses of IDisposable that can help to make your code more readable, and even apply a kind of AOP-style coding to your code. MSDN describes <a href="http://msdn.microsoft.com/en-us/library/system.idisposable.aspx">IDisposable</a> as follows: -</p>
<blockquote><p>Defines a method to release allocated resources.</p>
</blockquote>
<p>In the remarks section it states this: -</p>
<blockquote><p>The primary use of this interface is to release unmanaged resources. The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used. However, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and stream</p>
</blockquote>
<p>However, there is a secondary use for this interface which has absolutely nothing to do with the GC or memory allocation etc.. It comes into being because of the way that the “using” statement works in C#, which behind the scenes, simply calls Dispose() for us once the using statement goes out of scope (in a finally block). We can use this to our advantage in a number of situations where you want have the following behaviour: -</p>
<ol>
<li>Turn on something
<li>Do some code utilising that something
<li>Turn it off again</li>
</ol>
<ol>Consider the following (contrived) example – we’re in a dark room and want to write out some text on a keyboard; in order to do that we need to turn on the light whilst we’re typing, and then turn it off when we’re finished: -</ol>
<p><a href="http://cockneycoder.files.wordpress.com/2011/12/image6.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb6.png?w=614&#038;h=309" width="614" height="309"></a>
<p>&nbsp;</p>
<p><a href="http://cockneycoder.files.wordpress.com/2011/12/image7.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb7.png?w=260&#038;h=225" width="260" height="225"></a></p>
<p>A more elegant way might be as follows: -</p>
<p><a href="http://cockneycoder.files.wordpress.com/2011/12/image8.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb8.png?w=595&#038;h=153" width="595" height="153"></a></p>
<p>This is a much more readable version of code; it’s implied from the using statement what the scope of the light is. All we have to do is implement IDisposable on our Light class, and on the constructor and Dispose call the appropriate methods (bear in mind that Dispose gets called automatically once the using statement goes out of scope).</p>
<p><a href="http://cockneycoder.files.wordpress.com/2011/12/image9.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb9.png?w=313&#038;h=161" width="313" height="161"></a></p>
<p>Easy. There are many situations where this pattern could be applied that have nothing to do with managed resources: -</p>
<ul>
<li>Temporarily changing the console colour and then having it go back to what it was
<li>Changing the mouse pointer to an egg-timer whilst doing some time-consuming operation and when it completes resetting it
<li>Starting a Stopwatch when an operation starts and stopping it when it completes
<li>Changing some settings on your UI e.g. writeable / read-only etc. when in a particular application state etc.</li>
</ul>
<ul>In short, anywhere that you want to “temporarily” set the state of something and then reset it again. You can also chain them up: -</ul>
<p><a href="http://cockneycoder.files.wordpress.com/2011/12/image10.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb10.png?w=612&#038;h=204" width="612" height="204"></a>
<p>Nice. In my second post, I’ll discuss a way of generalising this class of problem and how we can decouple ourselves from IDisposable yet still retain the benefits of the using statement.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/647/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=647&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2011/12/27/getting-creative-with-idisposable-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb10.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>The cost of creating Expression Trees</title>
		<link>http://cockneycoder.wordpress.com/2011/12/26/the-cost-of-creating-expression-trees/</link>
		<comments>http://cockneycoder.wordpress.com/2011/12/26/the-cost-of-creating-expression-trees/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 16:48:59 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[expression trees]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/?p=620</guid>
		<description><![CDATA[First, merry xmas etc. etc.. Second – expression trees. I just wanted to post a short blog about the actual cost of creating trees that can be illustrated by comparing the following two code samples: - See the difference? Rather than creating the expression inline of the for loop (Sample A), we create it once [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=620&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">First, merry xmas etc. etc..</p>
<p align="justify">Second – expression trees. I just wanted to post a short blog about the actual cost of creating trees that can be illustrated by comparing the following two code samples: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb.png?w=497&#038;h=119" width="497" height="119"></a></p>
<p align="justify">
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb1.png?w=492&#038;h=137" width="492" height="137"></a></p>
<p align="justify">See the difference? Rather than creating the expression inline of the for loop (Sample A), we create it once outside the for loop and reuse it for all iterations (Sample B). (FYI: <strong>ParseExpression()</strong> does absolutely nothing – it’s just there as a means to an end). Here’s the timing results for 1,000,000 loops: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb2.png?w=320&#038;h=103" width="320" height="103"></a></p>
<p align="justify">Running the performance tuning wizard against this shows us some cheeky reflection calls behind-the-scenes which even brings up a performance warning: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image5.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb5.png?w=644&#038;h=159" width="644" height="159"></a></p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image4.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image_thumb4.png?w=653&#038;h=36" width="653" height="36"></a></p>
<p align="justify">The lesson to be learned? Expression Trees are an extremely useful tool in your arsenal – and can be used to give big performance gains over e.g. reflection or even dynamic, but ensure that you cache the expressions themselves otherwise the cost of creating the tree can outweigh the benefits gained from them.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/620/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/620/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/620/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/620/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/620/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/620/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/620/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/620/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/620/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/620/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/620/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/620/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/620/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/620/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=620&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2011/12/26/the-cost-of-creating-expression-trees/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Namespaces, namespaces and more namespaces</title>
		<link>http://cockneycoder.wordpress.com/2011/12/13/namespaces-namespaces-and-more-namespaces/</link>
		<comments>http://cockneycoder.wordpress.com/2011/12/13/namespaces-namespaces-and-more-namespaces/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 22:08:02 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[framework design]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/?p=608</guid>
		<description><![CDATA[Some random thoughts and suggestions follow regarding how you design the namespaces that your classes fit into when writing APIs that other developers will utilise. Many of these points I’ve recently been dealing with myself whilst having a team of developers joining a team I’m working in; when documenting some of the API and framework, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=608&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Some random thoughts and suggestions follow regarding how you design the namespaces that your classes fit into when writing APIs that other developers will utilise.</p>
<p align="justify">Many of these points I’ve recently been dealing with myself whilst having a team of developers joining a team I’m working in; when documenting some of the API and framework, I realised that it was not as easily discoverable or navigable as it could be; the next time I work on a reusable API, I’ll bear these points in mind more. I’d also recommend having a read of <a href="http://www.amazon.co.uk/Framework-Design-Guidelines-Conventions-ebook/dp/B0017SWPNO">Framework Design Guidelines</a>, which I read not too long ago and really opened my eyes in a number of ways to framework design.</p>
<ul>
<li>
<div align="justify"><strong>Make your classes discoverable</strong>. I can’t stress this enough. The namespaces of your API should be easy to navigate, logically laid out and as readable as possible. Put yourself in the shoes of another developer who types <strong>MyApplication.</strong> in Visual Studio. When they press that “.” key, Intellisense is going to pop up and show them the different areas they can look through. This needs to be as clear as possible in order to guide them through the API; when I start trying out a new API, Intellisense is my first port of call – I certainly don’t start by reading all the documentation on every class.</div>
</li>
<li>
<div align="justify"><strong>Distinguish between 80/20 classes</strong>. It’s tempting to simply place all your classes that fulfil a particular function into a single namespace, but this often doesn’t help the developer. Instead, consider making a sub-namespace which contains more advanced features or classes (used 20% of the time) and keep the more common ones (used 80% of the time) at the higher, more easily discoverable, namespace. Also be strict regarding encapsulation – don’t make classes / methods / properties etc. public unless you need to.</div>
</li>
<li>
<div align="justify"><strong>Do <u>not</u> use department names in your namespace</strong>. Physical departments are always changing. At the end of the day they usually really have nothing to do with your API. If your department is restructured or renamed, will your code magically stop working? I would even go as far as to say for internal applications, do not include the company name either – what’s the point.</div>
</li>
<li>
<div align="justify"><strong>Beware of rigidly following the “namespace must be a child of the assembly name rule”</strong>. If we had an assembly called e.g. “MyApplication.Framework”, all code in that assembly should theoretically go underneath the MyApplication.Framework namespace. However, as an API developer, you might want very frequent and popular classes not to be buried away underneath the Framework level – you might want a developer to simply type “MyApplication.” and see the 4 or 5 most important classes that your API has to offer because that’s all that they might need most of the time. Indeed, they might have nothing to do with one another in terms of functionality – perhaps one is to do with logging, another to do with eventing etc.. It might sometimes be better to have an assembly which does not following the System.Subsystem.BlaBla naming convention and instead is simply called “BlaBla” – you’re not implying a namespace from this so are free to put stuff in any namespace.</div>
</li>
<li>
<div align="justify"><strong>Don’t be concerned with file navigation</strong>. Don’t worry that the developer cannot infer at a glance what assembly a particular class lives in. They can hit F12 and be transported to the source code (or metadata) of the class immediately; they can use Solution Navigator to find the file, or have Solution Explorer follow the active file etc.. That should not be your main concern when designing your API.</div>
</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/608/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/608/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/608/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=608&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2011/12/13/namespaces-namespaces-and-more-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>
	</item>
		<item>
		<title>Performance or readability with Expression Trees in C#</title>
		<link>http://cockneycoder.wordpress.com/2011/11/19/performance-or-readability-with-expression-trees-in-c/</link>
		<comments>http://cockneycoder.wordpress.com/2011/11/19/performance-or-readability-with-expression-trees-in-c/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 15:58:16 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[expression trees]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/?p=604</guid>
		<description><![CDATA[I was fumbling around trying to create some expression trees on Friday and was working through some stuff with a colleague of mine (someone who actually knows how to do it better than me!) and I got to thinking about the characteristics of different ways of doing the same things in C# with respect to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=604&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">I was fumbling around trying to create some expression trees on Friday and was working through some stuff with a colleague of mine (someone who actually knows how to do it better than me!) and I got to thinking about the characteristics of different ways of doing the same things in C# with respect to both runtime performance and readability / ease of development.</p>
<p align="justify">Let’s say we have the following type hierarchy:</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/11/image5.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/11/image_thumb5.png?w=355&#038;h=253" width="355" height="253"></a></p>
<p align="justify">Easy enough. Now we want, for some arbitrary reason, to write a generic method that will set a specific integer property to the value of 25, but we don’t know which one it is. In our example above, that could be both the Age of the employee, or the AddressId. You could do this with reflection: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/11/image6.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/11/image_thumb6.png?w=648&#038;h=104" width="648" height="104"></a></p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/11/image7.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/11/image_thumb7.png?w=426&#038;h=65" width="426" height="65"></a></p>
<p align="justify">
<p align="justify">
<p align="justify">
<h2 align="justify">Expression Trees</h2>
<p align="justify">Nice. This works well, no problems whatsoever. There is another, strongly typed way of doing it though, with expression trees. By passing in an expression tree that navigates to that property, we can, at runtime, construct a Action method specific to what we want, and then call that method as needed. Here’s how we would consume such a method: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image56.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image56_thumb.png?w=660&#038;h=112" width="660" height="112"></a></p>
<p align="justify">ageSetter and addressIdSetter are two delegates that we are constructing <em>at runtime </em>to perform the task of setting the appropriate property to the value of 25. The main benefit of such an approach is obvious i.e. strong typing. But there’s another, more subtle benefit of such an approach – performance. To understand why this is, we need to understand how this method is implemented.</p>
<p align="justify">CreatePropertySetter returns an Action&lt;T&gt; which, when called, will set the appropriate property to 25: (I’ve elided the GetMembersEnumerator method for clarity)</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image43.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image43_thumb.png?w=660&#038;h=293" width="660" height="293"></a></p>
<p align="justify">
<p align="justify">
<p align="justify">To make it a bit easier to see what happens, when we call the method with e =&gt; e.Age, here’s what the above method looks like with debugger quickwatches pinned: -</p>
<p align="justify"><a href="http://cockneycoder.files.wordpress.com/2011/12/image48.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://cockneycoder.files.wordpress.com/2011/12/image48_thumb.png?w=660&#038;h=250" width="660" height="250"></a></p>
<p align="justify">By compiling the final expression, we get a proper Action method which is the same as <strong>instance =&gt; instance.Age = 25</strong>, except we’ve constructed this code, at runtime.</p>
<p align="justify">I find Expression Trees difficult to get my head around. I understand the idea of them – essentially building up a tree of things like “assign property” and “call method” and “if” etc. which can then be compiled into a lambda. But the Expression API has lots of factory methods and many ways to do the same thing; I guess with time you gain familiarity with the API, but it’s definitely not the easiest thing in the world to get your head around. Worse still, look at the code required to do the same thing as that reflection code – much more effort and much less readable.</p>
<p align="justify">However, where performance is concerned, Expression Trees will beat Reflection by miles – <em>as long as you cache the Action method that is generated</em>! The construction and parsing of the expression trees required to create the Action is an expensive operation, so you should cache the Actions. Once you’ve done that, the cost is extremely low, as you are simply calling an action method, almost the same as if you had written it yourself. For example, to set both the Age and AddressId properties to 25, for 2.5 million Employees, I observed the following timings: -</p>
<p align="justify">
<table border="0" cellspacing="0" cellpadding="2" width="324">
<tbody>
<tr>
<td valign="top" width="167"><strong>Type of code applied</strong></td>
<td valign="top" width="155" align="right"><strong>Time required (ms)</strong></td>
</tr>
<tr>
<td valign="top" width="167">Direct assignment</td>
<td valign="top" width="155" align="right">
<p align="right">144</p>
</td>
</tr>
<tr>
<td valign="top" width="167"><strong>Reflection</strong></td>
<td valign="top" width="155" align="right">
<p align="right"><strong>3,881</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="167"><strong>Expression Trees</strong></td>
<td valign="top" width="155" align="right">
<p align="right"><strong>349</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="167">Dynamic </td>
<td valign="top" width="155" align="right">
<p align="right">597</p>
</td>
</tr>
<tr>
<td valign="top" width="167">Hard-coded lambdas</td>
<td valign="top" width="155" align="right">
<p align="right">136</p>
</td>
</tr>
</tbody>
</table>
<p align="justify">Obviously the other three options wouldn’t be appropriate for the problem at hand (generic property assignment) but I wanted to illustrate how these two mechanisms performed. By the way &#8211; notice how much quicker dynamic is than reflection (and these timings were obtained when caching the property info objects as well). Funnily enough, if I wrote hard coded lambdas e.g. <strong>instance =&gt; instance.Age = 25</strong> and used them, they outperformed code like <strong>instance.Age = 25</strong>. Why?</p>
<p align="justify">
<h2 align="justify">Conclusion</h2>
<p align="justify">When you next use reflection for some property assignments or method calls, think about using Expression Trees, particularly where performance is a factor. Expression Trees are time consuming to write and understand, but offer superior performance and can be consumed in a strongly-typed manner. Alternatively, consider the use of dynamic where possible – again, for property setters and getters and method calls it offers better performance than reflection, and whilst obviously not strongly-typed, the code is again far more readable.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/604/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=604&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2011/11/19/performance-or-readability-with-expression-trees-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/11/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/11/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/11/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image56_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image43_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/12/image48_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>C# interviewing standards</title>
		<link>http://cockneycoder.wordpress.com/2011/11/15/interviewing-standards/</link>
		<comments>http://cockneycoder.wordpress.com/2011/11/15/interviewing-standards/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 22:55:44 +0000</pubDate>
		<dc:creator>Isaac Abraham</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[interviewing]]></category>

		<guid isPermaLink="false">https://cockneycoder.wordpress.com/2011/11/15/interviewing-standards/</guid>
		<description><![CDATA[Before I start, this isn’t an “elitist” rant of mine! Now that that’s out of the way… One thing that often gets on my nerves when interviewing developers is when people rate themselves out of 5 for a particular technology. Generally people tend to rate themselves on the following scale: - 3: I have used [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=591&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<ul>
<p align="justify">Before I start, this isn’t an “elitist” rant of mine! Now that that’s out of the way…</p>
<p align="justify">One thing that often gets on my nerves when interviewing developers is when people rate themselves out of 5 for a particular technology. Generally people tend to rate themselves on the following scale: -</p>
</ul>
<ul>
<li>
<div align="justify"><strong>3</strong>: I have used this technology a few times and know what it is.</div>
<li>
<div align="justify"><strong>4</strong>: I have used it on at least one project before.</div>
<li>
<div align="justify"><strong>5</strong>: I have been using it for a while and think that I know it to the fullest.</div>
</li>
</ul>
<ul>
<p align="justify">There is no 1/5 or 2/5 of course. No-one ever gives themselves 1 for a technology on their CV (after all, why bother saying you’re crap at something). And the worst part is, all this rating does is show how much you <em>know that you don’t know</em> in the subject matter. Let’s take C# as an example. Someone might know the following: -</p>
</ul>
<ul>
<li>
<div align="justify">how to create and use generic collections, and understand the benefits from a usability point of view over ArrayList</div>
<li>
<div align="justify">how to use e.g. foreach loops and basic flow control</div>
<li>
<div align="justify">they might know how to use LINQ queries on a LINQ-to-SQL data context</div>
</li>
</ul>
<p align="justify">However, they may not be aware of: -</p>
<ul>
<li>
<div align="justify">how to create their own generic classes, or how generics work underneath</div>
<li>
<div align="justify">what is the yield keyword and how it can be of use</div>
<li>
<div align="justify">what is the difference between IEnumerable and IQueryable, or what an expression tree is</div>
</li>
</ul>
<ul>
<p align="justify">That’s all fine. But as far as this person is aware, they’re a 5/5 C# developer because they <em>aren’t even aware </em>of what they are missing out on. Perhaps they give themselves a 4/5 “just in case” there’s a keyword that they might have missed <img style="border-style:none;" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://cockneycoder.files.wordpress.com/2011/11/wlemoticon-winkingsmile.png?w=600"> Whenever I interview people, I’d much rather someone give themselves a 2 or 3 out of 5 and be honest about it – or perhaps surprise us with what they know – rather than big themselves up and then fall at the first hurdle. All that does personally is fill me with suspicion – after all, if they’ve given themselves a 5/5 for something and been caught out so quickly, all the other aspects of their CV should be treated with the same suspicion.</p>
<p align="justify">My personal advice would be that unless you can back it up, <strong>don’t do it</strong>. <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://cockneycoder.files.wordpress.com/2011/11/wlemoticon-smile.png?w=600"></p>
<p>For what it’s worth – and I don’t consider myself an expert in it – here’s the <em>sort</em> of things I would look for if someone rates themselves out of 5 in C# (note I have tried not to mention things like design patterns etc. etc., but rather just knowledge of the language itself, and I suppose its relationship with .NET as well): -</ul>
<ul>
<li>
<div align="justify"><strong>1/5</strong>: Understanding of basic control flow; try/catch statements; methods and&nbsp; overloading; difference between static and instance members; properties; levels of encapsulation; object scope.</div>
<li>
<div align="justify"><strong>2/5</strong>: Able to explore and consume new simple APIs with little guidance. Consume and understand generic methods and classes; can create standard LINQ queries and consume IEnumerables / IQueryables. Good understanding of value and reference types, boxing and disposing of objects. Good understanding of object lifetime and the GC. Understands Reflection and its pros/cons.</div>
<li>
<div align="justify"><strong>3/5</strong>: Deep understanding of generics. Good understanding of the components of C#3 e.g. Extension methods, lambdas, expression trees etc. Comfortable with usage of Action&lt;T&gt; and Func&lt;T&gt;. Understanding of multi-threaded processes.</div>
<li>
<div align="justify"><strong>4/5</strong>: Good understanding of the role of the compiler in C# and its relationship with the .NET runtime. Good understanding of yield keyword. Understanding of closures. Knowledge of Task&lt;T&gt; and it’s relationship with threads. Understanding of dynamic, both in consumption and the underlying technology.</div>
<li>
<div align="justify"><strong>5/5</strong>: Expert level in nearly all areas e.g. compiler behaviour, memory allocation, expression trees, GC behaviour etc. etc. Perhaps your name is Eric Lippert, Anders Hejlsberg or Mads Torgersen etc. etc.?</div>
</li>
</ul>
<p align="justify">I guess even someone like those individuals that I mention don’t know “everything” and the language because C# and it’s relationship with .NET is now so vast, and so complex, that no-one could possibly know the intricacies of every component of the language.</p>
<p align="justify">Now, I bet that people could write some great systems with just a 2/5 or 3/5. I would also say that there is little relationship between someone writing fault tolerant, readable and maintainable code and their knowledge of the language. All it means is that you have more tools at your disposal when faced with a problem; the challenge is knowing when to use the right one for the job at hand.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cockneycoder.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cockneycoder.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cockneycoder.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cockneycoder.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cockneycoder.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cockneycoder.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cockneycoder.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cockneycoder.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cockneycoder.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cockneycoder.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cockneycoder.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cockneycoder.wordpress.com/591/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cockneycoder.wordpress.com/591/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cockneycoder.wordpress.com/591/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cockneycoder.wordpress.com&amp;blog=14652090&amp;post=591&amp;subd=cockneycoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cockneycoder.wordpress.com/2011/11/15/interviewing-standards/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dc2491777fca22a04ef50d0b11eec756?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">isaaca</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/11/wlemoticon-winkingsmile.png" medium="image">
			<media:title type="html">Winking smile</media:title>
		</media:content>

		<media:content url="http://cockneycoder.files.wordpress.com/2011/11/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
	</channel>
</rss>
