<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">

<channel>
	<title>YTechie - C#, ASP.NET, and Adobe Flex Blog</title>
	
	<link>http://www.ytechie.com</link>
	<description>Productive software development using ASP.NET, C#, and Adobe Flex</description>
	<pubDate>Thu, 25 Jun 2009 18:08:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Ytechie" type="application/rss+xml" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">Ytechie</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FYtechie" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FYtechie" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FYtechie" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://feeds.feedburner.com/Ytechie" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FYtechie" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FYtechie" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FYtechie" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Delayed execution vs ToList() in LINQ Database Queries</title>
		<link>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html</link>
		<comments>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html#comments</comments>
		<pubDate>Tue, 23 Jun 2009 16:46:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.net]]></category>

		<category><![CDATA[LINQ]]></category>

		<category><![CDATA[entity framwork]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html</guid>
		<description><![CDATA[LINQ to SQL and Entity framework allow us to build a query, which gets translated into an expression tree, and executed once the full query is built. The beauty is that we can build up a query using multiple expressions and Lambdas, without actually querying the data. Since these types of queries are delay loaded, [...]]]></description>
			<content:encoded><![CDATA[<p>LINQ to SQL and Entity framework allow us to build a query, which gets translated into an expression tree, and executed once the full query is built. The beauty is that we can build up a query using multiple expressions and Lambdas, without actually querying the data. Since these types of queries are delay loaded, why not avoid executing them until the last possible moment? Read on to see why this is usually a bad idea.</p>
<p>First, let’s take a look the code for a repository method that builds a query, executes the query, and returns the results in a list:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:3a31321f-f9b9-4c17-91c2-43d838b3f22a" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">public IEnumerable&lt;Cat&gt; FindAllCats()
{
	var query = from c in db.Cats
		select c;

	return query.ToList();
}</pre>
</div>
<p align="center"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Execute in Repository" border="0" alt="Execute in Repository" src="http://www.ytechie.com/post-images/2009/06/image1.png" width="486" height="142" /> </p>
<p>The “ToList” is forcing the IQueryable&lt;Cat&gt; query to execute and put the results in a list <strong>immediately</strong>. However, we know that IQueryable&lt;T&gt; inherits from IEnumerable&lt;T&gt;, so what happens if we avoid the list creation completely?</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:10d24797-5a70-435a-85bc-c076fe3c457b" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">public IEnumerable&lt;Cat&gt; FindAllCats()
{
	var query = from c in db.Cats
		select c;

	return query;
}</pre>
</div>
<p align="center"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Execute in UI" border="0" alt="Execute in UI" src="http://www.ytechie.com/post-images/2009/06/image2.png" width="486" height="142" /></p>
<p align="left">In this scenario, our method is returning the same interface, but the underlying type is now a LINQ database iterator instead of a List&lt;T&gt;.</p>
<p><strong>Delaying execution can lead to</strong> <strong><em>multiple</em></strong> <strong>executions</strong></p>
<p>If the code is not explicitly putting the results into a list, we’re actually passing back a form of an iterator. This works great if we only need to execute the query once. However, if we iterate through the list more than once, <strong>we actually end up executing our query multiple times</strong>. This can obviously lead to poor performance.</p>
<p>If you’re writing fast queries, you may not even notice if they’re being called too many times. However, there may be a worse problem lurking in your code. <strong>Each time you iterate through the enumerator, you’re getting a different set of objects</strong>. The same query is being made with the same results, but the objects are re-built each time. This leads to objects that are <strong>equivalent, but not the same</strong>. For example, you may get back Cat objects with the names “Bill” and “Ted”, but if you actually check them for equality using “==”, they will not be the same object <strong>instance</strong>. <font color="#ff0000"><strong>Correction: Scott points out in the comments that this isn’t necessarily the case. Keep in mind that it can still occur if projecting types and not working with the original objects.</strong></font></p>
<p><strong>Delaying execution may mean you no longer have a database connection when attempting to execute the query</strong></p>
</p>
<p>If you delegate the task of initiating your query to another layer, you better be sure that the database connection is still around, and is in a queryable state. If you’re using the standard repository pattern and a short-lived database connection pattern, you may quickly run into problems when you try to iterate through the results of the enumerator you receive from your repository layer.</p>
<p><strong>Conclusion</strong></p>
<p>If you’re thinking about moving the execution of your queries to another layer, make sure you understand the consequences. You’ll need to weigh those consequences against the tiny benefit that you’ll receive from the delayed execution. There may be cases where delaying the execution or possibly avoiding it completely will improve your application, but those are probably very rare cases.</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/fwUif-yxxow" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/06/delayed-execution-vs-tolist-in-linq-database-queries.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Common Pitfalls when working with DateTime’s</title>
		<link>http://www.ytechie.com/2009/06/common-pitfalls-when-working-with-datetimes.html</link>
		<comments>http://www.ytechie.com/2009/06/common-pitfalls-when-working-with-datetimes.html#comments</comments>
		<pubDate>Tue, 02 Jun 2009 19:05:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.net]]></category>

		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/06/common-pitfalls-when-working-with-datetimes.html</guid>
		<description><![CDATA[In .NET, the DateTime structure provides us wonderful functionality, but this seemingly simple structure can cause a lot of headaches if you don’t fully understand how to use it properly.
 
Understand the terminology
First, UTC, GMT, and even Zulu time are all the same thing. They’re basically a universal time clock that is not subject to [...]]]></description>
			<content:encoded><![CDATA[<p>In .NET, the <a href="http://msdn.microsoft.com/en-us/library/system.datetime.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/system.datetime.aspx?referer=');">DateTime</a> structure provides us wonderful functionality, but this seemingly simple structure can cause a lot of headaches if you don’t fully understand how to use it properly.</p>
<p align="center"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Clock" border="0" alt="Clock" src="http://www.ytechie.com/post-images/2009/06/clock.jpg" width="244" height="163" /> </p>
<p><strong>Understand the terminology</strong></p>
<p>First, UTC, GMT, and even Zulu time are all the same thing. They’re basically a universal time clock that is not subject to changes in time zones or time changes. Each tick of the universal clock represents a moment in our perception of time. </p>
<p><strong>Use UTC as long as possible</strong></p>
<p><strong>UTC</strong> is very useful when developing software because it removes the need to know where the time was from, or where it’s going to be used. We don’t even care <em>when</em> it was from, or <em>when</em> we’re displaying it. You can think of your <strong>local</strong> clock as a view of the time right now, where you are. It has already taken into account the time zone and daylight savings time.</p>
<p>These properties of your local clock suggest that we should always convert from the local clock to universal time as early as possible when accepting user input, and convert it back to the users time only when displaying it. This is a simple, easy to use pattern that may be enough to avoid some of the potential problems that other projects face. This pattern will give you the ability to cope with time changes and time zones much more easily.</p>
<p>Converting between local time and UTC is pretty easy. <a href="http://msdn.microsoft.com/en-us/library/system.datetime.tolocaltime.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/system.datetime.tolocaltime.aspx?referer=');">ToLocalTime</a> will convert from universal time to local time. <a href="http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx?referer=');">ToUniversalTime</a> will convert to UTC. Just be aware that these methods have a certain amount of logic in them that only has the rules that were in effect when they were written. They are not perfect for all scenarios. You’ll also want to take a look at the <a href="http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx?referer=');">Kind</a> property, which affects which conversions you can perform, as well as providing a nice way to keep track of whether or not he time has been adjusted to UTC.</p>
<p><strong>Daylight Savings Time &amp; Time Changes</strong></p>
<p>Every year in many parts of the world, the time changes. Apparently the idea is to save gobs of money by using the sunlight more efficiently instead of using artificial lights. Unfortunately, this really sucks for software developers.</p>
<p>I used to write software for manufacturing facilities that would run during a time change. If you have software that records and time-sensitive data during a time change, your software had better be prepared to handle it the fact that one hour is skipped, and another is repeated. Storing the data in UTC solves part of the problem. Unfortunately, when you try to display the data you’ll have an hour of missing data, and a hour with overlapping data. <strong>You may have to design your user interface to deal with this</strong>.</p>
<p><strong>Fixed-time Appointments</strong></p>
<p>Unfortunately, UTC doesn’t solve all of our time offset problems. Let’s say that you have an appointment that you’re scheduling for a future date that occurs when DST is in effect, but it’s not in effect right now. You choose 5:00am for your appointment time. Your application happily converts the time to UTC, and the reverse process expectedly yields the same result. The problem is, the time offset when the appointment occurs will be different than it is now. Daylight savings for the central time zone for example, switches between and offset of –5 and –6. This diagram attempts to visualize:</p>
<p align="center">&#160;<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DST DateTime Diagram" border="0" alt="DST DateTime Diagram" src="http://www.ytechie.com/post-images/2009/06/image.png" width="476" height="260" /> </p>
<p>What we want to store is the fact that our appointment occurs at <strong>5:00am local time</strong>. If we simply store the information as UTC, we’re losing this additional information. When we switch to <strong>non-DST</strong> time and use our current time adjustment of <strong>–6 hours</strong>, our appointment now occurs at <strong>4:00am</strong>.</p>
<p>If you’re writing an application that stores fixed-time appointments as well as appointments that are designed to have even intervals (exactly 1 month apart, etc) or occur in a different time zone or DST, you’ll need to store an additional flag with the event so you can make the determination if it needs to be adjusted.</p>
<p><strong>Conclusion</strong></p>
<p>Times can be complicated depending on the requirements of your project. It would be unwise to work these problems out toward the end of a project, because the consistency of usage can’t be guaranteed. Do yourself a favor and plan ahead for these issues, and it will be much easier.</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/IABtGo1nfB8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/06/common-pitfalls-when-working-with-datetimes.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Tip for Technical Presentations – Detailed Notes</title>
		<link>http://www.ytechie.com/2009/05/tip-for-technical-presentations-detailed-notes.html</link>
		<comments>http://www.ytechie.com/2009/05/tip-for-technical-presentations-detailed-notes.html#comments</comments>
		<pubDate>Mon, 18 May 2009 18:10:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/05/tip-for-technical-presentations-detailed-notes.html</guid>
		<description><![CDATA[Justin Etheredge over at CodeThinked is asking for tips for technical presentations. I can certainly relate to his experiences. Technical presentations, or any type of presentation for that matter, can be intimidating, difficult, and scary.
&#160; 
In my college days, I had to give a presentation in one of my information systems classes. I was pretty [...]]]></description>
			<content:encoded><![CDATA[<p>Justin Etheredge over at CodeThinked is <a href="http://www.codethinked.com/post/2009/05/18/A-Technical-Presenters-Journey-Part-1-Know-Your-Audience.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/www.codethinked.com/post/2009/05/18/A-Technical-Presenters-Journey-Part-1-Know-Your-Audience.aspx?referer=');">asking for tips for technical presentations</a>. I can certainly relate to his experiences. Technical presentations, or any type of presentation for that matter, can be intimidating, difficult, and scary.</p>
<p>&#160;<img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="Presentation" border="0" alt="Presentation" src="http://www.ytechie.com/post-images/2009/05/presentation.jpg" width="301" height="200" /> </p>
<p>In my college days, I had to give a presentation in one of my information systems classes. I was pretty arrogant back then (ok, I still am), so I thought it would be a piece of cake to just wing it. I could save time and look like a cool speaker all at the time time. The result was me getting in front of the class, having my face turn red, and basically say “uh” and “um” for 10 minutes. It was so bad that people actually began to laugh. It pains me to even write about it.</p>
<p>A semester later, I had to give another presentation to an even bigger class. I was so nervous I can’t even describe it. I spent hours upon hours making creating a “script” that I could simply read. The result was that I actually didn’t even use the script. I actually knew what the hell I was talking about and ended up using the script as a reference. I did a great job speaking!</p>
<p>So how do I prepare for presentations these days? I have detailed notes, formatted specifically for the presentation. On my slides, I always keep the number of bullet points per slide low, usually 4 or less. In my notes, I organize them by bullet point so that I can walk though them while I go over each bullet point. <strong>I try to balance simplify with detail. </strong>The notes have to be <strong>simple</strong> enough to read quickly, but <strong>detailed</strong> enough that I can just read them out loud if I lose focus and forget the purpose. Bolding keywords and phrases can help quickly identify the key concepts while still having a readable version if needed.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Slide with Notes" border="0" alt="Slide with Notes" src="http://www.ytechie.com/post-images/2009/05/image1.png" width="481" height="348" /> </p>
</p>
<p>I’ve seen many presentations where the speaker gets nervous and forgets what a slide or bullet point means. The usual remedy they employ is just reading the slide verbatim. Don’t let this happen to you. <strong>It is almost certain that you’ll forget a critical piece of information during your presentation. The trick is to be ready for it.</strong></p>
<p>In my most recent <a href="http://www.ytechie.com/2009/04/speaking-at-day-of-net-at-fox-valley-tech.html">presentation (on Unit Testing)</a>, I actually wrote a paper on the topic I was presenting on. This allowed me to get all of my thoughts in order, and get feedback from others. Once I actually had to put together the PowerPoint, that was the easy part. I was basically creating an outline from an existing document, and the details became my notes.</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/oXGKW8ihmeg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/05/tip-for-technical-presentations-detailed-notes.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Practical .NET Unit Testing – Free paper released</title>
		<link>http://www.ytechie.com/2009/04/practical-net-unit-testing-free-paper-released.html</link>
		<comments>http://www.ytechie.com/2009/04/practical-net-unit-testing-free-paper-released.html#comments</comments>
		<pubDate>Thu, 30 Apr 2009 13:04:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[software development]]></category>

		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/04/practical-net-unit-testing-free-paper-released.html</guid>
		<description><![CDATA[I’ve been working on a unit testing paper that sums up my experience in unit testing, and discusses some of the core information that I feel is important about the subject. It’s very much a work in progress, but I wanted to get it out sooner rather than later. I’ll be continuously updating it as [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been working on a unit testing paper that sums up my experience in unit testing, and discusses some of the core information that I feel is important about the subject. It’s very much a work in progress, but I wanted to get it out sooner rather than later. I’ll be continuously updating it as time goes on.</p>
<p><strong>Update: I updated the <a href="http://downloads.ytechie.com/Practical_.NET_Unit_Testing.pdf" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/downloads.ytechie.com/Practical_.NET_Unit_Testing.pdf?referer=');">PDF location</a> to one that doesn&#8217;t require registration.</strong></p>
<p align="center"><a href="http://downloads.ytechie.com/Practical_.NET_Unit_Testing.pdf" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/downloads.ytechie.com/Practical_.NET_Unit_Testing.pdf?referer=');"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Practical .NET Unit Testing" border="0" alt="Practical .NET Unit Testing" src="http://www.ytechie.com/post-images/2009/05/image.png" width="392" height="203" /></a></p>
<p align="left">There are some really great books out there about unit testing, but I think some of them are trying too hard to be long enough to be considered a “book”. I set out to create a document that fills the gap between the various snippets of information from blog posts, and the comprehensive books on the subject. If you’re interested in something a bit more in-depth, here are some great books on the subject:</p>
<ul>
<li>
<div><a href="http://www.amazon.com/gp/product/1933988274?ie=UTF8&amp;tag=ytechie-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=1933988274" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/www.amazon.com/gp/product/1933988274?ie=UTF8_amp_tag=ytechie-20_amp_linkCode=xm2_amp_camp=1789_amp_creativeASIN=1933988274&amp;referer=');">The Art of Unit Testing by Roy Osherove</a></div>
</li>
<li>
<div><a href="http://www.amazon.com/gp/product/0131495054?ie=UTF8&amp;tag=ytechie-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=0131495054" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/www.amazon.com/gp/product/0131495054?ie=UTF8_amp_tag=ytechie-20_amp_linkCode=xm2_amp_camp=1789_amp_creativeASIN=0131495054&amp;referer=');">xUnit Test Patterns by Gerard Meszaros</a></div>
</li>
</ul>
<p>The paper currently consists of 5 main sections:</p>
<ul>
<li>Why Write Unit Tests? </li>
<li>Unit Test Mechanics </li>
<li>Common Unit Testing Strategies </li>
<li>Designing for Testability </li>
<li>Advanced Techniques </li>
</ul>
<p>Here is a more complete snapshot of the current outline:</p>
<ul>
<li>Introduction </li>
<li>Unit Testing &amp; Managers </li>
<li>What Unit Tests Really Do </li>
<li>Types of Testing </li>
<li>Testing Framework </li>
<li>Test Runner </li>
<li>Unit Test Structure </li>
<li>Other Test Attributes </li>
<li>What is Refactoring? </li>
<li>Test Driven Development </li>
<li>Evolving Code </li>
<li>When Should You Write Unit Tests? </li>
<li>Test is for Functionality, Not Code! </li>
<li>The Constraints of Reality </li>
<li>Interfaces - Quick Overview </li>
<li>Using a Mocking Framework </li>
<li>Stubs </li>
<li>The Test Driven Design Paradox </li>
<li>Testing Under Pressure </li>
<li>Extracting Duplicate Logic </li>
<li>Modular Design Benefits </li>
</ul>
<p>So what are you waiting for? <a href="http://www.scribd.com/doc/14713003/Practical-NET-Unit-Testing" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/www.scribd.com/doc/14713003/Practical-NET-Unit-Testing?referer=');">Go check it out online instantly</a>, you can even <a href="http://downloads.ytechie.com/Practical_.NET_Unit_Testing.pdf" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/downloads.ytechie.com/Practical_.NET_Unit_Testing.pdf?referer=');">download it as a PDF</a> if you like. Is anything missing? Is anything just plain wrong? I’d love to hear your feedback.</p>
<p>Remember, if you want to hear more about unit testing, <a href="http://www.ytechie.com/2009/04/speaking-at-day-of-net-at-fox-valley-tech.html">I’ll be speaking in Northeast Wisconsin Saturday, May 9th</a>.</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/vY_DRzpubKU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/04/practical-net-unit-testing-free-paper-released.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Speaking at Day of .NET at Fox Valley Tech</title>
		<link>http://www.ytechie.com/2009/04/speaking-at-day-of-net-at-fox-valley-tech.html</link>
		<comments>http://www.ytechie.com/2009/04/speaking-at-day-of-net-at-fox-valley-tech.html#comments</comments>
		<pubDate>Tue, 28 Apr 2009 14:54:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.net]]></category>

		<category><![CDATA[software development]]></category>

		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/04/speaking-at-day-of-net-at-fox-valley-tech.html</guid>
		<description><![CDATA[If you’re interested in hearing about writing practical unit tests in .NET, I’ll be speaking at the Fox Valley .NET user group “Day of .NET” event May 9th! Here is the synopsis for your reading pleasure:
Want to learn how to write good automated unit tests that are beneficial both to the product/customer and to you [...]]]></description>
			<content:encoded><![CDATA[<p>If you’re interested in hearing about writing practical unit tests in .NET, I’ll be speaking at the <a href="http://fvnug.org" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/fvnug.org?referer=');">Fox Valley .NET user group</a> <a href="http://fvnug.org/dnn/DayOfNet/Schedule/tabid/62/Default.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/fvnug.org/dnn/DayOfNet/Schedule/tabid/62/Default.aspx?referer=');">“Day of .NET” event</a> May 9th! Here is the synopsis for your reading pleasure:</p>
<blockquote><p>Want to learn how to write good automated unit tests that are beneficial both to the product/customer and to you as a developer? See an overview of the mechanics of unit testing including the tools and frameworks available. You&#8217;ll see examples of how to test existing code, but you&#8217;ll also see practical examples of how seemingly un-testable code can be designed so that it can be tested with ease. Learn how test driven development and refactoring will improve the readability of your code, minimize debugging, and speed up development.</p>
</blockquote>
<p><a href="http://fvnug.org" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/fvnug.org?referer=');"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.ytechie.com/post-images/2009/04/image5.png" width="490" height="79" /></a> </p>
<p>If you’re anywhere near the Northeast Wisconsin area, stop in. It’s free!</p>
<p>I’ll be publishing both the presentation and a supporting 25+ page paper shortly, so make sure you’re <a href="http://feedproxy.google.com/Ytechie" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/feedproxy.google.com/Ytechie?referer=');">subscribed to my feed</a>.</p>
<p><a href="http://www.fvtc.edu/public/" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/www.fvtc.edu/public/?referer=');">Fox Valley Tech</a> is located at:     <br /><a href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=1825+N.+Bluemound+Drive,+Appleton+WI&amp;sll=37.0625,-95.677068&amp;sspn=1.468445,2.771301&amp;ie=UTF8&amp;z=15&amp;msa=0&amp;msid=107741674408312530799.000001120068a94c2e438" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/maps.google.com/maps?f=q_amp_source=s_q_amp_hl=en_amp_geocode=_amp_q=1825+N.+Bluemound+Drive_+Appleton+WI_amp_sll=37.0625_-95.677068_amp_sspn=1.468445_2.771301_amp_ie=UTF8_amp_z=15_amp_msa=0_amp_msid=107741674408312530799.000001120068a94c2e438&amp;referer=');">1825 N. Bluemound</a>     <br />Appleton, WI 54912</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/4tE79oWy4F4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/04/speaking-at-day-of-net-at-fox-valley-tech.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>int inherits from object? An investigation into how.</title>
		<link>http://www.ytechie.com/2009/04/int-inherits-from-object-an-investigation-into-how.html</link>
		<comments>http://www.ytechie.com/2009/04/int-inherits-from-object-an-investigation-into-how.html#comments</comments>
		<pubDate>Fri, 17 Apr 2009 18:39:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/04/int-inherits-from-object-an-investigation-into-how.html</guid>
		<description><![CDATA[I’ve began working with a study group which was formed to study for the .NET Framework Application Development certification exam (70-536). I’m eager to get certified because I think it helps fill-in knowledge gaps that I may not have necessarily took the time to focus on normally. One of the first things that came up [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve began working with a study group which was formed to study for the .NET Framework Application Development certification exam (70-536). I’m eager to get certified because I think it helps fill-in knowledge gaps that I may not have necessarily took the time to focus on normally. One of the first things that came up in our study group is the fact that <strong>int</strong>, which is an alias for <strong>System.Int32</strong>, derives from Sytem.ValueType, which, in turn, derives from <strong>System.Object</strong>. Let’s take a close look at what that actually means, and how it’s implemented.</p>
<p>When I first heard that <strong>int</strong> ultimately derived from Object, I didn’t believe it for a number of reasons:</p>
<ul>
<li>If you inherit from <strong>Object</strong>, that derived object IS an object </li>
<li>If <strong>int</strong> is a subclass of <strong>Object</strong>, then boxing isn’t necessary </li>
</ul>
<p>The truth is, my assumptions were not correct. The .NET team, for consistency sake, made all types fit nicely into the type hierarchy:</p>
<p align="center"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Object Hierarchy" border="0" alt="Object Hierarchy" src="http://www.ytechie.com/post-images/2009/04/image3.png" width="275" height="306" /> </p>
<p align="left">If the .NET team had built <strong>System.Int32</strong> to work like any other reference type, there would be clear performance issues. In reality, we need value types to be lean and mean. They are stored on the stack (instead of the heap for reference types). To do this, there is some internal “magic” going on that treats objects that inherit from ValueType differently. Behind the scenes it optimizes how they’re used to get the best of both worlds. If you try to inherit from ValueType, you’ll get a compiler error, because it is only exists for build-in value types.</p>
<p align="left">Of course we want our cake and we want to eat it too. There are often times when you want to use a value type in a method that takes an object as a parameter. To keep up the illusion that a value type is an object, the framework employs boxing. It effectively wraps the value type inside of an object.</p>
<p align="center"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Let me out, I&#39;m an object!" border="0" alt="Let me out, I&#39;m an object!" src="http://www.ytechie.com/post-images/2009/04/image4.png" width="283" height="269" /></p>
<p align="left">Take a look a the following code:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:51b1363f-2059-42fd-8c66-268d18130de3" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">public string GetObjectString(object obj)
{
    return obj.ToString();
}

[TestMethod]
public void IntAsObject_Boxing()
{
    var str = GetObjectString(4);
    Assert.AreEqual("4", str);
}</pre>
</div>
<p align="left">And look at the corresponding IL for the test method:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:8e0c58b8-4c00-4610-aa74-6f1b2f84be66" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">IL_0001:  ldarg.0
IL_0002:  ldc.i4.4
IL_0003:  box        [mscorlib]System.Int32
IL_0008:  call       instance string _4_17_09_Boxing.UnitTest1::GetObjectString(object)
IL_000d:  stloc.0
IL_000e:  ldstr      "4"
IL_0013:  ldloc.0
IL_0014:  call       void [Microsoft.VisualStudio.QualityTools.UnitTestFramework]Microsoft.VisualStudio.TestTools.UnitTesting.Assert::AreEqual&lt;string&gt;(!!0, !!0)
IL_0019:  nop
IL_001a:  ret</pre>
</div>
<p align="left">Notice that boxing occurs on line 3. It’s using the IL “box” command to let you stay oblivious to the fact that there is some magic going on behind the scenes.</p>
<p align="left"><strong>Conclusion</strong></p>
<p align="left">The end result is that we have an integer, which is an object, but isn’t really, that needs to be wrapped inside of an object, which shouldn’t be necessary, but is because it is. <img src='http://www.ytechie.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p align="left">Does this really matter? Well, not really. For the most part you don’t need to know this. If you’re truly inquisitive and want to know what’s going on, you may find it interesting.</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/K4g8sTEJQTo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/04/int-inherits-from-object-an-investigation-into-how.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Unit Testing a LINQ to SQL or EF Query</title>
		<link>http://www.ytechie.com/2009/04/unit-testing-a-linq-to-sql-or-ef-query.html</link>
		<comments>http://www.ytechie.com/2009/04/unit-testing-a-linq-to-sql-or-ef-query.html#comments</comments>
		<pubDate>Thu, 09 Apr 2009 18:58:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[LINQ]]></category>

		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/04/unit-testing-a-linq-to-sql-or-ef-query.html</guid>
		<description><![CDATA[I was writing a slightly non-trivial method to query a database to find a record matching a certain time range. It quickly became clear that it would be nice to write some automated unit tests against it. Integration tests would be less than ideal because of the execution time and complexity. I ended up with [...]]]></description>
			<content:encoded><![CDATA[<p>I was writing a slightly non-trivial method to query a database to find a record matching a certain time range. It quickly became clear that it would be nice to write some automated unit tests against it. Integration tests would be less than ideal because of the execution time and complexity. I ended up with a way to test the code without jumping through too many hoops.</p>
<p><strong>IEnumerable vs IQueryable</strong></p>
<p>First, you need to understand the purpose of IEnumerable and IQueryable. IEnumerable defines a stream of objects that can be retrieved sequentially. It’s implemented for nearly every type of list, and it’s an integral part of LINQ. There are now methods included such as “Where” and “Select” that let us filter, sort, and manipulate lists of data in interesting yet simple ways. This can also be referred to as LINQ to objects.</p>
<p>IQueryable inherits from IEnumerable, and is designed to be translatable into a query. IQueryable is typically used to build an expression tree that <strong>represents</strong> the requested operations. The operations are not actually executed until the expression tree is evaluated and used.</p>
<p>As an example, let’s say I have a database with a table and entities called DateRange. Suppose I cast the DateRange entityset (which implements IQueryable&lt;DateRange&gt;) as IEnumerable&lt;DateRange&gt;. When I call LINQ expressions on that IEnumerable, the underlying query is run immediately, which effectively causes all of the data from that table to be retrieved. If I use IQueryable without casting, my operations get turned into SQL that gets executed when I actually try to iterate through the data (probably using ToList() or foreach). It’s obviously preferable to have the query run in SQL since it can more efficiently filter the data.</p>
<p><strong>The Problem</strong></p>
<p>As I mentioned earlier, I recently starting writing a data access method that started to contain some non-trivial logic. Whenever I see logic, I want to be able to unit test it! I ended up pulling out the logic into its own static method. This method takes in IEnumerable&lt;DateRange&gt;, which can also accept IQueryable&lt;DateRange&gt; (because of the inheritance, you’ll recall). Then, I simply use the AsQueryable method in IEnumerable. This ends up building the needed expression tree that can be translated into a SQL query, but it also lets me test against an in memory collection.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:fa00aac0-6c39-4e4b-bc9f-a7781d500240" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">public static DateRange FindRelativeToDate(IEnumerable&lt;DateRange&gt; enumerable, DateTime reference, int periodOffset)
{
	//Build as an expression tree, if possible, otherwise enumerate
	var queryable = enumerable.AsQueryable();

	//Now put in all the logic

	var reference2 = reference.AddDays(-1);

	var initialRange = from bp in queryable
		 where reference &gt;= bp.Start &amp;&amp; reference2 &lt; bp.End
		 select bp;

	var currentDateRange = initialRange.First();

	if(periodOffset == 0)
		return currentDateRange;

	var newRange = from bp in queryable
		select bp;

	if (periodOffset &gt; 0)
	{
		newRange = newRange.Where(x =&gt; x.Start &gt;= currentDateRange.Start);
		newRange = newRange.OrderBy(x =&gt; x.Start);
	}
	else
	{
		newRange = newRange.Where(x =&gt; x.End &lt;= currentDateRange.End);
		newRange = newRange.OrderByDescending(x =&gt; x.Start);
	}

	return newRange.Skip(Math.Abs(periodOffset)).Take(1).FirstOrDefault();
}</pre>
</div>
<p>In my unit test class, I can define a list of sample data. I took real data from the database to make the tests as close to reality as possible:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:04d1e3b3-50b1-48e5-931a-eb3c96fa191e" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">private static readonly List&lt;DateRange&gt; _DateRanges = new List&lt;DateRange&gt;
{
	new DateRange {Start = new DateTime(2009, 1, 1), End = new DateTime(2009, 1, 30)},
					new DateRange {Start = new DateTime(2009, 1, 31), End = new DateTime(2009, 3, 01)},
					new DateRange {Start = new DateTime(2009, 3, 2), End = new DateTime(2009, 3, 31)},
					new DateRange {Start = new DateTime(2009, 4, 1), End = new DateTime(2009, 4, 30)},
};</pre>
</div>
<p>Now, I can easily test the static class I wrote (this is 1 of 9+ real tests):</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:44884bb7-a315-4cd2-a693-f699e9d4e34a" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">[TestMethod]
public void FindRelativeToDate_MiddleOfDateRange_ContainingDateRange()
{
	var result = DateRangeRepository.FindRelativeToDate(_DateRanges, new DateTime(2009, 3, 15), 0);
	Assert.AreEqual(_DateRanges[2], result);
}</pre>
</div>
<p>The only thing that is left to do is wire up the repository method so that it calls my static method. This is a thin wrapper layer that will actually get used in production. If you run profiler, you’ll see that the query expression is being evaluated and converted into an efficient SQL expression.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ad5a6773-4fc7-435a-b3f1-f68cc877ff64" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">public DateRange FindRelativeToDate(DateTime reference, int periodOffset)
{
	var ctx = dbEntities;
	return FindRelativeToDate(ctx.DateRangeSet, reference, periodOffset);
}</pre>
</div>
<p><strong>Limitations/Conclusion</strong></p>
<p>Unfortunately, this method of testing a repository doesn’t scale easily. If you start working with multiple entity sets that are combined with join operations, this technique is next to impossible to use. You’ll see the most benefit when working with a single entity type, and need to test logic in your repository method.</p>
<p>One thing you need to be aware of, is that LINQ to SQL and Entity Framework don’t implement every IQueryable/IEnumerable method. This means that you could potentially make calls on the in-memory collection that will then fail when you use the actual database. Fortunately, these problems can usually be detected fairly quickly.</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/q2nIp8CoSKI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/04/unit-testing-a-linq-to-sql-or-ef-query.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Maintaining Consistent Line Lengths</title>
		<link>http://www.ytechie.com/2009/04/maintaining-consistent-line-lengths.html</link>
		<comments>http://www.ytechie.com/2009/04/maintaining-consistent-line-lengths.html#comments</comments>
		<pubDate>Mon, 06 Apr 2009 14:10:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[productivity]]></category>

		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/04/maintaining-consistent-line-lengths.html</guid>
		<description><![CDATA[Today&#8217;s tip comes from the “Anally Retentive” department. In the .NET CLR team likes to keep their lines of code under 110 characters long. I’m assuming that they’re trying to maintain consistency and readability. I often try to maintain an imaginary line length limit, but I doubt I’m very consistent.
 
Fortunately, Visual Studio provides a [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s tip comes from the “Anally Retentive” department. In the <a href="http://blogs.msdn.com/shawnfa/archive/2006/07/07/659281.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/blogs.msdn.com/shawnfa/archive/2006/07/07/659281.aspx?referer=');">.NET CLR team likes to keep their lines of code under 110 characters long</a>. I’m assuming that they’re trying to maintain consistency and readability. I often try to maintain an imaginary line length limit, but I doubt I’m very consistent.</p>
<p><img title="Vertical line in Visual Studio" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="272" alt="Vertical line in Visual Studio" src="http://www.ytechie.com/post-images/2009/04/image.png" width="483" border="0" /> </p>
<p>Fortunately, Visual Studio provides a hidden feature that lets you draw a vertical line in the text editor to show you where a certain line length would end. Fire up your registry editor and find this key:</p>
<p><strong>HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor</strong></p>
<p>If you’re using a version of Visual Studio before 2008, you’ll need to decrement the 9.0 version number in the path above.</p>
<p>Then, add the following value (as a string or REG_SZ) with the name of “<strong>Guides</strong>”:</p>
<p><strong>RGB(192,192,192) 110</strong></p>
<p>The first part is the color, and the second part is the line length. Personally, I use a line length of 110 to stay consistent with how Microsoft has chosen to do it. I like the color listed above because it’s faint, but visible. Since the line is almost impossible to see in the screenshot above, here is an un-scaled screenshot of the line itself:</p>
<p align="center"><img title="Vertical Line" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="68" alt="Vertical Line" src="http://www.ytechie.com/post-images/2009/04/image1.png" width="213" border="0" /> </p>
<p align="left">To further enforce the 110 character limit, you could also resize the code portion of your Visual Studio window so that it’s near the line. This will make the line itself a little less annoying, while allowing you to use the rest of the window for other information. For example, take a look at how much room I have on a 1920&#215;1200 screen when I horizontally resize my code window:</p>
<p align="left"><img title="Utilizing a large monitor in Visual Studio" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="291" alt="Utilizing a large monitor in Visual Studio" src="http://www.ytechie.com/post-images/2009/04/image2.png" width="467" border="0" />&#160;</p>
<p align="left">Obviously this tip isn’t for everyone. You may be working with legacy code with long lines, or you might work on a team that doesn’t mind long lines. The great news is that Visual Studio is pretty accommodating to however you like to work.</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/j3JuZR0JioM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/04/maintaining-consistent-line-lengths.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Ode to the iPhone &amp; iPod Touch</title>
		<link>http://www.ytechie.com/2009/03/ode-to-the-iphone-ipod-touch.html</link>
		<comments>http://www.ytechie.com/2009/03/ode-to-the-iphone-ipod-touch.html#comments</comments>
		<pubDate>Fri, 27 Mar 2009 01:52:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[hardware]]></category>

		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/03/ode-to-the-iphone-ipod-touch.html</guid>
		<description><![CDATA[I know I’m nearly two years late to the game, but I finally went out an purchased an iPod Touch, and I have a feeling an iPhone will be mine in the near future. I’ve been blown away by how far ahead of it’s time this thing is. More importantly, it amazing how much of [...]]]></description>
			<content:encoded><![CDATA[<p>I know I’m nearly two years late to the game, but I finally went out an purchased an iPod Touch, and I have a feeling an iPhone will be mine in the near future. I’ve been blown away by how far ahead of it’s time this thing is. More importantly, it amazing how much of an application ecosystem has developed in such a short time.</p>
<p><img title="Kyocera 6035" style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" height="301" alt="Kyocera 6035" src="http://www.ytechie.com/post-images/2009/03/image.png" width="222" border="0" /> </p>
<p>Back in the day, I bought one of the first Smartphone&#8217;s to be sold in the United States, the <a href="http://en.wikipedia.org/wiki/Kyocera_6035" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Kyocera_6035?referer=');">Kyocera 6035</a>. It was basically a Palm device glued to a phone. It was pretty cool since I could use the same device to play Monopoly and make phone calls. After getting rid of this phone, it would be years before I would get another so called “Smartphone”.</p>
<p>Years later, I started getting into the Windows Mobile world (Pocket PC at the time). The Windows mobile platform is compelling because as a developer I can write applications using the .NET Compact Framework without a huge learning curve. It’s also one of the few platforms that works/worked great with Microsoft Exchange. My current carrier of choice, Sprint, also tends to have a great suite of Windows Mobile phones. I also like the fact that any hackable feature is just a registry edit away.</p>
<p><img title="HTC Touch Diamond" style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" height="240" alt="HTC Touch Diamond" src="http://www.ytechie.com/post-images/2009/03/image1.png" width="240" border="0" /> </p>
<p>My current phone is an <a href="http://en.wikipedia.org/wiki/HTC_Touch_Diamond" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/HTC_Touch_Diamond?referer=');">HTC Touch Diamond</a>. <strong>On paper</strong>, this is currently one of the most amazing phones ever created. It’s one of the smallest Smartphone&#8217;s you can buy, yet it has a fast processor, VGA screen, excellent GPS, light sensor, stylus sensor, accelerometers, resistive &amp; capacitive features, etc. However, in reality, this phone drives me crazy. Opera is a decent browser except that it takes too long to open, and doesn’t render as fast as it should on 3g. The push email features are pretty good except that the UI is a joke. Scrolling is not as smooth as it should be. Integration between apps is non-existent. The resistive screen isn’t optimal for finger use. The experience is just laughable. The list goes on. I assumed these were all unavoidable simply due to the fact that it’s a mobile platform.</p>
<p>Recently, I decided to try the iPod touch. It’s my understanding that it’s somewhat of a gateway drug to the iPhone. Essentially, it’s the same thing but without a phone, a real GPS, and a microphone.</p>
<p>After using this device for a while, I am consistently surprised how streamlined and painless it is to use. Nearly every function works without even thinking about it. Every motion is perfectly smooth. No configuration is too difficult.</p>
<p>At first I was skeptical about the main interface, which consists of one or more screens full of icons. There is really no organization, no folders. The beauty of this design is in its simplicity. You’re never more than one press away from the information you’re looking for. Weather, click. Headlines, click. Calendar, click. Email, click. Touch Flo 3d on my HTC phone is essentially lipstick on a pig. It looks cool, and kind of works well if you’re completely sober.</p>
<p>Now, let’s get to the real reason that the iPhone is an unstoppable force. They have an insane application ecosystem. Most of the applications are not worth the bytes they’re made of. However, a few of them are so simple, so elegant, and so efficient that they change the platform. For example, if I want to see what movies are in the theater, I can use the movie app. If I want TV listings, I use the TV app. If I want to find local events or lookup a number, I use the yellow pages app.</p>
<p>iPhone applications usually have similar functionality to what you get in your browser on your desktop or laptop computer, but they’re typically designed to do one thing, and do it well. If you were to download an application to your computer specifically for getting movie times, I’m sure the experience would be similar, but on the desktop platform it’s not quite worth it. I find myself using my iPod touch instead of my laptop to get a lot of quick information. I’ve also been opened up to a world of information that I normally would not have seen. For example, I have an application that shows me the local events in the area. I could have Googled for the same information, but this puts it all just a press away.</p>
<p>If you are someone that hasn’t given the iPhone platform a try, do yourself a favor and go spend $230 on the iPod Touch. Then, visit the app store and download some freebies. If you’re waiting for Windows Mobile or Android to catch up and build up the same application ecosystem, don’t hold your breath.</p>
<p>I’ve been so excited by this platform that I ordered myself a Mac Mini that should hopefully be showing up tomorrow :-). Stay tuned as I talk about the experience of a c# developer writing an iPhone app in Objective-C!</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/NY5GRJAk4As" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/03/ode-to-the-iphone-ipod-touch.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Slick inline trace logging in ASP.NET</title>
		<link>http://www.ytechie.com/2009/03/slick-inline-trace-logging-in-aspnet.html</link>
		<comments>http://www.ytechie.com/2009/03/slick-inline-trace-logging-in-aspnet.html#comments</comments>
		<pubDate>Tue, 03 Mar 2009 18:02:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://www.ytechie.com/2009/03/slick-inline-trace-logging-in-aspnet.html</guid>
		<description><![CDATA[I’m going to show you a slick way to configure log4net to your trace log, and then make it extremely simple to view the trace log for a page while viewing that page. Ultimately, we’ll end up with something that looks like this:
 
It may be difficult to see from the screenshot, but I’m looking [...]]]></description>
			<content:encoded><![CDATA[<p>I’m going to show you a slick way to configure <a href="http://logging.apache.org/log4net/index.html" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/logging.apache.org/log4net/index.html?referer=');">log4net</a> to your trace log, and then make it extremely simple to view the trace log for a page <strong>while</strong> viewing that page. Ultimately, we’ll end up with something that looks like this:</p>
<p><a href="http://www.ytechie.com/post-images/2009/03/pagetracing.png"><img title="page-tracing" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="446" alt="page-tracing" src="http://www.ytechie.com/post-images/2009/03/pagetracing-thumb.png" width="485" border="0" /></a> </p>
<p>It may be difficult to see from the screenshot, but I’m looking at a standard ASP.NET page, but there is tracing information at the bottom. This tracing information is the same information you would see if you configured tracing your <em>web.config</em>, and then used the <em>trace.axd</em> page. However, we’re displaying it right along with the page request. To allow tracing to be enabled with a simple URL parameter, you can add the following code into your <em>Global.asax</em> file:</p>
<div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d2c077e4-6d53-4f24-9efe-01190af67dec" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="c#">protected void Application_BeginRequest(object s, EventArgs e)
{
	if (Context.Request.QueryString["trace"] == "true")
		Context.Trace.IsEnabled = true;
}</pre>
</div>
<p>Of course in a public environment, it may be wise to add security or at least obfuscate the parameter. The trace information contains server information that may be helpful to someone trying to compromise the server.</p>
<p>Now that we have tracing information, how can we get our log messages to show up? Log4net provides an appender for logging to the ASP.NET tracing feature:</p>
<p><div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ab0b4ffe-4201-497b-9353-12ce443cab15" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="xml">&lt;appender name="AspNetTraceAppender"
	type="log4net.Appender.AspNetTraceAppender" &gt;
	&lt;layout type="log4net.Layout.PatternLayout"&gt;
		&lt;conversionPattern
			value="[Thread #%thread] %-5level - %message%newline" /&gt;
	&lt;/layout&gt;
&lt;/appender&gt;</pre>
</div>
<p>Don’t forget to wire up the adapter so that log4net knows to use it:</p>
<div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:7b11243d-0aa8-44f5-87a2-4660a3edb830" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="xml">&lt;root&gt;
	&lt;level value="DEBUG" /&gt;
	&lt;appender-ref ref="AspNetTraceAppender" /&gt;
&lt;/root&gt;</pre>
</div>
<p>Now, in your code, you can simply log messages as you normally would:</p>
<div class="wlWriterEditableSmartContent" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d73b9a80-cf72-43f8-9911-0efa3e535a00" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre name="code" class="c#">_log.Debug("Loading User Data");</pre>
</div>
<p><strong>Conclusion</strong></p>
<p>I’ve found this type of configuration very useful in my ASP.NET applications. It lets me analyze how long each portion of the page generation is taking so that I can find bottlenecks. It also motivates me to write a fair amount of logging, since I’ll see a benefit during development, as well as after deploying it into the wild.</p>
<img src="http://feeds.feedburner.com/~r/Ytechie/~4/rMA2XdKYyoM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ytechie.com/2009/03/slick-inline-trace-logging-in-aspnet.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 1.564 seconds -->
