<feed 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="http://www.w3.org/2005/Atom" xml:lang="en-US">
    <title>Making Stuff Faster</title>
    <link rel="self" type="application/xml" href="http://geekswithblogs.net/johnsPerfBlog/Atom.aspx" />
    <subtitle type="html">Design, Code, Database Performance</subtitle>
    <id>http://geekswithblogs.net/johnsPerfBlog/Default.aspx</id>
    <author>
        <name>John Conwell</name>
        <uri>http://geekswithblogs.net/johnsPerfBlog/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 0.0.0.0">Subtext</generator>
    <updated>2008-10-13T09:52:50Z</updated>
    <entry>
        <title>MDbg: a managed wrapper around ICorDebug!</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/13/mdbg-a-managed-wrapper-around-icordebug.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/13/mdbg-a-managed-wrapper-around-icordebug.aspx</id>
        <published>2008-10-13T09:51:41-07:00:00</published>
        <updated>2008-10-13T09:52:50Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/125807.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/125807.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>Many core processors and parallel processing</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/06/many-core-processors-and-parallel-processing.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2008/10/06/many-core-processors-and-parallel-processing.aspx</id>
        <published>2008-10-06T09:05:03-07:00:00</published>
        <updated>2008-10-06T09:59:08Z</updated>
        <content type="html">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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/125662.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/125662.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>Complexity and Usability</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2008/07/22/complexity-and-usability.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2008/07/22/complexity-and-usability.aspx</id>
        <published>2008-07-22T09:10:07-07:00:00</published>
        <updated>2008-07-22T09:14:17Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/123943.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/123943.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>Creating an instance of a generic paremeter is slooooo: part deux</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-paremeter-is-slooooo-part.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-paremeter-is-slooooo-part.aspx</id>
        <published>2008-06-13T12:30:08-07:00:00</published>
        <updated>2008-06-13T12:30:08Z</updated>
        <content type="html">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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/122850.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/122850.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>Creating an instance of a generic paremeter is slooooo</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-type-is-slooooo-again.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2008/06/13/creating-an-instance-of-a-generic-type-is-slooooo-again.aspx</id>
        <published>2008-06-13T08:40:46-07:00:00</published>
        <updated>2008-06-13T08:41:41Z</updated>
        <content type="html">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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/122842.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/122842.aspx</wfw:comment>
        <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>
    </entry>
    <entry>
        <title>No more null checking on your IEnumerables before you iterate over them</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2008/05/29/no-more-null-checking-on-your-ienumerables-before-you-iterate.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2008/05/29/no-more-null-checking-on-your-ienumerables-before-you-iterate.aspx</id>
        <published>2008-05-29T16:14:15-07:00:00</published>
        <updated>2008-05-30T09:34:57Z</updated>
        <content type="html">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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/122487.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/122487.aspx</wfw:comment>
        <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>
    </entry>
    <entry>
        <title>NTEXT vs NVARCHAR(MAX) in SQL 2005</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2008/04/16/ntext-vs-nvarcharmax-in-sql-2005.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2008/04/16/ntext-vs-nvarcharmax-in-sql-2005.aspx</id>
        <published>2008-04-16T14:34:57-07:00:00</published>
        <updated>2008-04-16T14:34:57Z</updated>
        <content type="html">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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/121297.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/121297.aspx</wfw:comment>
        <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>
    </entry>
    <entry>
        <title>Easily write Reflection.Emit code</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/28/easily-write-reflection.emit-code.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/28/easily-write-reflection.emit-code.aspx</id>
        <published>2008-03-28T08:43:28-07:00:00</published>
        <updated>2008-03-28T08:43:28Z</updated>
        <content type="html">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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/120819.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/120819.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>The Instrumentation  Model</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/26/the-instrumentation--model.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2008/03/26/the-instrumentation--model.aspx</id>
        <published>2008-03-26T22:02:33-07:00:00</published>
        <updated>2008-03-26T22:09:06Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/120786.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/120786.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>Code Analysis Tools</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2006/08/29/89691.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2006/08/29/89691.aspx</id>
        <published>2006-08-29T10:40:00-07:00:00</published>
        <updated>2006-08-29T10:40:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/89691.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/89691.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>Introduction to Creating Dynamic Types with Reflection.Emit parts 1 and 2</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2006/05/02/76959.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2006/05/02/76959.aspx</id>
        <published>2006-05-02T06:00:00-07:00:00</published>
        <updated>2006-05-02T06:00:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/76959.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/76959.aspx</wfw:comment>
        <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>
    </entry>
    <entry>
        <title>Generic IComparer&lt;T&gt; is a good thing.  And null comparisons</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2006/04/07/74594.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2006/04/07/74594.aspx</id>
        <published>2006-04-07T12:52:00-07:00:00</published>
        <updated>2006-05-01T04:43:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/74594.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/74594.aspx</wfw:comment>
        <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>
    </entry>
    <entry>
        <title>Color Picker Visual Studio Macro</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2006/03/13/72219.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2006/03/13/72219.aspx</id>
        <published>2006-03-13T11:36:00-07:00:00</published>
        <updated>2006-03-13T11:36:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/72219.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/72219.aspx</wfw:comment>
        <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>
    </entry>
    <entry>
        <title>Nice VS 2005 Snippet Collection</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2006/02/23/70535.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2006/02/23/70535.aspx</id>
        <published>2006-02-23T09:46:00-08:00:00</published>
        <updated>2006-02-23T09:46:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/70535.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/70535.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>Invaluable tool!</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/21/63778.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/21/63778.aspx</id>
        <published>2005-12-21T06:34:00-08:00:00</published>
        <updated>2005-12-21T06:34:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/63778.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/63778.aspx</wfw:comment>
        <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>
    </entry>
    <entry>
        <title>NMock or NUnit.Mocks</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/19/63555.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/19/63555.aspx</id>
        <published>2005-12-19T05:51:00-08:00:00</published>
        <updated>2005-12-19T05:51:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/63555.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/63555.aspx</wfw:comment>
        <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>
    </entry>
    <entry>
        <title>Top 3 hard rock / metal cover songs</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/05/62223.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/12/05/62223.aspx</id>
        <published>2005-12-05T06:11:00-08:00:00</published>
        <updated>2005-12-05T06:11:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/62223.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/62223.aspx</wfw:comment>
        <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>
    </entry>
    <entry>
        <title>Interfaces or abstract classes, or There is no silver bullet</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61553.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61553.aspx</id>
        <published>2005-11-29T06:10:00-08:00:00</published>
        <updated>2005-11-29T06:10:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/61553.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/61553.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>The Eight Fallacies of Distributed Computing</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61548.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/29/61548.aspx</id>
        <published>2005-11-29T05:39:00-08:00:00</published>
        <updated>2005-11-29T05:39:00Z</updated>
        <content type="html">&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;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/61548.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/61548.aspx</wfw:comment>
        <slash:comments>0</slash: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>
    </entry>
    <entry>
        <title>Microsoft AOP workshop highlights</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/21/60813.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/21/60813.aspx</id>
        <published>2005-11-21T14:20:00-08:00:00</published>
        <updated>2005-11-21T14:31:00Z</updated>
        <content type="html">&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 class that is being requested.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Any method that has an aspect associated with it would get overridden, and contain calls to the aspects in the appropriate place.&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;One nice thing about this approach is that you can design an AOP to be able to dynamically bind, unbind and change bindings on aspects to join points.&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 means you can change application functionality without ever shutting down the application, which is important for long running server applications such as a database or web server.&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;4. Actually extend the runtime environment and the type loader to create classes with the aspects embedded in them.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This is fairly complex as it requires you to extend the CLR and JIT compiler.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This is the approach that JBoss uses with Java.&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;All of these have their good and bad points.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The first one gave you processor performance, but at the cost of no IDE support (in .Net) for the new language construct for defining the aspect bindings.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Static byte weaving gives you better IDE support, but can break some compiler optimizations because the aspects are woven post build (you have to turn off compiler inlining).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Dynamic weaving forces you to use class factories and code against interfaces for any class that has an aspect.&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;A fifth way (for .Net) to create an aspect weaver that I didn&amp;#8217;t hear presented could follow these steps:&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: l0 level1 lfo4; tab-stops: list .5in"&gt;Post build, parse the binary assembly and recreate the entire assembly in a CodeDom object graph. 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l0 level1 lfo4; tab-stops: list .5in"&gt;Anywhere the weaver found an aspect binding, it would inject the call to the aspect into the code via the CodeDom API. 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l0 level1 lfo4; tab-stops: list .5in"&gt;Then use the C# compiler API to compile the CodeDom back to an assembly. 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l0 level1 lfo4; tab-stops: list .5in"&gt;With this approach, you would have full IDE support because you would just use attributes or an external aspect mapping file.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;You'd have full compiler optimizations because the woven code would be compiled again.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;You don&amp;#8217;t have to use factories and interfaces either.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Also, the CodeDom has debug symbol support, so you could update the debug symbols for the woven aspects. 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l0 level1 lfo4; tab-stops: list .5in"&gt;The hard part would be to write a generic assembly to CodeDom mapping tool.&lt;/LI&gt;&lt;/UL&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;Where are aspects executed in the context of a method:&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;Aspects can get applied in three different ways: at the beginning of the method, the end of the method, or instead of the method.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This is usually specified on the attribute that decorates the method.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;There is some cool work at creating an aspect definition construct to define where specifically in a method to apply an aspect.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;For example, inside a loop, or in the else block of an if / else statement.&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;How are aspects bound to their target method:&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 seem to be four camps on how to tag a method with an aspect.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;With attributes applied directly to the method, class or interface (generally accepted .Net approach).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;With a whole new extension to the language (JAspect approach).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And with an external file, such as an xml mapping file or a new language file much like how IDL was used with COM.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The fourth camp uses method naming conventions to tie the aspect to the method&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;(DoSomething_WithLogging_WithThreadSafety)&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;I like a combination of using Attributes and an xml file.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I think it&amp;#8217;s important to have the visual queue when you&amp;#8217;re coding that this method has an aspect applied to it.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But I like the dynamic flexibility that an external file could give you.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;At runtime you could change the file to turn on or off aspects, change when they are executed, swap one aspect for another.&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;Other directions that use 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;There is another area of AOP that some people are looking at.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Instead of using aspects to separate concerns from the main functionality of a program, they are using aspects to extend existing dlls.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;For instance, if you have a 3rd party dll, you could use static byte weaving to add fields, properties, methods and interfaces to the existing binary.&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;Problems with AOP:&lt;o:p&gt;&lt;/o:p&gt;&lt;/B&gt;&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: l3 level1 lfo5; tab-stops: list .5in"&gt;All approaches have problems with debugger and IDE support. 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l3 level1 lfo5; tab-stops: list .5in"&gt;One of the main ideas of AOP is that Aspects are hidden from most developers.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;A problem with this is that it separates the aspects from the developers which can lead to problems.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;What if the developer doesn&amp;#8217;t know, or forgets, there is an aspect that will apply thread safety checking, or serialization tags? 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l3 level1 lfo5; tab-stops: list .5in"&gt;Also, what about aspect priorities when multiple aspects are applied to the same methods.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Who is executed first?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Are there any considerations?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l3 level1 lfo5; tab-stops: list .5in"&gt;It&amp;#8217;s easier to see these issues when attributes are used to decorate methods with the aspects. 
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none; mso-list: l3 level1 lfo5; tab-stops: list .5in"&gt;How do you find your failure points?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Is it the original source, the aspect source, or the AOP weaver?&lt;/LI&gt;&lt;/UL&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;Future of AOP in .Net and Microsoft:&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;Currently there seems to be about 30'ish different implementations of AOP available in various languages in .Net.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;There doesnt seem to be any leading force withing Microsoft or the CLR team that is driving the integration of AOP into the CLR&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;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:City w:st="on"&gt;&lt;st1:place w:st="on"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Reading&lt;/B&gt;&lt;/st1:place&gt;&lt;/st1:City&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;:&lt;/B&gt; &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;Aspect Oriented Software Development, Addison Wesley&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;Other stuff:&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;It was interesting to see that academic and pure research groups focus totally on "getting it to work".&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But with very little regard to getting it to work easily.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;They didn&amp;#8217;t seem to realize that if the developer had to jump through lots of hoops in order to get the desired functionality, they most people wouldn&amp;#8217;t use it.&lt;/P&gt;&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/60813.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/60813.aspx</wfw:comment>
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/60813.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/60813.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Who else is using / implementing / interested in AOP</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/17/60399.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/17/60399.aspx</id>
        <published>2005-11-17T09:44:00-08:00:00</published>
        <updated>2005-11-17T09:44:00Z</updated>
        <content type="html">&lt;P&gt;How much attention does Aspect Oriented Programming have in the .Net community?&amp;nbsp; Are people using it?&amp;nbsp; implementing it?&amp;nbsp; know what it is?&amp;nbsp; &lt;/P&gt;&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/60399.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/60399.aspx</wfw:comment>
        <slash:comments>6</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/60399.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/60399.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Aspect Oriented Programming Workshop</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/17/60397.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/17/60397.aspx</id>
        <published>2005-11-17T09:38:00-08:00:00</published>
        <updated>2005-11-17T09:38:00Z</updated>
        <content type="html">&lt;P&gt;This last Monday I was fortunate enough to attend a workshop hosted by Microsoft Research on Aspect Oriented Programming.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The workshop most mostly attended by researchers from different universities in the US and Europe (though Brazil was also represented).&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;I've worked on an implementation of AOP in .Net on and off over the past year, and it was interesting to see that several universities were working on implementations that were along the same lines as my own.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;I was surprised to see how many different ways there was to implement AOP.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The four predominant ways were:&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 1in; DIRECTION: ltr; unicode-bidi: embed" type=a&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 2" value=1&gt;Static source weaving: this is where a tool weaves the aspects into the methods in the actual source code.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Then the normal compiler runs on the code&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 2" value=2&gt;Static byte weaving: this is where a post compile process modifies the compiled dll or exe by injecting the aspects into the actual byte code of the dll or exe&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 2" value=3&gt;Dynamic runtime weaving: this is where class factories are used to create instances of types that have aspects applied to them.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The factory uses System.Reflection.Emit to create new types, that inherit from the requested type.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This new type has the aspects woven into them.&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 2" value=4&gt;Modify the runtime / type loader: this is much more complex.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This is where the type loader of the runtime is changed to do the dynamic weaving.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This has the added benefit of not having to use class factories, but very complex to implement.&lt;/LI&gt;&lt;/OL&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;One thing that was interesting to see the lack of any guiding body on AOP within the .Net community.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The Java world has seemed to settle on (mostly) JAspect or JBoss.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;There are now several large scale enterprise software implementations in Java that utilize AOP with either of these two AOP implementations.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;An interesting comment was raised during a discussion as to why the .Net community hasn&amp;#8217;t embraced AOP like the Java community has.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In the Java arena, when someone creates something new, cool, and useful, companies aren't that afraid to integrate that new thing into their development process.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;But in the Microsoft world everybody waits to see what Microsoft will do.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Since the development environment and processes are so tightly integrated into MS products (even more so with MS Team System), companies don&amp;#8217;t want to head off in one direction when there is a chance that MS might go in the other direction.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;So if Microsoft doesn&amp;#8217;t ever feel the need to implement AOP, most likely it will never grow into the mainstream.&lt;/P&gt;&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/60397.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/60397.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/60397.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/60397.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Getting VisualStudio assemblies to work with Cecil</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/10/59726.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/10/59726.aspx</id>
        <published>2005-11-10T13:16:00-08:00:00</published>
        <updated>2005-11-10T13:16:00Z</updated>
        <content type="html">&lt;P&gt;One thing I finally figured out, through the help of the guy that wrote Cecil, is that Cecil wont load Incremental builds.&amp;nbsp; What does that mean?&amp;nbsp; You know how VisualStudio has two build options: Build and Rebuild.&amp;nbsp; Well when you use Build only the methods that change get recompiled.&amp;nbsp; This causes some weirdness in the assembly with the metadata tables&amp;nbsp;that Cecil cant (wont)&amp;nbsp;handle.&lt;/P&gt;
&lt;P&gt;How do you get around this?&amp;nbsp; Recompile is the answer! :-)&amp;nbsp; Recompile compiles all your code and creates proper metadata tables that Cecil can happily parse.&lt;/P&gt;&lt;img src="http://geekswithblogs.net/johnsPerfBlog/aggbug/59726.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/johnsPerfBlog/comments/59726.aspx</wfw:comment>
        <slash:comments>5</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/johnsPerfBlog/comments/commentRss/59726.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/johnsPerfBlog/services/trackbacks/59726.aspx</trackback:ping>
    </entry>
    <entry>
        <title>More about code uniqueness and....Cecil ROCKS!!!!!</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/04/59110.aspx" />
        <id>http://geekswithblogs.net/johnsPerfBlog/archive/2005/11/04/59110.aspx</id>
        <published>2005-11-04T06:15:00-07:00:00</published>
        <updated>2005-11-04T10:41:00Z</updated>
        <content type="html">&lt;P&gt;The tool I referred to &lt;A href="http://www.geekswithblogs.com/johnsperfblog/archive/2005/11/03/59035.aspx"&gt;in my last post about code uniqueness&lt;/A&gt; was FxCop.&amp;nbsp; I'm sure most people have heard of FxCop, but for those that haven't: FxCop provides a way to validate your compiled assemblies against a list of about 200 canned rules.&amp;nbsp; These rules are anything from design guidelines, security checks, performance checks, to globalization standards.&amp;nbsp; FxCop also provides a way for you to create your own rules and hook&amp;nbsp;them into its validation process.&amp;nbsp; Behind the scenes FxCop uses what Microsoft calls an Introspection engine to parse apart the IL opcodes&amp;nbsp;and metadata tables in your assembly and it builds an object graph that represents all interconnections between Namespaces, Types, Members, Fields...all the way down to the individual IL opcodes.&amp;nbsp; This provides an 