<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Tim Barcz - Programming</title>
    <link>http://www.timbarcz.com/blog/</link>
    <description>My Code is My Craft</description>
    <image>
      <url>http://www.timbarcz.com/blog/content/binary/channelImage.jpg</url>
      <title>Tim Barcz - Programming</title>
      <link>http://www.timbarcz.com/blog/</link>
    </image>
    <language>en-us</language>
    <copyright>Tim Barcz</copyright>
    <lastBuildDate>Tue, 05 Aug 2008 13:48:30 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>blog@timbarcz.com</managingEditor>
    <webMaster>blog@timbarcz.com</webMaster>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=42570527-952b-4d9f-a25a-84ef7abad9fb</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,42570527-952b-4d9f-a25a-84ef7abad9fb.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,42570527-952b-4d9f-a25a-84ef7abad9fb.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=42570527-952b-4d9f-a25a-84ef7abad9fb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/Logging_EA32/image_2.png">
            <img style="border-width: 0px;" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/Logging_EA32/image_thumb.png" width="305" align="right" border="0" height="324" />
          </a>I
have what I believe to be a fairly simple problem in theory, yet in reality it proves
to be a bit more hairy.  Below I present the problem and the requirements as
I see them as well as a few possible solutions.  The solution I've settled on
may or may not be correct, so I'm tossing out here to see what you guys think. 
By all means please post some feedback.
</p>
        <h3>Problem
</h3>
        <p>
To have a common, consistent logging access across multiple assemblies (that I own)
in an application.
</p>
        <h4>
        </h4>
        <h3>Requirements
</h3>
        <ul>
          <li>
I want to be able to have logging capabilities in any method of any class in my application. 
</li>
          <li>
I want to define logging once and only once for my application.  
</li>
          <li>
I want to maintain testability by not having any unnecessary dependencies or unmockable
objects.  
</li>
          <li>
I want as few assemblies to be aware of dependencies as possible.</li>
          <li>
If at all possible I wanted to avoid having all of my classes have an external dependency
on some interface (such as ILog) 
<ul><li>
I also want to avoid every class having a public property which exposes an ILog (for
setter injection) 
</li></ul></li>
        </ul>
        <h3>The Structure
</h3>
        <p>
To the right is a picture of the assembly dependency diagram. 
</p>
        <h3>Solution #1
</h3>
        <p>
I could use <a href="http://devlicio.us/blogs/casey/archive/2008/06/18/logging-with-castle-windsor-the-logging-facility-and-log4net.aspx">Windsor's
logging facility</a> as suggested by <a href="http://devlicio.us/blogs/casey/">Casey
Charlton</a> except that the solution provided only seemingly works for my top level
assembly, ABCCompany.MVC.Web.  I don't want my other assemblies to be aware that
I'm using an IoC Container.  I especially don't want the assemblies to know I'm
bound to a particular IoC container (in this case I'm using Castle's Windsor container). 
I've emailed Casey about this and we are going to try to talk this through. 
I'm interested to hear what his thoughts are given that on <a href="http://www.castleproject.org">Castle's
site</a> it says about the <a href="http://www.castleproject.org/container/facilities/v1rc3/logging/index.html">logging
facility</a> (emphasis mine):
</p>
        <blockquote>
          <p>
The logging facility provides a seamless way to add logging capabilities to your application.
There are two levels of integration. 
</p>
          <ul>
            <li>
Allow your classes to receive an ILogger instance for logging support 
</li>
            <li>
              <strong>Allow you to ask for an ILoggerFactory instance to provide logging support
to classes that are not managed by Windsor.</strong>
            </li>
          </ul>
        </blockquote>
        <p>
While I wait to talk with Casey I have to discount this solution since I cannot see
past the first assembly on how this would work and therefore cannot use this as my
solution of choice.
</p>
        <h3>Solution #2
</h3>
        <p>
This is what I've come up with so far.  Please comment if you see issues.  
</p>
        <p>
I have set up a static class inside of the ABCCompany.Framework assembly from which
all methods could call for Logging purposes.  This satisfies the requirements
above which states that I do not want constructor dependencies nor public setters
on all classes.  This solution however does mean that every assembly much also
ship with the ABCCompany.Framework assembly and all of it's dependent assemblies. 
I'm okay with this until I hear a reason that this is bad.  I view this much
like when I do work with Castle that in order to get any behavior I have to bring
Castle.Core along to the party.
</p>
        <p>
I liked Casey's solution (Solution #1) except that I cannot see past it working in
one and only one assembly.  I thought I could modify his solution by simply having
a static class, which any assembly can reference and call.  By default the Logger
would be set up with a NullLogger.  The Logging class would have a method available
to change the underlying logger.  It would then be incumbent upon the application
layer to change the logger if they actually wanted logging.  In my app this is
the first thing that happens, the NullLogger is replaced by an actual logger by calling
Log.SetLogger().
</p>
        <p>
As you can see from the code below I've followed much of Casey's example.
</p>
        <div>
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span>
              <span style="color: rgb(0, 0, 255);">private</span>
              <span style="color: rgb(0, 0, 255);">static</span> ILogger
logger;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 3:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">static</span> ILogger
Logger</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 4:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 5:</span> get</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 6:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 7:</span>
              <span style="color: rgb(0, 0, 255);">if</span> (logger
== <span style="color: rgb(0, 0, 255);">null</span>)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 8:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 9:</span> logger
= NullLogger.Instance;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 10:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 11:</span>
              <span style="color: rgb(0, 0, 255);">return</span> logger;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 12:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 13:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 14:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 15:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">static</span>
              <span style="color: rgb(0, 0, 255);">void</span> SetLogger(ILogger <span style="color: rgb(0, 0, 255);">value</span>)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 16:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 17:</span> logger
= <span style="color: rgb(0, 0, 255);">value</span>;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 18:</span> }</pre>
          </div>
        </div>
        <p>
I do have a dependency on the Castle.Core assembly (due to usage of types in Castle.Core.Logging). 
However none of the classes using the Log static class have to reference anything
to do with Castle since I've have methods which pass through to every method in ILogger
(see example below):
</p>
        <div>
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">static</span>
              <span style="color: rgb(0, 0, 255);">void</span> Debug(<span style="color: rgb(0, 0, 255);">string</span> message)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 3:</span> Logger.Debug(message);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 4:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 5:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 6:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">static</span>
              <span style="color: rgb(0, 0, 255);">void</span> Debug(<span style="color: rgb(0, 0, 255);">string</span> message,
Exception exception)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 7:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 8:</span> Logger.Debug(message,exception);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 9:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 10:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 11:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">static</span>
              <span style="color: rgb(0, 0, 255);">void</span> Debug(<span style="color: rgb(0, 0, 255);">string</span> format, <span style="color: rgb(0, 0, 255);">params</span><span style="color: rgb(0, 0, 255);">object</span>[]
args)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 12:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 13:</span> Logger.Debug(format,
args);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 14:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 15:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 16:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">static</span>
              <span style="color: rgb(0, 0, 255);">void</span> DebugFormat(<span style="color: rgb(0, 0, 255);">string</span> format, <span style="color: rgb(0, 0, 255);">params</span><span style="color: rgb(0, 0, 255);">object</span>[]
args)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 17:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 18:</span> Logger.DebugFormat(format,
args);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 19:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 20:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 21:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">static</span>
              <span style="color: rgb(0, 0, 255);">void</span> DebugFormat(Exception
exception, <span style="color: rgb(0, 0, 255);">string</span> format, <span style="color: rgb(0, 0, 255);">params</span><span style="color: rgb(0, 0, 255);">object</span>[]
args)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 22:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 23:</span> Logger.DebugFormat(exception,format,
args);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 24:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 25:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 26:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">static</span>
              <span style="color: rgb(0, 0, 255);">void</span> DebugFormat(IFormatProvider
formatProvider, <span style="color: rgb(0, 0, 255);">string</span> format, <span style="color: rgb(0, 0, 255);">params</span><span style="color: rgb(0, 0, 255);">object</span>[]
args)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 27:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 28:</span> Logger.DebugFormat(formatProvider,
format, args);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 29:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 30:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 31:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">static</span>
              <span style="color: rgb(0, 0, 255);">void</span> DebugFormat(Exception
exception, IFormatProvider formatProvider, <span style="color: rgb(0, 0, 255);">string</span> format, <span style="color: rgb(0, 0, 255);">params</span><span style="color: rgb(0, 0, 255);">object</span>[]
args)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 32:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 33:</span> Logger.DebugFormat(exception,
formatProvider, format, args);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 34:</span> }</pre>
          </div>
        </div>
        <p>
The usage pattern becomes quite simple in that any class that references ABCCompany.Framework
can use the ABCCompany.Framework.Logging.Log class.  No external references needs
</p>
        <p>
The reason I chose to bind myself at the framework level to Castle's ILogger interface
and not something like ILog (log4net) was because ILogger is an abstraction over the
ILog interface.  Castle also provides some concrete implementations of ILogger,
one of which is for log4net 
</p>
        <ul>
          <li>
log4net (requires Castle.Services.Logging.Log4netIntegration.dll) 
</li>
          <li>
NLog (requires Castle.Services.Logging.NLogIntegration.dll) 
</li>
          <li>
ConsoleLogger 
</li>
          <li>
DiagnosticsLogger 
</li>
          <li>
StreamLogger 
</li>
          <li>
WebLogger (TraceContext) 
</li>
          <li>
NullLogger (used as placeholder) 
</li>
        </ul>
        <p>
As far as testing is concerned, the solution imposes no restrictions on testing. 
In my testing assemblies my logging calls are swallowed by the null logger. 
If I want to ensure the logger is called in my testing (interaction based tests),
I can mock an instance of ILogger and call Log.SetLogger() and set up expectations
on the mock ILogger.
</p>
        <p>
As I've mulled over this solution now for about a day it feels pretty solid. 
As I go through the requirements above they are all satisfied.  However I can
only see as far as my current knowledge so I'm hoping that if you see issues with
the above that you'll let me know.
</p>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=42570527-952b-4d9f-a25a-84ef7abad9fb" />
      </body>
      <title>Single Source Logging In Multiple Assemblies</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,42570527-952b-4d9f-a25a-84ef7abad9fb.aspx</guid>
      <link>http://www.timbarcz.com/blog/SingleSourceLoggingInMultipleAssemblies.aspx</link>
      <pubDate>Tue, 05 Aug 2008 13:48:30 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/Logging_EA32/image_2.png"&gt;&lt;img style="border-width: 0px;" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/Logging_EA32/image_thumb.png" width="305" align="right" border="0" height="324"&gt;&lt;/a&gt;I
have what I believe to be a fairly simple problem in theory, yet in reality it proves
to be a bit more hairy.&amp;nbsp; Below I present the problem and the requirements as
I see them as well as a few possible solutions.&amp;nbsp; The solution I've settled on
may or may not be correct, so I'm tossing out here to see what you guys think.&amp;nbsp;
By all means please post some feedback.
&lt;/p&gt;
&lt;h3&gt;Problem
&lt;/h3&gt;
&lt;p&gt;
To have a common, consistent logging access across multiple assemblies (that I own)
in an application.
&lt;/p&gt;
&lt;h4&gt;
&lt;/h4&gt;
&lt;h3&gt;Requirements
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
I want to be able to have logging capabilities in any method of any class in my application. 
&lt;/li&gt;
&lt;li&gt;
I want to define logging once and only once for my application.&amp;nbsp; 
&lt;/li&gt;
&lt;li&gt;
I want to maintain testability by not having any unnecessary dependencies or unmockable
objects.&amp;nbsp; 
&lt;/li&gt;
&lt;li&gt;
I want as few assemblies to be aware of dependencies as possible.&lt;/li&gt;
&lt;li&gt;
If at all possible I wanted to avoid having all of my classes have an external dependency
on some interface (such as ILog) 
&lt;ul&gt;
&lt;li&gt;
I also want to avoid every class having a public property which exposes an ILog (for
setter injection) 
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;The Structure
&lt;/h3&gt;
&lt;p&gt;
To the right is a picture of the assembly dependency diagram. 
&lt;/p&gt;
&lt;h3&gt;Solution #1
&lt;/h3&gt;
&lt;p&gt;
I could use &lt;a href="http://devlicio.us/blogs/casey/archive/2008/06/18/logging-with-castle-windsor-the-logging-facility-and-log4net.aspx"&gt;Windsor's
logging facility&lt;/a&gt; as suggested by &lt;a href="http://devlicio.us/blogs/casey/"&gt;Casey
Charlton&lt;/a&gt; except that the solution provided only seemingly works for my top level
assembly, ABCCompany.MVC.Web.&amp;nbsp; I don't want my other assemblies to be aware that
I'm using an IoC Container.&amp;nbsp; I especially don't want the assemblies to know I'm
bound to a particular IoC container (in this case I'm using Castle's Windsor container).&amp;nbsp;
I've emailed Casey about this and we are going to try to talk this through.&amp;nbsp;
I'm interested to hear what his thoughts are given that on &lt;a href="http://www.castleproject.org"&gt;Castle's
site&lt;/a&gt; it says about the &lt;a href="http://www.castleproject.org/container/facilities/v1rc3/logging/index.html"&gt;logging
facility&lt;/a&gt; (emphasis mine):
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
The logging facility provides a seamless way to add logging capabilities to your application.
There are two levels of integration. 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Allow your classes to receive an ILogger instance for logging support 
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Allow you to ask for an ILoggerFactory instance to provide logging support
to classes that are not managed by Windsor.&lt;/strong&gt; 
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
While I wait to talk with Casey I have to discount this solution since I cannot see
past the first assembly on how this would work and therefore cannot use this as my
solution of choice.
&lt;/p&gt;
&lt;h3&gt;Solution #2
&lt;/h3&gt;
&lt;p&gt;
This is what I've come up with so far.&amp;nbsp; Please comment if you see issues.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
I have set up a static class inside of the ABCCompany.Framework assembly from which
all methods could call for Logging purposes.&amp;nbsp; This satisfies the requirements
above which states that I do not want constructor dependencies nor public setters
on all classes.&amp;nbsp; This solution however does mean that every assembly much also
ship with the ABCCompany.Framework assembly and all of it's dependent assemblies.&amp;nbsp;
I'm okay with this until I hear a reason that this is bad.&amp;nbsp; I view this much
like when I do work with Castle that in order to get any behavior I have to bring
Castle.Core along to the party.
&lt;/p&gt;
&lt;p&gt;
I liked Casey's solution (Solution #1) except that I cannot see past it working in
one and only one assembly.&amp;nbsp; I thought I could modify his solution by simply having
a static class, which any assembly can reference and call.&amp;nbsp; By default the Logger
would be set up with a NullLogger.&amp;nbsp; The Logging class would have a method available
to change the underlying logger.&amp;nbsp; It would then be incumbent upon the application
layer to change the logger if they actually wanted logging.&amp;nbsp; In my app this is
the first thing that happens, the NullLogger is replaced by an actual logger by calling
Log.SetLogger().
&lt;/p&gt;
&lt;p&gt;
As you can see from the code below I've followed much of Casey's example.
&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; ILogger
logger;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; ILogger
Logger&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 4:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 5:&lt;/span&gt; get&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 6:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 7:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (logger
== &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 8:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 9:&lt;/span&gt; logger
= NullLogger.Instance;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 10:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 11:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; logger;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 12:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 13:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 14:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 15:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; SetLogger(ILogger &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 16:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 17:&lt;/span&gt; logger
= &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 18:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
I do have a dependency on the Castle.Core assembly (due to usage of types in Castle.Core.Logging).&amp;nbsp;
However none of the classes using the Log static class have to reference anything
to do with Castle since I've have methods which pass through to every method in ILogger
(see example below):
&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Debug(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; message)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 3:&lt;/span&gt; Logger.Debug(message);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 4:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 5:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 6:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Debug(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; message,
Exception exception)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 7:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 8:&lt;/span&gt; Logger.Debug(message,exception);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 9:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 10:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 11:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Debug(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; format, &lt;span style="color: rgb(0, 0, 255);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;[]
args)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 12:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 13:&lt;/span&gt; Logger.Debug(format,
args);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 14:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 15:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 16:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; DebugFormat(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; format, &lt;span style="color: rgb(0, 0, 255);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;[]
args)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 17:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 18:&lt;/span&gt; Logger.DebugFormat(format,
args);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 19:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 20:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 21:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; DebugFormat(Exception
exception, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; format, &lt;span style="color: rgb(0, 0, 255);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;[]
args)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 22:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 23:&lt;/span&gt; Logger.DebugFormat(exception,format,
args);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 24:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 25:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 26:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; DebugFormat(IFormatProvider
formatProvider, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; format, &lt;span style="color: rgb(0, 0, 255);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;[]
args)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 27:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 28:&lt;/span&gt; Logger.DebugFormat(formatProvider,
format, args);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 29:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 30:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 31:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; DebugFormat(Exception
exception, IFormatProvider formatProvider, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; format, &lt;span style="color: rgb(0, 0, 255);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;[]
args)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 32:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 33:&lt;/span&gt; Logger.DebugFormat(exception,
formatProvider, format, args);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 34:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
The usage pattern becomes quite simple in that any class that references ABCCompany.Framework
can use the ABCCompany.Framework.Logging.Log class.&amp;nbsp; No external references needs
&lt;/p&gt;
&lt;p&gt;
The reason I chose to bind myself at the framework level to Castle's ILogger interface
and not something like ILog (log4net) was because ILogger is an abstraction over the
ILog interface.&amp;nbsp; Castle also provides some concrete implementations of ILogger,
one of which is for log4net 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
log4net (requires Castle.Services.Logging.Log4netIntegration.dll) 
&lt;/li&gt;
&lt;li&gt;
NLog (requires Castle.Services.Logging.NLogIntegration.dll) 
&lt;/li&gt;
&lt;li&gt;
ConsoleLogger 
&lt;/li&gt;
&lt;li&gt;
DiagnosticsLogger 
&lt;/li&gt;
&lt;li&gt;
StreamLogger 
&lt;/li&gt;
&lt;li&gt;
WebLogger (TraceContext) 
&lt;/li&gt;
&lt;li&gt;
NullLogger (used as placeholder) 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
As far as testing is concerned, the solution imposes no restrictions on testing.&amp;nbsp;
In my testing assemblies my logging calls are swallowed by the null logger.&amp;nbsp;
If I want to ensure the logger is called in my testing (interaction based tests),
I can mock an instance of ILogger and call Log.SetLogger() and set up expectations
on the mock ILogger.
&lt;/p&gt;
&lt;p&gt;
As I've mulled over this solution now for about a day it feels pretty solid.&amp;nbsp;
As I go through the requirements above they are all satisfied.&amp;nbsp; However I can
only see as far as my current knowledge so I'm hoping that if you see issues with
the above that you'll let me know.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=42570527-952b-4d9f-a25a-84ef7abad9fb" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,42570527-952b-4d9f-a25a-84ef7abad9fb.aspx</comments>
      <category>.NET</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=6c8e3d51-a59c-4325-92f1-deb8d28c2a88</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,6c8e3d51-a59c-4325-92f1-deb8d28c2a88.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,6c8e3d51-a59c-4325-92f1-deb8d28c2a88.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=6c8e3d51-a59c-4325-92f1-deb8d28c2a88</wfw:commentRss>
      <slash:comments>12</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I posted earlier this year with the basic question, <a href="http://www.timbarcz.com/blog/IsVarBetter.aspx">Is
Var Better?</a>  I'm not the only one to question the reintroduction of var. 
Rhys Campbell went as far as to say some <a href="http://rhysc.blogspot.com/2008/07/var-abuse.html">abuse
the new keyword</a>. I will say that my initial aversion to using var has softened
a bit.  However there are at least two issues I have with them.
</p>
        <ol>
          <li>
Implicit conversions</li>
          <li>
Intellisense</li>
        </ol>
        <h3>Implicit Conversions
</h3>
        <p>
In my latest project I've encapsulated all domain knowledge in it's own assembly in
DDD fashion.  We have the notion of a ProductSku, a unique identifier for a product. 
A Product object therefore has a ProductSku property which identifies it.  I
could have implemented the ProductSku property as a string type, but in thinking about
my domain and remembering <a href="http://www.enterpriseintegrationpatterns.com/ramblings/40_marchnan.html">March
is Not a Number</a> ProductSku is now it's own first-class citizen type.
</p>
        <p>
I have the following code to perform implicit conversion from a ProductSku to a string:
</p>
        <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 1:</span>
              <span style="color: #008000">///
&lt;summary&gt;</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span>
              <span style="color: #008000">///
Performs an implicit conversion from &lt;see cref="JPCycles.Domain.ProductSKU"/&gt;
to &lt;see cref="System.String"/&gt;.</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 3:</span>
              <span style="color: #008000">///
&lt;/summary&gt;</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 4:</span>
              <span style="color: #008000">///
&lt;param name="sku"&gt;The sku.&lt;/param&gt;</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 5:</span>
              <span style="color: #008000">///
&lt;returns&gt;The result of the conversion.&lt;/returns&gt;</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 6:</span>
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">static</span>
              <span style="color: #0000ff">implicit</span>
              <span style="color: #0000ff">operator</span>
              <span style="color: #0000ff">string</span>(ProductSKU
sku)</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 7:</span> {</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 8:</span>
              <span style="color: #0000ff">return</span> sku.<span style="color: #0000ff">value</span>;</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 9:</span> }</pre>
          </div>
        </div>
        <p>
In order to test this method I have the following code:
</p>
        <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 1:</span> [Test]</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span>
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">void</span> Implicit_conversion_of_sku_to_string()</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 3:</span> {</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 4:</span>
              <span style="color: #0000ff">string</span> skuValue
= <span style="color: #006080">"ZZ123456"</span>;</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 5:</span> var
sku = <span style="color: #0000ff">new</span> ProductSKU(skuValue);</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 6:</span>  </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 7:</span> var
converted = sku;</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 8:</span>  </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 9:</span> Assert.That(converted,
Is.EqualTo(skuValue));</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 10:</span> }</pre>
          </div>
        </div>
        <p>
As you can see in line 7, I'm using the var keyword.  The problem with this is
that using var in the scenario keeps me from testing the code that I want to test. 
The goal of the test is to confirm the implicit conversion of a ProductSku to string. 
This happens in line 7.  However when using the var keyword, the compiler interprets
the "converted" variable as a ProductSku object and not a string object,
as I really want.  
</p>
        <p>
See below for confirmation:
</p>
        <p>
          <a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_4.png">
            <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="272" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_thumb_1.png" width="551" border="0" />
          </a>
        </p>
        <p>
(You might be saying to yourself that the conversion still happens in line 9, when
the ProductSku object is evaluated against a string.  You might be right? 
Or...does the string get implicitly converted to a ProductSku object?  If you
don't know the answer to that question off the top of you head you cannot rely on
line 9 for your conversion.  Also you shouldn't be using your asserts to perform
the work for which you are testing)
</p>
        <p>
If I leave the var keyword in place in line seven, my test will pass and possibly
deceive me into thinking I've properly tested my code.  Only when running a coverage
report do I see that the implicit conversion method is never being called.
</p>
        <p>
The use of var is fine, except that now I have to think about how the compiler will
interpret a statement versus what I want in programming it.  The var keyword
does the best it can, but sometimes that's not good enough.  As another example,
compare the following code:
</p>
        <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 1:</span> IUser
user1 = <span style="color: #0000ff">new</span> User();</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span> var
user2 = <span style="color: #0000ff">new</span> User();</pre>
          </div>
        </div>
The two users above have different type signatures, which on some level bothers me
a bit, since you can see that the code is clearly the same. 
<h3>Intellisense
</h3><p>
The use of var makes intellisense less effective.  It's not the compilers fault
though.  Given the point where you use var, the compiler has no idea what you're
going to type on the right-hand side of the expression, so it cannot help.  
</p><p>
Say, for example, I want to define a Dictionary&lt;string,string&gt; called "my
list".  When I use the var keyword, I have to type out enough information
from which intellisense can narrow down what I'm looking for.  I hear a lot from
the proponents of var how great it is because complex declarations, especially with
generics, can be avoided.  I disagree and only need to show you the example below
to prove my point.  In the example below I'm writing the exact same line of code. 
The first example uses var, the second does not, which would you prefer?
</p><p><a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_6.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="262" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_thumb_2.png" width="450" border="0" /></a> 
</p><p><a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_8.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="139" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_thumb_3.png" width="526" border="0" /></a></p><p>
When using var I had to type everything since the compile cannot help me, only I had
to type on the right hand side of the expression.  So I really have saved nothing.
</p><p><a href="http://www.codinghorror.com">Jeff Atwood</a> posted that <a href="http://www.codinghorror.com/blog/archives/001136.html">by
not using var, you're being redundant</a>.  I would say that by not being redundant,
for which the compiler penalizes you nothing, you're being slower, because you cannot
take advantage of build-in assistance, ie intellisense.
</p><p>
These two annoyances won't stop me from using var in various (read: limited) situations. 
The point of this post is to caution the reader to not be too quick to jump on the
var bandwagon.  In the first example it may cause you headaches in performing
proper testing and in the second, it may slow you down with the loss of intellisense.
</p><img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=6c8e3d51-a59c-4325-92f1-deb8d28c2a88" /></body>
      <title>My Issues With Var</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,6c8e3d51-a59c-4325-92f1-deb8d28c2a88.aspx</guid>
      <link>http://www.timbarcz.com/blog/MyIssuesWithVar.aspx</link>
      <pubDate>Mon, 04 Aug 2008 14:55:55 GMT</pubDate>
      <description>&lt;p&gt;
I posted earlier this year with the basic question, &lt;a href="http://www.timbarcz.com/blog/IsVarBetter.aspx"&gt;Is
Var Better?&lt;/a&gt;&amp;#160; I'm not the only one to question the reintroduction of var.&amp;#160;
Rhys Campbell went as far as to say some &lt;a href="http://rhysc.blogspot.com/2008/07/var-abuse.html"&gt;abuse
the new keyword&lt;/a&gt;. I will say that my initial aversion to using var has softened
a bit.&amp;#160; However there are at least two issues I have with them.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Implicit conversions&lt;/li&gt;
&lt;li&gt;
Intellisense&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Implicit Conversions
&lt;/h3&gt;
&lt;p&gt;
In my latest project I've encapsulated all domain knowledge in it's own assembly in
DDD fashion.&amp;#160; We have the notion of a ProductSku, a unique identifier for a product.&amp;#160;
A Product object therefore has a ProductSku property which identifies it.&amp;#160; I
could have implemented the ProductSku property as a string type, but in thinking about
my domain and remembering &lt;a href="http://www.enterpriseintegrationpatterns.com/ramblings/40_marchnan.html"&gt;March
is Not a Number&lt;/a&gt; ProductSku is now it's own first-class citizen type.
&lt;/p&gt;
&lt;p&gt;
I have the following code to perform implicit conversion from a ProductSku to a string:
&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; &lt;span style="color: #008000"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; &lt;span style="color: #008000"&gt;///
Performs an implicit conversion from &amp;lt;see cref=&amp;quot;JPCycles.Domain.ProductSKU&amp;quot;/&amp;gt;
to &amp;lt;see cref=&amp;quot;System.String&amp;quot;/&amp;gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt; &lt;span style="color: #008000"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 4:&lt;/span&gt; &lt;span style="color: #008000"&gt;///
&amp;lt;param name=&amp;quot;sku&amp;quot;&amp;gt;The sku.&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 5:&lt;/span&gt; &lt;span style="color: #008000"&gt;///
&amp;lt;returns&amp;gt;The result of the conversion.&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 6:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;implicit&lt;/span&gt; &lt;span style="color: #0000ff"&gt;operator&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;(ProductSKU
sku)&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 7:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 8:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; sku.&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 9:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
In order to test this method I have the following code:
&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; [Test]&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Implicit_conversion_of_sku_to_string()&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 4:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; skuValue
= &lt;span style="color: #006080"&gt;&amp;quot;ZZ123456&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 5:&lt;/span&gt; var
sku = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ProductSKU(skuValue);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 7:&lt;/span&gt; var
converted = sku;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 9:&lt;/span&gt; Assert.That(converted,
Is.EqualTo(skuValue));&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 10:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
As you can see in line 7, I'm using the var keyword.&amp;#160; The problem with this is
that using var in the scenario keeps me from testing the code that I want to test.&amp;#160;
The goal of the test is to confirm the implicit conversion of a ProductSku to string.&amp;#160;
This happens in line 7.&amp;#160; However when using the var keyword, the compiler interprets
the &amp;quot;converted&amp;quot; variable as a ProductSku object and not a string object,
as I really want.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
See below for confirmation:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="272" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_thumb_1.png" width="551" border="0" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
(You might be saying to yourself that the conversion still happens in line 9, when
the ProductSku object is evaluated against a string.&amp;#160; You might be right?&amp;#160;
Or...does the string get implicitly converted to a ProductSku object?&amp;#160; If you
don't know the answer to that question off the top of you head you cannot rely on
line 9 for your conversion.&amp;#160; Also you shouldn't be using your asserts to perform
the work for which you are testing)
&lt;/p&gt;
&lt;p&gt;
If I leave the var keyword in place in line seven, my test will pass and possibly
deceive me into thinking I've properly tested my code.&amp;#160; Only when running a coverage
report do I see that the implicit conversion method is never being called.
&lt;/p&gt;
&lt;p&gt;
The use of var is fine, except that now I have to think about how the compiler will
interpret a statement versus what I want in programming it.&amp;#160; The var keyword
does the best it can, but sometimes that's not good enough.&amp;#160; As another example,
compare the following code:
&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; IUser
user1 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; User();&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; var
user2 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; User();&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
The two users above have different type signatures, which on some level bothers me
a bit, since you can see that the code is clearly the same. 
&lt;h3&gt;Intellisense
&lt;/h3&gt;
&lt;p&gt;
The use of var makes intellisense less effective.&amp;#160; It's not the compilers fault
though.&amp;#160; Given the point where you use var, the compiler has no idea what you're
going to type on the right-hand side of the expression, so it cannot help.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Say, for example, I want to define a Dictionary&amp;lt;string,string&amp;gt; called &amp;quot;my
list&amp;quot;.&amp;#160; When I use the var keyword, I have to type out enough information
from which intellisense can narrow down what I'm looking for.&amp;#160; I hear a lot from
the proponents of var how great it is because complex declarations, especially with
generics, can be avoided.&amp;#160; I disagree and only need to show you the example below
to prove my point.&amp;#160; In the example below I'm writing the exact same line of code.&amp;#160;
The first example uses var, the second does not, which would you prefer?
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_6.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="262" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_thumb_2.png" width="450" border="0" /&gt;&lt;/a&gt;&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_8.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="139" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/MyIssuesWithVar_FE/image_thumb_3.png" width="526" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
When using var I had to type everything since the compile cannot help me, only I had
to type on the right hand side of the expression.&amp;#160; So I really have saved nothing.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codinghorror.com"&gt;Jeff Atwood&lt;/a&gt; posted that &lt;a href="http://www.codinghorror.com/blog/archives/001136.html"&gt;by
not using var, you're being redundant&lt;/a&gt;.&amp;#160; I would say that by not being redundant,
for which the compiler penalizes you nothing, you're being slower, because you cannot
take advantage of build-in assistance, ie intellisense.
&lt;/p&gt;
&lt;p&gt;
These two annoyances won't stop me from using var in various (read: limited) situations.&amp;#160;
The point of this post is to caution the reader to not be too quick to jump on the
var bandwagon.&amp;#160; In the first example it may cause you headaches in performing
proper testing and in the second, it may slow you down with the loss of intellisense.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=6c8e3d51-a59c-4325-92f1-deb8d28c2a88" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,6c8e3d51-a59c-4325-92f1-deb8d28c2a88.aspx</comments>
      <category>.NET</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=4fe51b35-8314-4092-a496-c6c226037868</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,4fe51b35-8314-4092-a496-c6c226037868.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,4fe51b35-8314-4092-a496-c6c226037868.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=4fe51b35-8314-4092-a496-c6c226037868</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A coworker ran across the following and shared with me. 
</p>
        <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 1:</span>
              <span style="color: #0000ff">Dim</span> strpage</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span> strpage
= pageNumber.ToString()</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 3:</span>
              <span style="color: #0000ff">If</span> Len(strpage)
= 1 <span style="color: #0000ff">Then</span></pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 4:</span> strpage
= <span style="color: #006080">"000"</span> &amp; strpage</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 5:</span>
              <span style="color: #0000ff">ElseIf</span> Len(strpage)
= 2 <span style="color: #0000ff">Then</span></pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 6:</span> strpage
= <span style="color: #006080">"00"</span> &amp; strpage</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 7:</span>
              <span style="color: #0000ff">ElseIf</span> Len(strpage)
= 3 <span style="color: #0000ff">Then</span></pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 8:</span> strpage
= <span style="color: #006080">"0"</span> &amp; strpage</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 9:</span>
              <span style="color: #0000ff">End</span>
              <span style="color: #0000ff">If</span>
            </pre>
          </div>
        </div>
        <p>
The programmer is trying to ensure that the page number, when printed out, is always
four characters long.  This is not the best way to write this code.  I thought
I'd keep this post to myself but unfortunately this isn't the first time I've seen
code like this, it is quite common.
</p>
        <p>
The better way to write the above is:
</p>
        <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 1:</span>
              <span style="color: #0000ff">Dim</span> strpage</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span> strpage
= pagenumber.ToString(<span style="color: #006080">"0000"</span>)</pre>
          </div>
        </div>
        <p>
It's shorter, more concise, and easier to read.  Further the second example is
more extensible.  If the requirements change to say the page number should be
five characters, the first example must recompile.  The second example must be
recompiled as well in it's current state, however the string "0000" could
be moved to a configuration file somewhere and then wouldn't need to be.
</p>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=4fe51b35-8314-4092-a496-c6c226037868" />
      </body>
      <title>Formatting Output with ToString()</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,4fe51b35-8314-4092-a496-c6c226037868.aspx</guid>
      <link>http://www.timbarcz.com/blog/FormattingOutputWithToString.aspx</link>
      <pubDate>Sun, 13 Jul 2008 01:25:51 GMT</pubDate>
      <description>&lt;p&gt;
A coworker ran across the following and shared with me. 
&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; strpage&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; strpage
= pageNumber.ToString()&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; Len(strpage)
= 1 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 4:&lt;/span&gt; strpage
= &lt;span style="color: #006080"&gt;&amp;quot;000&amp;quot;&lt;/span&gt; &amp;amp; strpage&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 5:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; Len(strpage)
= 2 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 6:&lt;/span&gt; strpage
= &lt;span style="color: #006080"&gt;&amp;quot;00&amp;quot;&lt;/span&gt; &amp;amp; strpage&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 7:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ElseIf&lt;/span&gt; Len(strpage)
= 3 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 8:&lt;/span&gt; strpage
= &lt;span style="color: #006080"&gt;&amp;quot;0&amp;quot;&lt;/span&gt; &amp;amp; strpage&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 9:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
The programmer is trying to ensure that the page number, when printed out, is always
four characters long.&amp;#160; This is not the best way to write this code.&amp;#160; I thought
I'd keep this post to myself but unfortunately this isn't the first time I've seen
code like this, it is quite common.
&lt;/p&gt;
&lt;p&gt;
The better way to write the above is:
&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; strpage&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; strpage
= pagenumber.ToString(&lt;span style="color: #006080"&gt;&amp;quot;0000&amp;quot;&lt;/span&gt;)&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
It's shorter, more concise, and easier to read.&amp;#160; Further the second example is
more extensible.&amp;#160; If the requirements change to say the page number should be
five characters, the first example must recompile.&amp;#160; The second example must be
recompiled as well in it's current state, however the string &amp;quot;0000&amp;quot; could
be moved to a configuration file somewhere and then wouldn't need to be.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=4fe51b35-8314-4092-a496-c6c226037868" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,4fe51b35-8314-4092-a496-c6c226037868.aspx</comments>
      <category>.NET</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=29c99e82-9dcf-4669-97a7-326dd3c8f714</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,29c99e82-9dcf-4669-97a7-326dd3c8f714.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,29c99e82-9dcf-4669-97a7-326dd3c8f714.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=29c99e82-9dcf-4669-97a7-326dd3c8f714</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
About a month ago <a href="http://www.jpboodhoo.com" target="_blank">Jean-Paul Boodhoo</a> announced
a contest that he was sponsoring.  The <a href="http://www.jpboodhoo.com/blog/BuildingASolidCoreYourFutureIsRightAheadOfYouTheContest.aspx" target="_blank">contest
idea</a> centered around the idea of developing passion in others around you. 
I have an immense amount of respect for JP having met him at <a href="http://altdotnet.org/events/seattle" target="_blank">ALT.NET
Seattle</a>.  When the contest was announced I thought I'd put in an entry as
I enjoy the journey passion for my craft has taken me on with others.  Here is
my entry in its entirety:
</p>
        <blockquote>
          <p>
While I'm not quite sure that my entry will be legal - a bit on that in a second -
I would still like to share my story.  As for the legality of my entry, the rules
clearly state "Must be working full time as a software professional (<b>not a student</b>)"
(emphasis mine).  While I <i><b>am</b></i>a full time software professional,
I must say that I am, unequivocally, a student.  We all are, whether we realize
it or not.  The one truth I keep encountering in my maturation as a developer
is a bit of a paradox: the more I learn, the more I realize I don't know.  Therefore
I approach software development as a student and view my coworkers as students as
well.
</p>
          <p>
            <br />
When I started at my last place of employment I was humbled early and often by my
lack of knowledge in areas I thought I knew well.  Rather than being deterred,
it sparked a fire in me, and since then I've never turned back.  Being humble
and realizing, for lack of better words, how stupid I was, was quite possibly the
best thing for my maturation as a software professional.  That spark has matured
into a passion that I can best describe as the feeling of a child on Christmas morning,
eagerly shaking his sleeping brothers and sisters telling them that Santa has come. 
It's the type of knowledge where you share it not to show how much smarter or better
you are, but because you are, at your core, excited at the chance to share it with
someone else. 
</p>
          <p>
            <br />
Among things like reading blogs, starting a blog of my own, listening to podcasts,
I started to teach more. There are a great many people who believe that the best way
to learn is to teach others.  I fall squarely in that camp.  I began by
timidly teaching a few of the weekly developer trainings that the company offered. 
Soon, I was teaching quite regularly and in 2007, I taught more than anyone else in
the company.  I focused many of my talks on areas where I struggled and on things
I wanted to learn, realizing that if I struggled learning a concept/language/framework,
others probably did as well.  In one training session I created an elaborate
hands-on demonstration of how events and delegates work.  Participants were given
a card stating what they should do when a specific event occurred.  It started
innocently with me turning off the light switch and, at it's height, had people walking
all over the room, some making marks on the white board, others moving objects around
the room, and still others doing various assigned tasks.  I was told later by
someone that, "...it was the best training of events and delegates they ever had seen." 
That comment was special to me.  
</p>
          <p>
            <br />
Why do I think I deserve to win this contest?  Honestly, I don't know that I
do.  I'm not an "alpha" type, I haven't produced tons of tutorials or webcasts
to help the community, and most of you probably have never heard of me.  However,
I believe that if you ask current and former coworkers, they would say that I seek
to help and mentor others as well as offer myself up to be mentored.  To me,
more than having a large internet following, I desire to impact those around me. 
Below are two recent such examples.  The first is an email I received a bit after
I left my last place of employment:
</p>
          <blockquote>
            <p>
Hey Tim,
</p>
            <p>
How are you and howz your new work? Hope you have settled down. 
</p>
            <p>
Here same as usual , I got to take your big desk J yeeeeee . Josh A is sitting at
your place with my small desk. 
</p>
            <p>
              <b>Hey listen thanks for introducing Rhino mock , I am getting better at it and I
like it ….</b>
            </p>
            <p>
Usharani Kachegere
</p>
          </blockquote>
          <p>
The second example is is from a younger developer, Toran Billups, who emailed me one
day out of the blue when he saw that I updated my alumni page on our college website. 
Toran emailed me innocently one day asking about my work experience.  We started
chatting more and more and I provided whatever guidance I could to him.  I have
enjoyed my time mentoring Toran, as it's been a bit more focused with one-on-one time. 
I've gotten the chance to see him grow in his skill, and more importantly, his passion. 
Below are some of his comments about his experience over the last year and a half
in a recent chat:
</p>
          <blockquote>
            <p>
"I think from the moment I 'emailed you' to ask for some 'mentor like advice' you
have shown a true passion for software development/learning/etc."
</p>
            <p>
"your words have pushed me to a level I only dreamed of 11 months ago"
</p>
            <p>
"I'm knee deep in TDD and in part because of your words!"
</p>
            <p>
"I just built a house - otherwise ... i would move just to work with you- honestly"
</p>
            <p>
"it's like something happened after talking to you last year ... I never had anyone
challenge me like you did"
</p>
            <p>
"but again - without your 'patience' / 'care for others in the community' -- you could
have brushed me off with a simple 'newb' comment instead - you took the time (out
of your busy day) to help ask the 'right questions'
</p>
          </blockquote>
          <p>
If you're reading this and you've found yourself losing passion for your craft, family,
or faith, don't sit idly by.  Do something, anything, to get back into it. 
Do what whatever it takes to reawaken your passion and foster that passion, you'll
be much happier person for it.  I wrote last summer on my blog about passion
in a post titled "<a href="http://www.timbarcz.com/blog/2007/07/22/PassionInProgrammers.aspx">Passion
in Programmers</a>", and I believe what I wrote in that post to be as true today as
the day I wrote it.  In it I wrote, "Passion in my mind is a key characteristic
of being a great developer.  A passionate developer will never stop learning
and enjoys the journey of learning and thus is an asset to any team." 
</p>
        </blockquote>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=29c99e82-9dcf-4669-97a7-326dd3c8f714" />
      </body>
      <title>My "Building A Solid Core" Contest Entry</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,29c99e82-9dcf-4669-97a7-326dd3c8f714.aspx</guid>
      <link>http://www.timbarcz.com/blog/MyBuildingASolidCoreContestEntry.aspx</link>
      <pubDate>Tue, 08 Jul 2008 11:48:36 GMT</pubDate>
      <description>&lt;p&gt;
About a month ago &lt;a href="http://www.jpboodhoo.com" target="_blank"&gt;Jean-Paul Boodhoo&lt;/a&gt; announced
a contest that he was sponsoring.&amp;nbsp; The &lt;a href="http://www.jpboodhoo.com/blog/BuildingASolidCoreYourFutureIsRightAheadOfYouTheContest.aspx" target="_blank"&gt;contest
idea&lt;/a&gt; centered around the idea of developing passion in others around you.&amp;nbsp;
I have an immense amount of respect for JP having met him at &lt;a href="http://altdotnet.org/events/seattle" target="_blank"&gt;ALT.NET
Seattle&lt;/a&gt;.&amp;nbsp; When the contest was announced I thought I'd put in an entry as
I enjoy the journey passion for my craft has taken me on with others.&amp;nbsp; Here is
my entry in its entirety:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
While I'm not quite sure that my entry will be legal - a bit on that in a second -
I would still like to share my story.&amp;nbsp; As for the legality of my entry, the rules
clearly state "Must be working full time as a software professional (&lt;b&gt;not a student&lt;/b&gt;)"
(emphasis mine).&amp;nbsp; While I &lt;i&gt;&lt;b&gt;am&lt;/b&gt; &lt;/i&gt;a full time software professional,
I must say that I am, unequivocally, a student.&amp;nbsp; We all are, whether we realize
it or not.&amp;nbsp; The one truth I keep encountering in my maturation as a developer
is a bit of a paradox: the more I learn, the more I realize I don't know.&amp;nbsp; Therefore
I approach software development as a student and view my coworkers as students as
well.
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
When I started at my last place of employment I was humbled early and often by my
lack of knowledge in areas I thought I knew well.&amp;nbsp; Rather than being deterred,
it sparked a fire in me, and since then I've never turned back.&amp;nbsp; Being humble
and realizing, for lack of better words, how stupid I was, was quite possibly the
best thing for my maturation as a software professional.&amp;nbsp; That spark has matured
into a passion that I can best describe as the feeling of a child on Christmas morning,
eagerly shaking his sleeping brothers and sisters telling them that Santa has come.&amp;nbsp;
It's the type of knowledge where you share it not to show how much smarter or better
you are, but because you are, at your core, excited at the chance to share it with
someone else. 
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
Among things like reading blogs, starting a blog of my own, listening to podcasts,
I started to teach more. There are a great many people who believe that the best way
to learn is to teach others.&amp;nbsp; I fall squarely in that camp.&amp;nbsp; I began by
timidly teaching a few of the weekly developer trainings that the company offered.&amp;nbsp;
Soon, I was teaching quite regularly and in 2007, I taught more than anyone else in
the company.&amp;nbsp; I focused many of my talks on areas where I struggled and on things
I wanted to learn, realizing that if I struggled learning a concept/language/framework,
others probably did as well.&amp;nbsp; In one training session I created an elaborate
hands-on demonstration of how events and delegates work.&amp;nbsp; Participants were given
a card stating what they should do when a specific event occurred.&amp;nbsp; It started
innocently with me turning off the light switch and, at it's height, had people walking
all over the room, some making marks on the white board, others moving objects around
the room, and still others doing various assigned tasks.&amp;nbsp; I was told later by
someone that, "...it was the best training of events and delegates they ever had seen."&amp;nbsp;
That comment was special to me.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
Why do I think I deserve to win this contest?&amp;nbsp; Honestly, I don't know that I
do.&amp;nbsp; I'm not an "alpha" type, I haven't produced tons of tutorials or webcasts
to help the community, and most of you probably have never heard of me.&amp;nbsp; However,
I believe that if you ask current and former coworkers, they would say that I seek
to help and mentor others as well as offer myself up to be mentored.&amp;nbsp; To me,
more than having a large internet following, I desire to impact those around me.&amp;nbsp;
Below are two recent such examples.&amp;nbsp; The first is an email I received a bit after
I left my last place of employment:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Hey Tim,
&lt;/p&gt;
&lt;p&gt;
How are you and howz your new work? Hope you have settled down. 
&lt;/p&gt;
&lt;p&gt;
Here same as usual , I got to take your big desk J yeeeeee . Josh A is sitting at
your place with my small desk. 
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Hey listen thanks for introducing Rhino mock , I am getting better at it and I
like it ….&lt;/b&gt;
&lt;/p&gt;
&lt;p&gt;
Usharani Kachegere
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The second example is is from a younger developer, Toran Billups, who emailed me one
day out of the blue when he saw that I updated my alumni page on our college website.&amp;nbsp;
Toran emailed me innocently one day asking about my work experience.&amp;nbsp; We started
chatting more and more and I provided whatever guidance I could to him.&amp;nbsp; I have
enjoyed my time mentoring Toran, as it's been a bit more focused with one-on-one time.&amp;nbsp;
I've gotten the chance to see him grow in his skill, and more importantly, his passion.&amp;nbsp;
Below are some of his comments about his experience over the last year and a half
in a recent chat:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
"I think from the moment I 'emailed you' to ask for some 'mentor like advice' you
have shown a true passion for software development/learning/etc."
&lt;/p&gt;
&lt;p&gt;
"your words have pushed me to a level I only dreamed of 11 months ago"
&lt;/p&gt;
&lt;p&gt;
"I'm knee deep in TDD and in part because of your words!"
&lt;/p&gt;
&lt;p&gt;
"I just built a house - otherwise ... i would move just to work with you- honestly"
&lt;/p&gt;
&lt;p&gt;
"it's like something happened after talking to you last year ... I never had anyone
challenge me like you did"
&lt;/p&gt;
&lt;p&gt;
"but again - without your 'patience' / 'care for others in the community' -- you could
have brushed me off with a simple 'newb' comment instead - you took the time (out
of your busy day) to help ask the 'right questions'
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
If you're reading this and you've found yourself losing passion for your craft, family,
or faith, don't sit idly by.&amp;nbsp; Do something, anything, to get back into it.&amp;nbsp;
Do what whatever it takes to reawaken your passion and foster that passion, you'll
be much happier person for it.&amp;nbsp; I wrote last summer on my blog about passion
in a post titled "&lt;a href="http://www.timbarcz.com/blog/2007/07/22/PassionInProgrammers.aspx"&gt;Passion
in Programmers&lt;/a&gt;", and I believe what I wrote in that post to be as true today as
the day I wrote it.&amp;nbsp; In it I wrote, "Passion in my mind is a key characteristic
of being a great developer.&amp;nbsp; A passionate developer will never stop learning
and enjoys the journey of learning and thus is an asset to any team." 
&lt;/p&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=29c99e82-9dcf-4669-97a7-326dd3c8f714" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,29c99e82-9dcf-4669-97a7-326dd3c8f714.aspx</comments>
      <category>Musings</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=1136e7c9-b88d-4f52-a572-e2ec389dd24e</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,1136e7c9-b88d-4f52-a572-e2ec389dd24e.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,1136e7c9-b88d-4f52-a572-e2ec389dd24e.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1136e7c9-b88d-4f52-a572-e2ec389dd24e</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Compare the following two error messages and think about which you would find more
helpful.  Then, the next time you are throwing exceptions with messages remember
this post.
</p>
        <h3>Error Message from Castle's Windsor IoC libraries:
</h3>
        <blockquote>
          <h4>
            <i>Can't create component 'ProductService' as it has dependencies to be satisfied. </i>
          </h4>
          <h4>
            <i>ProductService is waiting for the following dependencies:</i>
          </h4>
          <h4>
            <i>Services: </i>
            <i>
              <br />
- ABCCompany.Framework.Services.IInventoryService which was registered but is also
waiting for dependencies. </i>
          </h4>
          <h4>
            <i>ControllerInventory is waiting for the following dependencies: </i>
          </h4>
          <h4>
            <i>Services: 
<br />
- ABCCompany.Controller.IInventoryRequestInterpreter which was not registered. 
<br /></i>
            <p>
            </p>
            <b>Description: </b>An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about the error and
where it originated in the code.
</h4>
          <p>
            <b>Exception Details: </b>Castle.MicroKernel.Handlers.HandlerException: Can't create
component 'ProductService' as it has dependencies to be satisfied. 
</p>
          <p>
ProductService is waiting for the following dependencies: 
</p>
          <p>
Services: 
<br />
- ABCCompany.Framework.Services.IInventoryService which was registered but is also
waiting for dependencies. 
</p>
          <p>
ControllerInventory is waiting for the following dependencies: 
</p>
          <p>
Services: 
<br />
- ABCCompany.Controller.IInventoryRequestInterpreter which was not registered. 
</p>
        </blockquote>
        <h3>
        </h3>
        <h3>Error Message from .NET framework:
</h3>
        <blockquote>
          <h4>
            <i>Object reference not set to an instance of an object.</i>
          </h4>
          <b>Description: </b>An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about the error and
where it originated in the code. 
<br /><b>Exception Details: </b>System.NullReferenceException: Object reference not set
to an instance of an object.</blockquote>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=1136e7c9-b88d-4f52-a572-e2ec389dd24e" />
      </body>
      <title>Assistive Exception Messages</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,1136e7c9-b88d-4f52-a572-e2ec389dd24e.aspx</guid>
      <link>http://www.timbarcz.com/blog/AssistiveExceptionMessages.aspx</link>
      <pubDate>Tue, 17 Jun 2008 20:05:47 GMT</pubDate>
      <description>&lt;p&gt;
Compare the following two error messages and think about which you would find more
helpful.&amp;nbsp; Then, the next time you are throwing exceptions with messages remember
this post.
&lt;/p&gt;
&lt;h3&gt;Error Message from Castle's Windsor IoC libraries:
&lt;/h3&gt;
&lt;blockquote&gt; 
&lt;h4&gt;&lt;i&gt;Can't create component 'ProductService' as it has dependencies to be satisfied. &lt;/i&gt;
&lt;/h4&gt;
&lt;h4&gt;&lt;i&gt;ProductService is waiting for the following dependencies:&lt;/i&gt;
&lt;/h4&gt;
&lt;h4&gt;&lt;i&gt;Services: &lt;/i&gt;&lt;i&gt; 
&lt;br&gt;
- ABCCompany.Framework.Services.IInventoryService which was registered but is also
waiting for dependencies. &lt;/i&gt;
&lt;/h4&gt;
&lt;h4&gt;&lt;i&gt;ControllerInventory is waiting for the following dependencies: &lt;/i&gt;
&lt;/h4&gt;
&lt;h4&gt;&lt;i&gt;Services: 
&lt;br&gt;
- ABCCompany.Controller.IInventoryRequestInterpreter which was not registered. 
&lt;br&gt;
&lt;/i&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;b&gt;Description: &lt;/b&gt;An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about the error and
where it originated in the code.
&lt;/h4&gt;
&lt;p&gt;
&lt;b&gt;Exception Details: &lt;/b&gt;Castle.MicroKernel.Handlers.HandlerException: Can't create
component 'ProductService' as it has dependencies to be satisfied. 
&lt;/p&gt;
&lt;p&gt;
ProductService is waiting for the following dependencies: 
&lt;/p&gt;
&lt;p&gt;
Services: 
&lt;br&gt;
- ABCCompany.Framework.Services.IInventoryService which was registered but is also
waiting for dependencies. 
&lt;/p&gt;
&lt;p&gt;
ControllerInventory is waiting for the following dependencies: 
&lt;/p&gt;
&lt;p&gt;
Services: 
&lt;br&gt;
- ABCCompany.Controller.IInventoryRequestInterpreter which was not registered. 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;Error Message from .NET framework:
&lt;/h3&gt;
&lt;blockquote&gt; 
&lt;h4&gt;&lt;i&gt;Object reference not set to an instance of an object.&lt;/i&gt;
&lt;/h4&gt;
&lt;b&gt;Description: &lt;/b&gt;An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about the error and
where it originated in the code. 
&lt;br&gt;
&lt;b&gt;Exception Details: &lt;/b&gt;System.NullReferenceException: Object reference not set
to an instance of an object.&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=1136e7c9-b88d-4f52-a572-e2ec389dd24e" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,1136e7c9-b88d-4f52-a572-e2ec389dd24e.aspx</comments>
      <category>.NET</category>
      <category>Programming</category>
      <category>Software</category>
    </item>
  </channel>
</rss>