<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" 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:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Making Stuff Faster</title>
        <link>http://geekswithblogs.net/johnsPerfBlog/Default.aspx</link>
        <description>Design, Code, Database Performance</description>
        <language>en-US</language>
        <copyright>John Conwell</copyright>
        <managingEditor>john@nwmountainplay.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Making Stuff Faster</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/johnsPerfBlog/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>MDbg: a managed wrapper around ICorDebug!</title>
            <category>Ramblings</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/13/mdbg-a-managed-wrapper-around-icordebug.aspx</link>
            <description>&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;Recently a performance bug came my way.&lt;span style=""&gt;  &lt;/span&gt;A highly multithreaded application, that can run for hours depending on the amount of data its processing, was observed having all its CPUs ramping up to 100% utilization, and the amount of data processed per second dropped down to nothing.&lt;span style=""&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;Ok, no big deal here.&lt;span style=""&gt;  &lt;/span&gt;I've most likely got a state where all threads are stuck in a tight loop (most likely the same loop), and each thread is waiting on the other to set a flag that will allow them to exit the loop.&lt;span style=""&gt;    &lt;/span&gt;Your basic deadlock issue.&lt;span style=""&gt;  &lt;/span&gt;Pretty easy to fix, if I can reproduce the problem on my dev machine and use the debugger to tell me what the offending function is. &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;The problem is that I wasn’t able to reproduce it.&lt;span style=""&gt;  &lt;/span&gt;Crap. &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;Ok…on to step two… &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;Looks like I'll have to find or build a tool that can give me the call stack of all the threads in a managed app.&lt;span style=""&gt;  &lt;/span&gt;I started out trying to use System.Diagnostics.StackTrace, and StackFrame.&lt;span style=""&gt;  &lt;/span&gt;From a System.Thread instance I can get create a StackTrace object and see what function the thread is in.&lt;span style=""&gt;  &lt;/span&gt;But I cant get a list of all System.Thread objects in an app.&lt;span style=""&gt;  &lt;/span&gt;I have access to the Process.Threads collection, but that gives me a list of System.Diagnostics.ProcessThread objects, not System.Thread.&lt;span style=""&gt;  &lt;/span&gt;Shoot…that’s not going to work. &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;Ok, next step is to look at creating a really light weight debugger, from .Net's ICorDebug api, to basically break into the app and dump out the call stack of all the managed threads.&lt;span style=""&gt;  &lt;/span&gt;I found a couple examples and it didn’t look too bad, but the only issue is that ICorDebug is a COM API.&lt;span style=""&gt;  &lt;/span&gt;So I'd have to do all that fun C++ COM stuff…Ick.&lt;span style=""&gt;  &lt;/span&gt;And I need the tool yesterday. &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;After digging around a bit more I found out that the Visual Studio debugger team wrote a very nice managed wrapper around ICorDebug, called MDbg.&lt;span style=""&gt;  &lt;/span&gt;Sweet! &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;There is a &lt;a href="http://blogs.msdn.com/jmstall/archive/2005/11/08/mdbg_linkfest.aspx"&gt;bunch of info about it here.&lt;/a&gt; &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;After digging a bit further, I found that someone write a handy little tool called &lt;a href="http://www.codeplex.com/MSE"&gt;Managed Stack Explorer&lt;/a&gt;.&lt;span style=""&gt;  &lt;/span&gt;Oh geez!&lt;span style=""&gt;  &lt;/span&gt;The gods are smiling at me!&lt;span style=""&gt;  &lt;/span&gt;That’s exactly what I need.&lt;span style=""&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;This little tool shows all managed apps running on your server.&lt;span style=""&gt;  &lt;/span&gt;When you pick an app, it shows all threads in the process.&lt;span style=""&gt;  &lt;/span&gt;When you click the thread, it shows you the call stack for that thread.&lt;span style=""&gt;  &lt;/span&gt;Simple and nice.&lt;span style=""&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;With this tool, I was able to find the offending non-threadsafe function in about 5 minutes.&lt;span style=""&gt;  &lt;/span&gt;Fixed, done, yipee. &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;But this post and about someone's tool, of my bug fixing adventures.&lt;span style=""&gt;  &lt;/span&gt;No, its about coming across one of the most useful APIs I've seen in a long time!&lt;span style=""&gt;  &lt;/span&gt;A simple and well designed .Net wrapper around ICorDebug, giving .Net developers full access to the CLR debugger.&lt;span style=""&gt;  &lt;/span&gt;I'm very excited about the idea of a managed wrapper around ICorDebug.&lt;span style=""&gt;  &lt;/span&gt;There are so many diagnostic tools that could be created with this.&lt;span style=""&gt;  &lt;/span&gt;I'm looking forward to digging around in the API!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125807"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125807" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/125807.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/13/mdbg-a-managed-wrapper-around-icordebug.aspx</guid>
            <pubDate>Mon, 13 Oct 2008 16:51:41 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/125807.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/13/mdbg-a-managed-wrapper-around-icordebug.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/125807.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/125807.aspx</trackback:ping>
        </item>
        <item>
            <title>Many core processors and parallel processing</title>
            <category>Parallel Processing</category>
            <category>Many-Core Processors</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/06/many-core-processors-and-parallel-processing.aspx</link>
            <description>Although most of topics I've written about are pretty random, I'll try to focus in on a much more narrow (yet incredibly broad) topic: multi core vs many core processing, parallel processing, and the paradigm shift that we software engineers are on the leading edge of having to face.&lt;br /&gt;
&lt;br /&gt;
To put it in short Intel, AMD, and other hardware manufacturers are telling anyone that listens that programmers need to change the way they think about designing enduser software.  End-user software needs to take advantage of multiple cores.  And this doesn't mean spinning up a background thread to do some compute intensive request, so that our UI remains responsive.  It means designing all compute intensive algorithms to scale to multiple processors. &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://software.intel.com/en-us/articles/developing-for-terascale-on-a-chip-first-article-in-the-series"&gt;Intel goes on to say&lt;/a&gt; that designing for 2, 4, or 8 processors is way to short sighted.  We need to design our software to scale out to N processors; where N could be 16, 64, or 512.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.codinghorror.com/blog/archives/000942.html"&gt;Coding Horror has a great post from last year&lt;/a&gt; that demonstrates how well common end user software take advantage of multi core processors.  The results as sad to say the least.&lt;br /&gt;
&lt;br /&gt;
We can no longer just expect our software to get faster with the next chip release by Intel or AMD.  What is worse, our software will most likely run slower on newer desktop and mobile chips.&lt;br /&gt;
&lt;br /&gt;
The trends in processor manufacturing is to have slower, cooler, more efficient individual cores, and to pack more and more of them on a single chip.  This means that end user software that only use 1 or 2 threads will actually run slower on newer processors. &lt;br /&gt;
&lt;br /&gt;
This can be seen with Intel's new quad core mobile processor: QX9300.  It has 4 cores, supporting hyper threading so it shows 8 cores in task manager, but runs at 2.53 GHz.  This is an amazing chip, but only for software that is actually designed to run across multiple cores.&lt;br /&gt;
&lt;br /&gt;
To boil it down to a simplified problem statement: Software outlives hardware, and hardware ain't getting any faster.  (more on that later)&lt;br /&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125662"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125662" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/125662.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/06/many-core-processors-and-parallel-processing.aspx</guid>
            <pubDate>Mon, 06 Oct 2008 16:05:03 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/125662.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/06/many-core-processors-and-parallel-processing.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/125662.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/125662.aspx</trackback:ping>
        </item>
        <item>
            <title>Complexity and Usability</title>
            <category>Design</category>
            <category>Ramblings</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2008/07/22/complexity-and-usability.aspx</link>
            <description>&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;Generally I'm not one to write a post that does nothing but highlight someone else's blog post...BUT...this one was important enough (IMHO) that I decided to break my own rule.  &lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;&lt;font size="4"&gt;&lt;span style="font-weight: bold;"&gt;Are you building a Leatherman or a Samurai sword?  &lt;/span&gt;&lt;font size="1"&gt;(stupid linker isnt working)&lt;/font&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;&lt;font size="4"&gt;&lt;font size="2"&gt;http://petewarden.typepad.com/searchbrowser/2008/07/are-you-buildin.html  &lt;/font&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;As programmers we always want to write new functionality...neat, new, COOL functionality.  That's just what we do, and we love it.  &lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;But its hard to keep in mind what our added functionality does to user efficiency.  No matter what we think our job is all about, its really about making the lives of our users easier and more efficient.&lt;span style=""&gt;  &lt;/span&gt;That’s it…done…its that simple.&lt;span style=""&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;This is easy to understand when writing a UI application.&lt;span style=""&gt;  &lt;/span&gt;If a new feature causes the use to perform 5 extra steps with the UI, but those 5 extra steps only give a small return on efficiency (so small it wasn’t worth the time to perform the 5 new steps), than drop the feature, its not worth it.&lt;span style=""&gt;  &lt;/span&gt;If the feature is complex or confusing, and will cause the user to misuse it or skip it all together, than drop the feature, its not worth it.&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;Where this becomes harder to evaluate is in writing an SDK API.&lt;span style=""&gt;  &lt;/span&gt;Like the above post states, we all want to write the ultimate architecture.&lt;span style=""&gt;  &lt;/span&gt;The one that can do anything and everything.&lt;span style=""&gt;  &lt;/span&gt;But "anything and everything" can quickly become a directionless mess, where you have a several hundred of classes with obvious direction on how to weave them together into the next "Wonder Bread".&lt;span style=""&gt;  &lt;/span&gt;What you end up with is a big mess that your users (other developers) will mostly likely just pass off as too complex and look for a simpler API.&lt;span style=""&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt;"&gt;The last part of the above post states it perfectly.&lt;span style=""&gt;  &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Calibri; font-size: 11pt; color: rgb(0, 0, 255);"&gt;"You end up with a million features, which makes it very time-consuming to build, and even when it's done, the number of different gizmos on your Leatherman scare off potential users. You need to have a strong connection to your actual customers, and be hearing about exactly what they need to do. Then you need to design around that, ruthlessly jettisoning anything that distracts from them achieving their goals."&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=123943"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=123943" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/123943.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2008/07/22/complexity-and-usability.aspx</guid>
            <pubDate>Tue, 22 Jul 2008 16:10:07 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/123943.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2008/07/22/complexity-and-usability.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/123943.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/123943.aspx</trackback:ping>
        </item>
        <item>
            <title>Creating an instance of a generic paremeter is slooooo: part deux</title>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-paremeter-is-slooooo-part.aspx</link>
            <description>For grins I looked at my code that calls:&lt;br /&gt;
&lt;br /&gt;
T tmp = new T();&lt;br /&gt;
&lt;br /&gt;
in &lt;a title="Lutz Roeder's Reflector" href="http://www.aisto.com/roeder/dotnet/" target="_blank"&gt;Reflector&lt;/a&gt;, so see if it could shed any light into T instance creation badness.  Well, it turns out that the C# compiler spits out code to call Activator.CreateInstance&lt;br /&gt;
&lt;br /&gt;
&lt;a title="T // Generic Argument"&gt;T&lt;/a&gt; &lt;strong&gt;tmp&lt;/strong&gt; = &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Activator" title="System.Activator"&gt;Activator&lt;/a&gt;.&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Activator/CreateInstance%3C%3E():%3C!!0%3E" title="T System.Activator.CreateInstance&amp;lt;T&amp;gt;();"&gt;CreateInstance&lt;/a&gt;&amp;lt;&lt;a title="T // Generic Argument"&gt;T&lt;/a&gt;&amp;gt;(); &lt;br /&gt;
&lt;br /&gt;
I kind of get why the C# compiler does this, because it doesnt know what T is at compile time.  But at run time the JIT compiler DOES know.  I'm surprised that the C# team didn't build in the smarts to JIT code to explicitly call the default constructor of whatever type T is.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122850"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122850" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/122850.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-paremeter-is-slooooo-part.aspx</guid>
            <pubDate>Fri, 13 Jun 2008 19:30:08 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/122850.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-paremeter-is-slooooo-part.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/122850.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/122850.aspx</trackback:ping>
        </item>
        <item>
            <title>Creating an instance of a generic paremeter is slooooo</title>
            <category>Code Performance</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-type-is-slooooo-again.aspx</link>
            <description>I recently needed to change how an array lookup worked to make it more efficient, and decided to use the List&amp;lt;T&amp;gt;.BinarySearch to do the lookup.  The class that contained this lookup had a generic parameter, and was constrained like so:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public class SortedNameList&amp;lt;T&amp;gt; where T : class, INameValueItem, new()&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;{...}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
where the T of List&amp;lt;T&amp;gt; was the same as the class generic parameter.&lt;br /&gt;
&lt;br /&gt;
In order to do the BinarySearch, List&amp;lt;T&amp;gt; required an input of type T to search against.  Since I only had the value of the property that will be compared against (an int), I needed to create a new temp instance of T, set the value, and then pass it into BinarySearch().&lt;br /&gt;
&lt;br /&gt;
My unit tests passed, all the functionality was good, and I was happy.  Then I ran the my app under a profiler to see how much faster my fancy BinarySearch was.  &lt;br /&gt;
&lt;br /&gt;
To my surprise, the time spent doing the binary search calls was almost exactly the same as a linear lookup (over 1.2 million searches)!  What the heck?  I know that creating a new temp object each lookup isn't very efficient, but it shouldn't make that much of a difference.&lt;br /&gt;
&lt;br /&gt;
So after looking a bit deeper and doing some more performance tests, I found out that creating a new instance of a generic ("&lt;span style="color: rgb(0, 0, 255);"&gt;T tmp = new T()&lt;/span&gt;") is sloooooo.  How slow?  How about 30X slower!  WOW...I had no idea!&lt;br /&gt;
&lt;br /&gt;
And its not that it takes the CLR some time to figure out how to create a new T, where most of the time is on the first instance, and the rest speed up.  Nope, the duration to create a new T is consistant, from the first instance to the millionth instance.&lt;br /&gt;
&lt;br /&gt;
Good to know...dont do that in a high volume area&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122842"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122842" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/122842.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-type-is-slooooo-again.aspx</guid>
            <pubDate>Fri, 13 Jun 2008 15:40:46 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/122842.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-type-is-slooooo-again.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/122842.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/122842.aspx</trackback:ping>
        </item>
        <item>
            <title>No more null checking on your IEnumerables before you iterate over them</title>
            <category>Ramblings</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2008/05/29/no-more-null-checking-on-your-ienumerables-before-you-iterate.aspx</link>
            <description>I get a bit sick of checking for null on my IEnumerable objects before doing a foreach over them.  In my opinion I think the CLR should check if the list is null, and if it is just exit out of the foreach iteration as if there were no items in it.&lt;br /&gt;
&lt;br /&gt;
Well, I was goofing around with Extension Methods a bit and figured out how to get this kind of functionality (sort of). &lt;br /&gt;
&lt;br /&gt;
Now unfortunatly Extension Methods cant override an existing method on a type, so I cant just create a new GetEnumerator extension method (well, actually i can make one, but it wont get called).  But I can create a new method that returns IEnumerable, and just call the foreach on it.&lt;br /&gt;
&lt;br /&gt;
So in order to do this, first add this class to your code&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public static class MyExtnesionMethods&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;{&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    public static IEnumerable&amp;lt;T&amp;gt; Enum&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt; input)&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    {&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        if (input != null)&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        {&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;            foreach (var t in input)&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;            {&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;                yield return t;&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;            }&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        }&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        else&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        {&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;            yield break;&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        }&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    }&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now, anything that inherits from IEnumerable&amp;lt;T&amp;gt; will have the Enum method.  Then all you have to do is call foreach on someClass.Enum(), even if someClass is null.  Below is an example of ho this works.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;static void Main(string[] args)&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;{&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    List&amp;lt;string&amp;gt; names = new List&amp;lt;string&amp;gt;()&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        {"john", "kim", "jean", "brent"};&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    //iterate names using stock enumerator&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    foreach (string name in names)                &lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        Console.WriteLine(name);&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    &lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    //iterate names using extension method&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    foreach (string name in names.Enum())&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        Console.WriteLine(name);&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    names = null;&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    //oh man!  I have to check for null...I hate that&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    if (names != null)&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        foreach (string name in names)&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;            Console.WriteLine(name);&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    //Yea!  I dont have to check for null anymore!&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    foreach (string name in names.Enum())&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;        Console.WriteLine(name);&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The extension method uses the "yield return" and "yield break" iterator syntax to let the foreach either spin over the IEnumerable if its not null, or if it is null, "yield break" returns false from the IEnumerable.MoveNext which tells the foreach that there are no more items in the list so it should break out of the loop.&lt;br /&gt;
&lt;br /&gt;
So, no more null checks!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Update&amp;gt;&lt;br /&gt;
A reader commented that this could be optimized by using the static method Enumerable.Empty&amp;lt;T&amp;gt;.  This would save an object instance from being created by the yield return functionality.  The new and improved Extension Method is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;public static IEnumerable&amp;lt;T&amp;gt; Enum&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt; input)&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;{&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;    return input ?? Enumerable.Empty&amp;lt;T&amp;gt;();&lt;/span&gt;&lt;br style="color: rgb(0, 0, 255);" /&gt;
&lt;span style="color: rgb(0, 0, 255);"&gt;}&lt;/span&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122487"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122487" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/122487.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2008/05/29/no-more-null-checking-on-your-ienumerables-before-you-iterate.aspx</guid>
            <pubDate>Thu, 29 May 2008 23:14:15 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/122487.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2008/05/29/no-more-null-checking-on-your-ienumerables-before-you-iterate.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/122487.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/122487.aspx</trackback:ping>
        </item>
        <item>
            <title>NTEXT vs NVARCHAR(MAX) in SQL 2005</title>
            <category>SQL Server Performance</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2008/04/16/ntext-vs-nvarcharmax-in-sql-2005.aspx</link>
            <description>I recently profiled a sproc that makes heavy use of the TSQL SUBSTRING function (hundreds of thousands of times) to see how it performs on a SQL 2005 database compared to a SQL 2000 database.  Much to my surprise the SQL 2005 database performed worse...dramatically worse than SQL 2000.&lt;br /&gt;
&lt;br /&gt;
After much researching it turns out the problem is that the column the text was stored in was an NTEXT, but SQL 2005 has deprecated the NTEXT in favor of NVARCHAR(MAX).  Now, you'd think that string functions on NTEXT would have the same performance on 2005 as it did on 2000, but thats not the case.  &lt;br /&gt;
&lt;br /&gt;
Ok, so NTEXT is old badness, and NVARCHAR(MAX) is new goodness.  Then the next logical step would be to convert the column to be a NVARCHAR(MAX) data type, but here lies a little but very important gotcha.&lt;br /&gt;
&lt;br /&gt;
By default NTEXT stores the text value in the LOB structure and the table structure just holds a pointer to the location in the LOB where the text lives.  &lt;br /&gt;
&lt;br /&gt;
Conversely, the default setting for NVARCHAR(MAX) is to store its text value in the table structure, unless the text is over 8,000 bytes at which point it behaves like an NTEXT and stores the text value in the LOB , and stores a pointer to the text in the table.&lt;br /&gt;
&lt;br /&gt;
So, just to recap, the default settings for NTEXT and NVARCHAR(MAX) are completely opposite.&lt;br /&gt;
&lt;br /&gt;
Now, what do you think will happen when you execute an ALTER COLUMN on a NTEXT column that changes the data type to a NVARCHAR(MAX)?  Where do you think the data will be stored?  In the LOB structure or the table structure?&lt;br /&gt;
&lt;br /&gt;
Well, lets walk through an example.  First create a table with one NTEXT column:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;CREATE TABLE [dbo].[testTable](&lt;/span&gt;&lt;br style="background-color: rgb(204, 255, 204);" /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;    [testText] [ntext] NULL&lt;/span&gt;&lt;br style="background-color: rgb(204, 255, 204);" /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]&lt;/span&gt;&lt;br style="background-color: rgb(204, 255, 204);" /&gt;
&lt;br /&gt;
Next, put 20 rows in the table:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;INSERT INTO testTable SELECT 'hmmm...i wonder if this will work'&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Then run a select query with IO STATISTICS:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;SET STATISTICS IO ON&lt;/span&gt;&lt;br style="background-color: rgb(204, 255, 204);" /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;SELECT * FROM testTable&lt;/span&gt;&lt;br style="background-color: rgb(204, 255, 204);" /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;SET STATISTICS IO OFF&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now, looking at the IO stats, we see there was only 1 logical read, but 60 LOB logical reads.  This is pretty much as expected as NTEXT stores its text value in the LOB not the table: &lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;Table 'testTable'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, &lt;span style="font-weight: bold;"&gt;lob logical reads 60&lt;/span&gt;, lob physical reads 0, lob read-ahead reads 0.&lt;/span&gt;&lt;br style="background-color: rgb(204, 255, 204);" /&gt;
&lt;br /&gt;
Now, lets alter the table to be an NVARCHAR(MAX):&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;ALTER TABLE testTable ALTER COLUMN testText NVARCHAR(MAX) null&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now when we run the select query again with UI STATISTICS we still get a lot of LOB reads (though less than we did with NTEXT).  So its obvious that when SQL Server did the alter table, it didn't use the default NVARCHAR(MAX) setting of text in row, but kept the text in the LOB and still uses pointers lookups to get the text out of the LOB.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;Table 'testTable'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, &lt;span style="font-weight: bold;"&gt;lob logical reads 40&lt;/span&gt;, lob physical reads 0, lob read-ahead reads 0.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This is not as expected and can be devastating for performance if you don't catch it, since NVARCHAR(MAX) with text &lt;span style="font-weight: bold;"&gt;not in row&lt;/span&gt; actually performs &lt;span style="font-weight: bold;"&gt;WORSE&lt;/span&gt; than NTEXT when doing SUBSTRING calls.&lt;br /&gt;
&lt;br /&gt;
So how do we fix this problem?  Its actually fairly easy.  After running your alter table, run an update statement setting the column value to itself, like so:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;UPDATE testTable SET testText = testText&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
SQL server moves the text from the LOB structure to the table (if less than 8,000 bytes).  So when we run the select again with IO STATISTICS we get 0 LOB reads.  &lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: rgb(204, 255, 204);"&gt;Table 'testTable'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, &lt;span style="font-weight: bold;"&gt;lob logical reads 0&lt;/span&gt;, lob physical reads 0, lob read-ahead reads 0.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
YEA!  This is what we want.&lt;br /&gt;
&lt;br /&gt;
Now, just for grins, what do you think happens if we change the NVARCHAR(MAX) back to NTEXT?  Well it turns out that SQL Server moves the text back to the LOB structure.  Completely backwards from what it did when converting NTEXT to NVARCHAR(MAX).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121297"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121297" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/121297.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2008/04/16/ntext-vs-nvarcharmax-in-sql-2005.aspx</guid>
            <pubDate>Wed, 16 Apr 2008 21:34:57 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/121297.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2008/04/16/ntext-vs-nvarcharmax-in-sql-2005.aspx#feedback</comments>
            <slash:comments>12</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/121297.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/121297.aspx</trackback:ping>
        </item>
        <item>
            <title>Easily write Reflection.Emit code</title>
            <category>Code Performance</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/28/easily-write-reflection.emit-code.aspx</link>
            <description>I was looking at Refletor addins the other day and ran across one that would be an amazing time saver.  &lt;br /&gt;
&lt;br /&gt;
Its an addin that generates the Reflection.Emit code!&lt;br /&gt;
&lt;br /&gt;
Anyone who has ever spent any time with the Reflection.Emit namespace should immediately realize how wonderful this tool has the potential to be (as long as the generated code is of good quality of course).&lt;br /&gt;
&lt;br /&gt;
Also, the way integrates with &lt;a title="Lutz Roeder's Reflector" href="http://www.aisto.com/roeder/dotnet/" target="_blank"&gt;Reflector&lt;/a&gt; is pretty slick.  It adds a "Reflection.Emit" choice in the list of languages you want Reflection to display the code in.  Then, in the left pane,when you click a module, class, method, property, whatever, it displays the Reflection.Emit code in the right pane that you would have to write to generate the thing you clicked on.&lt;br /&gt;
&lt;br /&gt;
Simple...and amazing!&lt;br /&gt;
&lt;br /&gt;
I recently spent 6 days writing Reflection.Emit code to generate two fairly complex methods.  2 days each for writing the code, and 1 day each for debugging it and making it actually work.  I probably could have cut that down to 1 to 2 days using this tool.&lt;br /&gt;
&lt;br /&gt;
I haven't yet compared the addin's generated Reflection Emit code to the code i've written manually to validate its quality, but just playing around with it, the generated code looks pretty good.&lt;br /&gt;
&lt;br /&gt;
It can be found here:&lt;br /&gt;
http://www.codeplex.com/reflectoraddins/Wiki/View.aspx?title=ReflectionEmitLanguage&amp;amp;referringTitle=Home&lt;br /&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120819"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120819" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/120819.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/28/easily-write-reflection.emit-code.aspx</guid>
            <pubDate>Fri, 28 Mar 2008 15:43:28 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/120819.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/28/easily-write-reflection.emit-code.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/120819.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/120819.aspx</trackback:ping>
        </item>
        <item>
            <title>The Instrumentation  Model</title>
            <category>Code Performance</category>
            <category>Design</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/26/the-instrumentation--model.aspx</link>
            <description>&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt;I've spent a lot of time lately thinking about instrumentation and how to integrate it into software projects.&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt; &lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt;As a performance engineer I tend to think about instrumentation from the point of view of someone who wants to record the details of what a system is doing, and then dig through the data and use it to figure out what is wrong.&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt; &lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt;But I’ve been talking to people the past few months about instrumentation, I’ve come to realize that instrumentation means different things to different people.&lt;span style=""&gt;  &lt;/span&gt;Some people think of instrumentation as a high level, light weight set of metrics that are easy to consume, understand, and extrapolate performance deltas; a management point of view.&lt;span style=""&gt;  &lt;/span&gt;Other people, like me, think of it as recording low level details of what’s going on in the call stacks and sql engine; a trouble shooter point of view. And then others think its somewhere in between; everyone else.&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt; &lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt;Well, I think everyone is correct.&lt;span style=""&gt;  &lt;/span&gt;There are different levels of instrumentation that are useful at different points in validating system health.&lt;span style=""&gt;  &lt;/span&gt;There should be easy to consume and understand metrics to validate day to day health checks, there is medium level detail instrumentation that is used to figure out where a problem is, but takes a bit more effort to analyze.&lt;span style=""&gt;  &lt;/span&gt;And if that isn’t enough to find and fix the problem, there is the dump everything to file model that gives you all the data you need to understand what is going on in the system, but requires internal knowledge of the system and time to analyze the data.&lt;span style=""&gt;  &lt;/span&gt;Also, each level builds upon the other, so there is as little duplicated effort as possible.&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt; &lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt;So I’ve tried to create an instrumentation model demonstrate these different levels, the answers each level tries to answer, and when you move onto the next level&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt; &lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt;The first level will provide you with the most early bang for your buck, and it’s a easy way to tell if you have a problem, with as little dev effort as possible.&lt;span style=""&gt;  &lt;/span&gt;Then as you get the high level metrics in, you can start building in the mid level metrics, and so on.&lt;span style=""&gt;  &lt;/span&gt;The main thing is to not try and build the entire instrumentation framework up front before you put anything it.&lt;span style=""&gt;  &lt;/span&gt;Start putting high level metrics in early and use then in your automated testing&lt;/p&gt;
&lt;br /&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/johnsPerfBlog/7892/o_InstrumentationModel.JPG" target="_blank"&gt;&lt;img width="525" height="425" border="1" align="left" alt="Instrumentation Model Image" src="/images/geekswithblogs_net/johnsPerfBlog/InstrumentationModel.JPG" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="margin: 0in; font-family: Verdana; font-size: 10pt;"&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120786"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120786" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/120786.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/26/the-instrumentation--model.aspx</guid>
            <pubDate>Thu, 27 Mar 2008 05:02:33 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/120786.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/26/the-instrumentation--model.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/120786.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/120786.aspx</trackback:ping>
        </item>
        <item>
            <title>Code Analysis Tools</title>
            <category>Code Performance</category>
            <category>Data Mining</category>
            <category>Design</category>
            <category>Ramblings</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2006/08/29/89691.aspx</link>
            <description>&lt;P&gt;I've started working on a collection of code analysis tools, that are open source and available&amp;nbsp;for anyone to use.&amp;nbsp; I've got a descriptive article located at CodeProject.com (&lt;A href="http://www.codeproject.com/cs/algorithms/Not_Used_Analysis.asp"&gt;http://www.codeproject.com/cs/algorithms/Not_Used_Analysis.asp&lt;/A&gt;), which includes the source code and binaries.&lt;/P&gt;
&lt;P&gt;The three main tools that I have so far are the following:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;A &amp;#8220;Not Used Finder&amp;#8221;: searches through a list of assemblies and looks for any type, method or field that isnt ever used.&amp;nbsp; Points out code that you should be able to remove.&lt;/LI&gt;
&lt;LI&gt;A visibility analysis: searches through a list of assemblies and looks at the visibility of methods and types and shows those that have a visibility higher than is required based on current usage.&lt;/LI&gt;
&lt;LI&gt;A Duplicate / Near Duplicate code analysis&lt;/LI&gt;&lt;/UL&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=89691"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=89691" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/89691.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2006/08/29/89691.aspx</guid>
            <pubDate>Tue, 29 Aug 2006 17:40:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/89691.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2006/08/29/89691.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/89691.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/89691.aspx</trackback:ping>
        </item>
        <item>
            <title>Introduction to Creating Dynamic Types with Reflection.Emit parts 1 and 2</title>
            <category>Ramblings</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2006/05/02/76959.aspx</link>
            <description>&lt;P&gt;I've recently finished part two of a series of articles on creating dynamic types with System.Reflection.Emit.&amp;nbsp; Dynamic types are types, or classes, manually generated and inserted into an AppDomain at runtime, from within the program.&amp;nbsp; The two articles are linked below.&lt;/P&gt;
&lt;P&gt;Part 1:&lt;BR&gt;&lt;A href="http://www.codeproject.com/dotnet/Creating_Dynamic_Types.asp"&gt;http://www.codeproject.com/dotnet/Creating_Dynamic_Types.asp&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Part 2:&lt;BR&gt;&lt;A href="http://www.codeproject.com/useritems/Creating_Dynamic_Types2.asp"&gt;http://www.codeproject.com/useritems/Creating_Dynamic_Types2.asp&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;I'm curious though.&amp;nbsp; I've got ideas for two more articles, but dont know if people would be interested in them.&amp;nbsp; The third article in this series would cover how to create an Aspect Oriented Programming framework via Reflection.Emit.&amp;nbsp; And the fourth article would go over how to debug dynamic types.&amp;nbsp; Would anyone be interested in these topics?&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=76959"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=76959" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/76959.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2006/05/02/76959.aspx</guid>
            <pubDate>Tue, 02 May 2006 13:00:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/76959.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2006/05/02/76959.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/76959.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/76959.aspx</trackback:ping>
        </item>
        <item>
            <title>Generic IComparer&lt;T&gt; is a good thing.  And null comparisons</title>
            <category>Code Performance</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2006/04/07/74594.aspx</link>
            <description>&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;There is something I've been wanting to post about for a while, but just didn&amp;#8217;t have enough info to make it worth my, or anyone who reads this, while.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;We all know that .Net 2.0 came out with something wonderful called Generics.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;I've been profiling a lot of my 1.1 code, comparing it to my 2.0 code that utilizes Generics, and the one change that has given me the greatest, most dramatic performance benefits is to switch from IComparer to IComparer&lt;T&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;I use IComparer a LOT.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;But there is a problem with it is it's Compare() method.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;The following is the pattern I use on all my compare functions:&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;public int Compare(object x, object y)&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;{&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt;if (x == null || y == null)&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; mso-outline-level: 3"&gt;throw new ApplicationException("Invalid NGram Compare");&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt;NGram n1 = x as NGram;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt;NGram n2 = y as NGram;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt;return n1.Score.CompareTo(n2.Score);&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;It takes an object for both its comparison operators.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Then I have to cast it to NGram before I can compare against my Score property.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;This extra step may not be much, but if you are sorting an array that holds 1.5 million NGram objects, this adds up to a LOT of operations.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Enter IComparer&lt;T&gt;!&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;This is the Generics version of IComparer, and its compare function would look like this for IComparer&lt;NGRAM&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;public int Compare(NGram x, NGram y)&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;{&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt;if (x == null || y == null)&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; mso-outline-level: 3"&gt;throw new ApplicationException("Invalid NGram Compare");&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt;return x.Score.CompareTo(y.Score);&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;}&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Notice that two NGram instances are passed into the Compare function, instead of two objects.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;This lets me save the casting operations.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;YEAH!&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;It must be faster, right?&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;So like any good performance guy (or gall for that matter) I revved up my favorite code profiler and ran two tests: one with the generic comparer and one with the object comparer, and sorted an array of 1.5 million NGram objects a few times.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;And guess what I saw.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;The generics comparer was slower than the object comparer.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;And not just a little bit slower either.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;But 61% slower!!!&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Oh my gosh&amp;#8230;what the hell is going on here?&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Generics have to be faster!&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Its less code!&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;So, to get to the bottom of this mystery, I opened my assembly in &lt;A title="Lutz Roeder's Reflector" href="http://www.aisto.com/roeder/dotnet/" target=_blank&gt;Reflector&lt;/A&gt; and took a peek at the IL code for each function.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;I know IL doesn&amp;#8217;t lie to me.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;What I saw was very interesting, and it had to do with checking an object to see if it is null.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;This is a section of IL from the generics Compare function.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0000: ldarg.1 &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0001: ldnull &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0002: call bool NGram::op_Equality(NGram, NGram)&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0007: brtrue.s L_0012&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0009: ldarg.2 &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_000a: ldnull &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_000b: call bool NGram::op_Equality(NGram, NGram)&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0010: brfalse.s L_001d&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0012: //throw exception stuff&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;This is pretty much what I expected to see.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Argument 1 is loaded onto the stack, then a null is loaded onto the stack.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Then the NGram's operator equality function is called to see if the two are the same or not (is the ngram null).&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;If it is, then it branches down to the throw new exception code.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;It then loads argument 2 onto the stack, and another null onto the stack.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;And does another NGram operator equality check.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Like I said before, nothing really amazing here, and pretty much what I'd expect.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;The IL has to call the operator Equality function just to be sure that I didn&amp;#8217;t override it in my NGram class.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Ok, now lets take a look at how nulls were checked I the object comparer's IL code to see what was so different that it would be 61% faster.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;This is what I saw:&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_000e: ldarg.1 &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_000f: brfalse.s L_0014&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0011: ldarg.2 &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0012: brtrue.s L_001f&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;L_0014: //throw exception stuff&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Damn&amp;#8230;that&amp;#8217;s a lot less code!&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;What's going on here?&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Well, it looks like the IL compiler does something that the C# compiler wont let you get away with.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;In C++ a NULL, a 0, and FALSE are all the same thing.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;They are all 0.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;But the C# compiler doesn&amp;#8217;t allow you to make this leap.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Null, 0, and false are three distinctly different things.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;So what the IL code is doing is loading the first NGram instance onto the stack, then just doing a false equality check.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Since null the same as false (in IL) this works just fine.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;The C# compiler knows, when comparing null an object that is casted all the way down to Object, it can just compare it to false and call it good.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;So why didn&amp;#8217;t the C# compiler do this for the NGram null comparison?&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Because I could have overloaded the == operator in my NGram class, that&amp;#8217;s why.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;And if I did, then it would need to call it.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;But doesn&amp;#8217;t the C# compiler have enough info to check if I have overloaded it or not, and if not do a false comparison?&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Yes it does, but it looks like that&amp;#8217;s one optimization it doesn&amp;#8217;t do, unfortuanttly&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;So to test this theory out, I took the null check out of my IComparer&lt;NGram&gt;.Compare function and re-ran my test code under the profiler, and this time the generic comparer without the null checks were 66% faster than the object comparer.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Ahhhh, satisfaction at last.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt; &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;This exercise reinforced something in my head.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Even if you KNOW that thing a is faster then thing b, always profile it just to be sure.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Yes, a generic typed comparer is much faster than a normal object comparer.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;But if I had just done the code change and called it good, I would have actually slowed my app down.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Which is a bad thing.&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=74594"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=74594" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/74594.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2006/04/07/74594.aspx</guid>
            <pubDate>Fri, 07 Apr 2006 19:52:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/74594.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2006/04/07/74594.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/74594.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/74594.aspx</trackback:ping>
        </item>
        <item>
            <title>Color Picker Visual Studio Macro</title>
            <category>Ramblings</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2006/03/13/72219.aspx</link>
            <description>&lt;FONT size=2&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;Every now and then I need to create a color object in my code, but don&amp;#8217;t know exactly what color I want.&amp;nbsp; So I created this little macro to popup the ColorDialog, then insert a little line of code for the color you picked.&lt;/SPAN&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;Nothing magic or special here, just another useful macro.&amp;nbsp; The only problem with it is the color dialog comes up behind Visual Studio so you have to Alt-Tab to see it.&amp;nbsp; A bit annoying,&amp;nbsp;I know.&amp;nbsp; If anyone figures that one out I'll post the fix.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Public Sub ColorPicker() &lt;BR&gt;Dim colorDlg As New ColorDialog &lt;BR&gt;colorDlg.AllowFullOpen = True &lt;BR&gt;colorDlg.AnyColor = True &lt;BR&gt;colorDlg.FullOpen = True &lt;BR&gt;colorDlg.SolidColorOnly = False &lt;BR&gt;Dim ret As DialogResult = colorDlg.ShowDialog() &lt;BR&gt;If ret = DialogResult. Cancel Then &lt;BR&gt;Return &lt;BR&gt;End If &lt;BR&gt;Dim color As System.Drawing.Color = colorDlg.Color &lt;BR&gt;Dim code As String &lt;BR&gt;If color.IsNamedColor Then &lt;BR&gt;code = "Color color = Color." + color.Name + ";" &lt;BR&gt;Else &lt;BR&gt;code = "Color color = Color.FromArgb(" + color.ToArgb().ToString() + ");" &lt;BR&gt;End If &lt;BR&gt;Dim textSelection As TextSelection = DTE.ActiveDocument.Selection() &lt;BR&gt;Dim edit As EditPoint = textSelection.TopPoint.CreateEditPoint() &lt;BR&gt;edit.Insert(code) &lt;BR&gt;End Sub&lt;/FONT&gt;&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=72219"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=72219" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/72219.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2006/03/13/72219.aspx</guid>
            <pubDate>Mon, 13 Mar 2006 18:36:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/72219.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2006/03/13/72219.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/72219.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/72219.aspx</trackback:ping>
        </item>
        <item>
            <title>Nice VS 2005 Snippet Collection</title>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2006/02/23/70535.aspx</link>
            <description>&lt;P&gt;Ever since I discovered snippets in Visual Studio 2005, I've been using them like crazy.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Microsoft has a good list of pre-canned snippets (&lt;A href="http://msdn.microsoft.com/vstudio/downloads/codesnippets/"&gt;http://msdn.microsoft.com/vstudio/downloads/codesnippets/&lt;/A&gt;) in 13 different categories.&lt;/P&gt;
&lt;P&gt;But the best category of snippets I've found thoroughly covers NUnit code templates.&amp;nbsp; It's located here: &lt;A href="http://www.codeproject.com/dotnet/UnitTestCodeSnips.asp"&gt;http://www.codeproject.com/dotnet/UnitTestCodeSnips.asp&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Combining these NUnit code snippets, with TestDriven.Net (&lt;A href="http://www.testdriven.net/"&gt;http://www.testdriven.net/&lt;/A&gt;) and it really makes it easy to practice&amp;nbsp;test driven development&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=70535"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=70535" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/70535.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2006/02/23/70535.aspx</guid>
            <pubDate>Thu, 23 Feb 2006 17:46:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/70535.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2006/02/23/70535.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/70535.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/70535.aspx</trackback:ping>
        </item>
        <item>
            <title>Invaluable tool!</title>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/21/63778.aspx</link>
            <description>&lt;P&gt;Yesterday I stumbled across a totally invaluable tool to help with unit testing your code in Visual Studio:&amp;nbsp; &lt;A href="http://www.testdriven.net/"&gt;TestDriven.Net&lt;/A&gt;. (formerly known as NUnitAddIn)&amp;nbsp; It's a Visual Studio addin that allows you to run your NUnit, MbUnit, Team System, and soon Zanebug&amp;nbsp;unit tests by just right clicking on the test method, class or namspace and clicking the &amp;#8220;Run Test(s)&amp;#8221; menu item.&amp;nbsp; You can run just one test, all the tests in a class or all the tests in the namespace.&amp;nbsp; This is cool and all, but the best part is that it will allow you to run the test under debug.&amp;nbsp; So you set your break point in the unit test, right click and pick &amp;#8220;Test with...Debugger&amp;#8221; and boom!, you've now got the process caught on your breakpoint.&amp;nbsp; No more attaching the debugger&amp;nbsp;to a running&amp;nbsp;NUnit process.&amp;nbsp; This is especially nice if you need native code support with the debugger, because when you detach the debugger from NUnit, NUnit would get closed.&lt;/P&gt;
&lt;P&gt;Now this isn't a total replacement for using NUnit when TDD'ing.&amp;nbsp; You still would want to run the entire suite of tests fairly often.&amp;nbsp; Its writing individual tests where this tool really shines.&lt;/P&gt;
&lt;P&gt;And did I mention the best part?&amp;nbsp; Its free!&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=63778"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=63778" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/63778.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/21/63778.aspx</guid>
            <pubDate>Wed, 21 Dec 2005 14:34:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/63778.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/21/63778.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/63778.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/63778.aspx</trackback:ping>
        </item>
        <item>
            <title>NMock or NUnit.Mocks</title>
            <category>Design</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/19/63555.aspx</link>
            <description>&lt;P&gt;Does anybody have any experience with either of these two types of mock objects?&amp;nbsp; Over the past few months I have gone back and taken a new look at Test Driven Development and am starting to&amp;nbsp;switch the way&amp;nbsp;I think about writing code.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;In writing some of my unit tests I've had a need for a mock object framework.&amp;nbsp; In looking around, i've noticed that these two seem to be the two brightest stars in the .Net universe in respect to mock objects.&lt;/P&gt;
&lt;P&gt;Can anyone compare and contrast them? Give some insight into using them?&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=63555"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=63555" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/63555.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/19/63555.aspx</guid>
            <pubDate>Mon, 19 Dec 2005 13:51:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/63555.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/19/63555.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/63555.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/63555.aspx</trackback:ping>
        </item>
        <item>
            <title>Top 3 hard rock / metal cover songs</title>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/05/62223.aspx</link>
            <description>&lt;P&gt;So I've recently been looking for fun rock / metal covers of songs from the 60's / 70's / 80's.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;My top 3 favorites are:&lt;/P&gt;1. Deadsy's cover of Rush's &amp;#8220;Tom Sawyer&amp;#8220;&lt;BR&gt;2. Korn's cover of Pink Floyd's &amp;#8220;Another Brink in the Wall &lt;BR&gt;3. Metalica's cover of Bob Seger's &amp;#8220;Turn the Page&amp;#8220; 
&lt;P&gt;What are your favorites?&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=62223"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=62223" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/62223.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/05/62223.aspx</guid>
            <pubDate>Mon, 05 Dec 2005 14:11:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/62223.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/05/62223.aspx#feedback</comments>
            <slash:comments>23</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/62223.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/62223.aspx</trackback:ping>
        </item>
        <item>
            <title>Interfaces or abstract classes, or There is no silver bullet</title>
            <category>Design</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61553.aspx</link>
            <description>&lt;P&gt;A few weeks ago &lt;A href="http://www.geekswithblogs.com/johnsperfblog/archive/2005/11/21/60813.aspx"&gt;I&amp;nbsp;attended an AOP workshop at Microsoft&lt;/A&gt;.&amp;nbsp; One of the AOP flavors that was presented&amp;nbsp;requires you to implement an interface for every class that you want to apply aspects too.&amp;nbsp; I find this fairly annoying and constricting.&amp;nbsp; When I voiced my concern about having to create one interface for every class in my 600 class architecture, I was told by the majority of the&amp;nbsp;people there, from both academia and the CLR team,&amp;nbsp;that this is how you should design your framework anyway.&amp;nbsp; That interfaces allows for the greatest extensibility.&lt;/P&gt;
&lt;P&gt;Interestingly enough, I just started reading a book called &lt;A href="http://www.amazon.com/gp/product/0321246756/104-1996328-1083907?v=glance&amp;amp;n=283155&amp;amp;n=507846&amp;amp;s=books&amp;amp;v=glance"&gt;Framework Design Guidelines, written by Krysztof Cwalina and Brad Abrams&lt;/A&gt;, both heavy hitters at Microsoft.&amp;nbsp; In chapter 4, Type Design Guidelines, they state that when designing a polymorphic hierarchy for reference types, in general, you should opt for using abstract classes vs interfaces.&amp;nbsp; The book states that when applying a &amp;#8220;Is A&amp;#8220; relationship you should utilize an abstract class.&amp;nbsp; And if you are applying a&amp;nbsp;&amp;#8220;Can Do&amp;#8221; relationship to a class, then you use an interface (IDisposable, IEnumerable, IComparable).&amp;nbsp; The main argument here is that interfaces should be immutable from version to version, but base classes can evolve with much greater ease.&amp;nbsp; The only major&amp;nbsp;down side to using abstract classes vs interfaces is that .Net only allows 1 class inheritance, but you can interface inherit all day long.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;My main programming mantra states that there is &lt;A href="http://www.amazon.com/gp/product/0201835959/104-1996328-1083907?v=glance&amp;amp;n=283155&amp;amp;s=books&amp;amp;v=glance"&gt;no silver bullet&lt;/A&gt;.&amp;nbsp; There is no &amp;#8220;One&amp;#8221; tool.&amp;nbsp; Each tool has a purpose, and should only be used for that purpose and that purpose alone.&amp;nbsp; When designing a system, look at your requirements and use the tools that fit the situation appropriately.&amp;nbsp; Don't try to force the use of a tool just because you used it before.&amp;nbsp; Try to understand what the tool's use is for.&amp;nbsp; But it seems people are looking for the Matrix version of a programming tool.&amp;nbsp; The One...&lt;/P&gt;
&lt;P&gt;When I&amp;nbsp;here people saying &amp;#8220;Every class should have an explicitly defined interface&amp;#8221; it really makes me wonder where this comes from.&amp;nbsp; I have to think these guys are throwbacks from the COM days, who didn't really understand why COM did this.&amp;nbsp; They just understood that if it was a class, it had an interface, and they didn't need to know why.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Now, the really interesting thing is that both the authors for the Framework Design Guidelines book are program managers for the CLR team, yet there were people in their team spouting the interface mantra.&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=61553"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=61553" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/61553.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61553.aspx</guid>
            <pubDate>Tue, 29 Nov 2005 14:10:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/61553.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61553.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/61553.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/61553.aspx</trackback:ping>
        </item>
        <item>
            <title>The Eight Fallacies of Distributed Computing</title>
            <category>Ramblings</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61548.aspx</link>
            <description>&lt;P&gt;Someone on GeeksWithBlogs posted this link, but I think it was so important that it deserves a second showing.&amp;nbsp; Its the &lt;A href="http://today.java.net/jag/Fallacies.html"&gt;8 fallacies of distributed computing&lt;/A&gt;.&amp;nbsp; As anyone who has looked through my blog knows, I'm not a big fan of the&amp;nbsp;Web Service&amp;nbsp;storm thats blowing through the programming world.&amp;nbsp; It just doesnt make sense to blindly make massive distributed architectures inside your own fire walls.&amp;nbsp; But companies are doing it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=61548"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=61548" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/61548.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Conwell</dc:creator>
            <guid>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61548.aspx</guid>
            <pubDate>Tue, 29 Nov 2005 13:39:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/61548.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61548.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/61548.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/61548.aspx</trackback:ping>
        </item>
        <item>
            <title>Microsoft AOP workshop highlights</title>
            <category>Design</category>
            <category>Ramblings</category>
            <link>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/21/60813.aspx</link>
            <description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;I previously posted that I had attended a workshop hosted by Microsoft Research on the topic of Aspect Oriented Programming. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;The core purpose of AOP I&amp;#8217;m a firm believer of: to modularize systems more effectively. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;But I&amp;#8217;m still not sold on the AOP implementation of this directive. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;But, I do fine AOP intriguing and have developed an implementation that uses dynamic runtime weaving (more about this below). &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;It works pretty well, and doesn&amp;#8217;t degrade the application performance too bad.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Anyway, for those who want to learn some more about AOP, here are some ramblings about AOP that&amp;nbsp;I pulled out of last week&amp;#8217;s workshop:&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;&lt;A href="http://www.geekswithblogs.com/images/www_geekswithblogs_com/johnsperfblog/3362/r_AOPattendees.jpg"&gt;&lt;IMG alt="Click to view a larger image" src="/images/www_geekswithblogs_com/johnsperfblog/3362/t_AOPattendees.jpg" border=0&gt;&lt;/A&gt; 
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-SIZE: 14pt"&gt;Aspect Oriented Programming Overview&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Problem with regular development practices: &lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;With traditional programming techniques, most code is highly coupled, complex and often there is much "administrative" repetitive code which makes system hard to maintain.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Or worse, in order to make to code less complex, such administrative code is totally left out.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Generally accepted good design practices state that a function should do one thing, and one thing only.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But often a function must do many additional tasks (aspects): logging, error handling, thread safety, etc.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This other "stuff" is often boiler plate code that is copy/pasted around all over the system.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;What is AOP&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;AOP tries to fix this problem by separating these aspects out of the function into some sort of external construct.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The method is then decorated with these aspects in order to tell the runtime environment (or other external process) that they should be applied to the method at runtime.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;This way, the function's source code only does the one thing its supposed to do.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;The concepts of what has become AOP started back in 1987.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Its goal is to modularize systems more effectively, which is nothing new.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Main AOP Terminology&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in" type=disc&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l4 level1 lfo1; tab-stops: list .5in"&gt;Aspects: features of a program that do not relate to the core functionality of the program directly, but are needed for proper program execution 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l4 level1 lfo1; tab-stops: list .5in"&gt;Cross cutting concerns: same thing as an aspect 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l4 level1 lfo1; tab-stops: list .5in"&gt;Join point: point within a program where the aspect can be applied.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;When the process in an application arrives at the join point of the program, the aspect is executed. 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l4 level1 lfo1; tab-stops: list .5in"&gt;Point cut descriptor: one place in source that defines all places where join points are applied to the source. 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l4 level1 lfo1; tab-stops: list .5in"&gt;Attributes: defines a single join point for an aspect in the source. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Standard way in .Net to decorate classes, interfaces, and methods with aspects 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l4 level1 lfo1; tab-stops: list .5in"&gt;Weaving: the act of inserting calls to the aspect into the main program. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;There are many ways to implement this.&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Examples of how AOP can be used to solve some of these problems&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in" type=disc&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Trace output 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Logging 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Checking for error conditions and acting accordingly 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Dynamically generated asserts for method arguments 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Transaction control 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Exception handling (maybe) 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Thread safety and coordination 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;State change and response mechanism 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Singleton pattern mechanism 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Business rule engine implementation (allows business rule logic to change dynamically without redeploying binaries) 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;encryption / decryption 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Generate execution metrics 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Custom security policy enforcement 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Method pre/post processors (much like proxy classes) 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Dynamically override a method (could use for deploying support patches.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Just deploy one aspect with one method.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The rest of the class stays the same) 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Object instance pool management 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Onsite client error debugging 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l2 level1 lfo2; tab-stops: list .5in"&gt;Plug in architecture that customers could use to plug in their custom functionality to our product.&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;Almost all real world commercial implementations of AOP are in Java.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;All (most?) .Net implementations of AOP are either designed through research groups or academia. 
&lt;P&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Simplified example of AOP: &lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Take the following 3 simple classes.&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Point&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 1"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;X()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 2"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Y()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 3; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;UpdateUI()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Line&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 1"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Point1()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 2"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Point2()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 3; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;UpdateUI()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Figure&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 1"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Line1()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 2"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Line2()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 3"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Line3()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 4"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Line4()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 5; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 41.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=55&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;UpdateUI()&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;When any code calls the X or Y property of the Point class, or the Point1 or&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Point2 property of the Line class, it should call the UpdateUI method.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Or the X, Y, Point1 and Point2 properties could call UpdateUI themselves (as well as the Line1-4 properties of Figure).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But then you have duplicate code dispersed throughout the classes that does the same thing.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Not only that, but these properties shouldn&amp;#8217;t really know about a UI at all.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;The UI update logic could be pulled out into an aspect, which is then applied to the class.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;At some point (depending on the type of AOP your&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;using) the AOP weaver would interrogate attributes and determine if any aspects should be executed or not.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Problem to watch out for would be unnecessarily duplicated calls to the aspects.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;For example, what if the developer updates all 4 lines of class Figure? &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;UpdateUI could get called 28 times.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;AOP engine should have ability to specify aspect execution rules along the call stack.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;.Net'ish examples of limited AOP:&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;FileIOPermissionAttribute.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This does a stack walk to check for file IO permission.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;You could put the code in each method, or just apply the attribute at the top of the method.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It keeps the method from getting cluttered&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Problem with .Net and attributes:&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Even though .Net has build in AOP style constructs, they are hard coded into the runtime.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If you define your own attributes, you must also define how and when those attributes are &lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'MS Mincho'; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA"&gt;interrogated and &lt;/SPAN&gt;used.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;.Net does not have a generic way to hook into the runtime to say "When you come across this attribute, do this".&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Different AOP implementation techniques&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;There are 4 &lt;STRONG&gt;main&lt;/STRONG&gt; implementation techniques for AOP&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;1. Static source weaving:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The programming language is extended to include constructs for defining define aspects and where they get applied.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Before the language compiler gets executed, the AOP engine/compiler inspects the source code for aspects.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It then either inlines the aspect code into the method its applied to, or inlines a call to an aspect instance.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This altered source is then run through the language compiler and the resulting exe or dll is generated.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This has best runtime performance since compiler has a chance to apply optimizations.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This is how AspectJ works&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;2. Static byte weaving: The source is compiled through the normal language compiler.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Then an AOP weaver loads the dll/exe into memory.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It looks at the aspect mapping mechanism (this could be an xml file, a new language file like IDL, or attributes) and injects byte code into the dll/exe in the appropriate places to execute the aspect.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The dll or exe is then saved off to file.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;3. Dynamic weaving: dll or exe is compiled through the normal language compiler.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;At runtime, there is some mechanism that emits code into memory to execute the aspects at the appropriate place.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;There are several techniques to do this.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;One approach is to utilize class factories in order to create any instance of a class that has aspects applied to it.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The factory would emit into memory a new class that inherits from the 