<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.atalasoft.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Steve's Tech Talk</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx</link><description>Ruminations on technology, software and philosophy.
</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Lou Francos</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx</link><pubDate>Tue, 06 May 2008 19:25:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13905</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>1</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13905.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13905</wfw:commentRss><description>&lt;p&gt;I was playing with the &lt;a href="http://www.atalasoft.com/cs/blogs/31appsin31days/archive/2008/05/03/product-box-generator.aspx"&gt;Product Box Generator&lt;/a&gt; and created the following bit of fun:&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;blockquote&gt;&lt;p&gt;&lt;img src="http://www.atalasoft.com/cs/photos/techtalkgallery/images/13904/original.aspx"&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;p&gt;I love software.&lt;/p&gt;&lt;p&gt;Thanks, Lou, for tolerating me.&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx&amp;amp;;subject=Lou+Francos" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx&amp;amp;;title=Lou+Francos" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx&amp;amp;title=Lou+Francos" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx&amp;amp;;title=Lou+Francos" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx&amp;amp;;title=Lou+Francos&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/06/lou-francos.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13905" width="1" height="1"&gt;</description><category domain="http://www.atalasoft.com/cs/blogs/stevehawley/archive/tags/silly+image/default.aspx">silly image</category></item><item><title>When &quot;new&quot; is Too Slow</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx</link><pubDate>Mon, 05 May 2008 13:46:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13887</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>2</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13887.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13887</wfw:commentRss><description>
&lt;p&gt;I was working on some prototype code that needed to be super fast.&amp;nbsp; After getting basic functionality up and running, I found that the biggest chunk of time was getting lost in operator new.&amp;nbsp; In this particular chunk of code, I had some simulated recursion that was making lots and lots of little objects that were being pushed and popped onto a stack.&amp;nbsp; The issue was that these objects are tiny and transient.&amp;nbsp; This means that all the overhead imposed by new and delete will get charged again and again and again.&lt;/p&gt;

&lt;p&gt;There are a number of choices available to you when you do this.&amp;nbsp; I'll pass on one that breaks a number of conventional OO design rules, specifically is-a/has-a.&amp;nbsp; In my case, I had some objects that have two purposes in life - to hold data and to live in a stack.&amp;nbsp; If you are a fan of STL, you will probably haul out stack&amp;lt;t&amp;gt; and call it good.&amp;nbsp; In my case, STL's performance was heinous, so I chose to smudge the is-a/has-a line and make my little object into a stack element rather than using a stack element to hold it:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;class StackPoint {&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StackPoint(unsigned int x, unsigned int y) : m_next(NULL)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_pt.x = x; m_pt.y = y;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StackPoint (POINT pt) : m_pt(pt), m_next(NULL) { }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual ~StackPoint () { }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int X() { return m_pt.x; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int Y() { return m_pt.y; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SetX(int x) { m_pt.x = x; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SetY(int y) { m_pt.y = y; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StackPoint *GetNext() { return m_next; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SetNext(StackPoint *next) { m_next = next; }&lt;br&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; POINT m_pt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StackPoint *m_next;&lt;br&gt;};&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;br&gt;
class MyStack {&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyStack() : m_stack(NULL) { }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual ~MyStack();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool IsEmpty() { return m_stack == NULL; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void Push(StackPoint *item) { item-&amp;gt;SetNext(m_stack); m_stack = item; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StackPoint *Pop();&lt;br&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StackPoint *m_stack;&lt;br&gt;}; &lt;br&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In these snippets, I'm leaving out some of the methods, but they're simple to write.&amp;nbsp; Pop() returns null if the stack is empty, or the top of the stack otherwise, resetting the stack pointer.&amp;nbsp; The destructor rips the entire stack, disposing each element in turn.&amp;nbsp; From these two classes, I can now create an allocator like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;class StackPointAllocator {&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StackPointAllocator() {&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual ~StackPointAllocator() { }&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; StackPoint *Alloc(int x, int y);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void Free(StackPoint *p);&lt;br&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyStack m_stack;&lt;br&gt;}; &lt;br&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;In this case, the StackPointAllocator has a method called Alloc which will do one of two things.&amp;nbsp; If m_stack.IsEmpty() is true, it will call operator new.&amp;nbsp; If m_stack.IsEmpty() is false, it will pop the top item off, set x and y and return it.&amp;nbsp; In the typical case, there is an item left on the stack and so "allocation" (really recycling), is only a few assignment statements.&amp;nbsp; Note that m_stack is a NOT a pointer, which means that its destructor will automatically get called when the allocator goes out of scope or is deleted.&lt;br&gt;&lt;/p&gt;&lt;p&gt;To give you a sense of the power of doing this, the original problem with allocation was costly because I was allocating tens of millions of these objects, each of which has a very short life span.Even though the individual cost was small, multiplying by 10M added up.&amp;nbsp; I'd rather do 40M assignments.&amp;nbsp; Once the code was refactored (easy), the time for allocation totally vanished from the performance profile.&lt;/p&gt;&lt;p&gt;Now, the real C++ programmer question is "Why didn't I override global operator new for StackPoint?" &lt;br&gt;&lt;/p&gt;&lt;p&gt;Overriding global operator new means that all code that allocates these objects will go through the global allocator - that's a bigger deal.&amp;nbsp; I use this code in other places that shouldn't use this allocator.&amp;nbsp; I end up making the allocators I use stack objects, which means that objects in the free list disappear when they go out of scope.&lt;/p&gt;&lt;p&gt;Classic engineering dilemma: which is more important? performance or OO design?&amp;nbsp; In this case, the API is NOT public, so the dirty little secret is hidden away, making this a perfectly acceptable choice.&amp;nbsp; Performance, FTW.&amp;nbsp; In addition, there were two other considerations - readability and expedience.&amp;nbsp; Readability was not lost at all, and since I could knock this out inside a half hour, I won on expedience too.&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx&amp;amp;;subject=When+%26quot%3bnew%26quot%3b+is+Too+Slow" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx&amp;amp;;title=When+%26quot%3bnew%26quot%3b+is+Too+Slow" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx&amp;amp;title=When+%26quot%3bnew%26quot%3b+is+Too+Slow" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx&amp;amp;;title=When+%26quot%3bnew%26quot%3b+is+Too+Slow" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx&amp;amp;;title=When+%26quot%3bnew%26quot%3b+is+Too+Slow&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/05/05/when-new-is-too-slow.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13887" width="1" height="1"&gt;</description><category domain="http://www.atalasoft.com/cs/blogs/stevehawley/archive/tags/code+C_2B002B00_+performance/default.aspx">code C++ performance</category></item><item><title>Out, Out, Damn Ref</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx</link><pubDate>Fri, 18 Apr 2008 19:44:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13715</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>2</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13715.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13715</wfw:commentRss><description>
&lt;p&gt;What is the difference between the out and ref keywords in C#?&amp;nbsp; Rick and I were discussing this earlier today and I decided that I wanted to find out for real.&amp;nbsp; Inherently, I know what the difference is: ref is passed by reference and out is pass by reference with the added requirement that the parameter must be assigned to.&lt;/p&gt;

&lt;p&gt;But this is a very minor semantic difference, so the real question is whether or not the difference is enforced by the language/compiler or by the CLR.&amp;nbsp; For this, we will determine the answer empirically with this chunk of code:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;private void SetMyFriend(out int x)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = 5;&lt;br&gt;}&lt;br&gt;&lt;br&gt;private void TouchMyFriend(ref int x)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = 3;&lt;br&gt;}&lt;br&gt;&lt;br&gt;private void MyFriend()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int x;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SetMyFriend(out x);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TouchMyFriend(ref x);&lt;br&gt;}&lt;br&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;Once this is written and compiled, we can pull it up with ildasm and have a look at what the compiler has done.&lt;/p&gt;

&lt;p&gt;Here is the IL for SetMyFriend()&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.method private hidebysig instance void&amp;nbsp; SetMyFriend([out] int32&amp;amp; x) cil managed&lt;br&gt;{&lt;br&gt;&amp;nbsp; // Code size&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5 (0x5)&lt;br&gt;&amp;nbsp; .maxstack&amp;nbsp; 8&lt;br&gt;&amp;nbsp; IL_0000:&amp;nbsp; nop&lt;br&gt;&amp;nbsp; IL_0001:&amp;nbsp; ldarg.1&amp;nbsp; // put address of x on the stack&lt;br&gt;&amp;nbsp; IL_0002:&amp;nbsp; ldc.i4.5 // put a 5 on the stack&lt;br&gt;&amp;nbsp; IL_0003:&amp;nbsp; stind.i4 // store the 5 into the address&lt;br&gt;&amp;nbsp; IL_0004:&amp;nbsp; ret&lt;br&gt;} // end of method BasicTesting::SetMyFriend&lt;/code&gt; &lt;br&gt;&lt;/p&gt;

&lt;p&gt;No surprises - x is passed in as an int32&amp;amp; or a reference to a four byte int - ah, but it has the magic [out] attribute on it as well.&lt;/p&gt;

&lt;p&gt;Here is TouchMyFriend():&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.method private hidebysig instance void&amp;nbsp; TouchMyFriend(int32&amp;amp; x) cil managed&lt;br&gt;{&lt;br&gt;&amp;nbsp; // Code size&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5 (0x5)&lt;br&gt;&amp;nbsp; .maxstack&amp;nbsp; 8&lt;br&gt;&amp;nbsp; IL_0000:&amp;nbsp; nop&lt;br&gt;&amp;nbsp; IL_0001:&amp;nbsp; ldarg.1&lt;br&gt;&amp;nbsp; IL_0002:&amp;nbsp; ldc.i4.3&lt;br&gt;&amp;nbsp; IL_0003:&amp;nbsp; stind.i4&lt;br&gt;&amp;nbsp; IL_0004:&amp;nbsp; ret&lt;br&gt;} // end of method BasicTesting::TouchMyFriend&lt;br&gt;&lt;br&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You'll notice that except for the [out] in the declaration, it is absolutely identical to SetMyFriend.&amp;nbsp; I won't insert the calling code, but it is precisely the same for both.&amp;nbsp; So the answer to the question is that the compiler enforces it to the degree that it will attempt to determine if the value has been assigned via static analysis.&amp;nbsp; Yet, is this 100% the case because the parameter is marked as [out].&amp;nbsp; Does the CLR do the verification?&amp;nbsp; The answer is no - if you write the following managed C++ method:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;static void DontTouchMe([System::Runtime::InteropServices::Out]int __gc &amp;amp;x)&lt;br&gt;{&lt;br&gt;}&lt;br&gt;&lt;/code&gt;&lt;br&gt;&lt;/p&gt;

the C++ compiler lets it go by and at runtime, the CLR lets it work too.&amp;nbsp; This is moderately distressing, but not surprising.&amp;nbsp; Lesson: out is only fully honored in C#.

&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx&amp;amp;;subject=Out%2c+Out%2c+Damn+Ref" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx&amp;amp;;title=Out%2c+Out%2c+Damn+Ref" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx&amp;amp;title=Out%2c+Out%2c+Damn+Ref" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx&amp;amp;;title=Out%2c+Out%2c+Damn+Ref" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx&amp;amp;;title=Out%2c+Out%2c+Damn+Ref&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/out-out-damn-ref.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13715" width="1" height="1"&gt;</description></item><item><title>Intraeducation</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx</link><pubDate>Fri, 18 Apr 2008 12:31:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13709</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>2</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13709.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13709</wfw:commentRss><description>&lt;p&gt;In a &lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/07/16/professional-development.aspx"&gt;previous blog entry&lt;/a&gt;, I wrote about the importance of professional development, especially from within.&amp;nbsp; I'd like to briefly underscore this with a double line written in a heavy magic marker.&lt;/p&gt;&lt;p&gt;One of the major goals of education at the high school level (at least it was when I was teaching) is to foster lifelong learning.&amp;nbsp; I am a strong proponent of this and try to live it as best as I can.&lt;/p&gt;&lt;p&gt;It is also important to recognize, as you get older and more experienced, your ability to take new things and put them into a bigger picture in terms of either abstraction or&amp;nbsp; concrete application.&amp;nbsp; Here's an ideal example, Rick has been writing a series about using &lt;a href="http://www.atalasoft.com/cs/blogs/rickm/archive/2008/04/15/improving-performance-through-stack-allocation-net-memory-management-part-2.aspx"&gt;stack allocation&lt;/a&gt; for performance tuning. I had written a &lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/archive/2006/10/26/11039.aspx"&gt;blog entry&lt;/a&gt; about this a couple years back which got some helpful comments.&lt;/p&gt;&lt;p&gt;Rick came in to ask me a few questions and in true Steve style, I sent him off with about a half dozen new questions that we raised together and a direction for finding the answers, and a spark.&lt;br&gt;&lt;/p&gt;&lt;p&gt;The point is that most of us know more than we give ourselves credit for.&amp;nbsp; If you choose to believe this then you can take advantage of it to help your colleagues learn.&amp;nbsp; I don't mean necessarily shoving knowledge down their throats (guilty!), but rather finding the opportune moment to add a piece to the puzzle to help sort things out or put in a bigger perspective.&lt;/p&gt;&lt;p&gt;Personal perspective adds a lot to the picture as well.&amp;nbsp; I came into the professional from an old school direction.&amp;nbsp; As an adolescent, I (re)invented a lot of the major elements of computer science and software engineering while coding in assembly language.&amp;nbsp; No, really.&amp;nbsp; I wrote code that was procedural before I had been exposed to procedural programming.&amp;nbsp; Later I wrote code that was object-oriented before I had seen C++ because it solved the problems I needed to solve in a terse, uniform, effective way.&amp;nbsp; As a result, when I look at languages like C# or C++, I often find myself thinking of them in terms of how I would write that code in plain C or in an assembly.&amp;nbsp; I do this because I naturally try to spot bottlenecks where code could be (a) made more flexible and (b) be make faster.&amp;nbsp; For example, I demonstrated this to Rick again by showing a traditional C++ code pattern and then showed how it could be implemented in C and with a tiny bit of refactoring would shave a half dozen instructions off an inner loop without losing any of the flexibility.&amp;nbsp; The point there is that I had a perspective that he didn't and by sharing it, I hope I just saved Rick years of work.&amp;nbsp; It took me years, after all, to learn it.&lt;br&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx&amp;amp;;subject=Intraeducation" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx&amp;amp;;title=Intraeducation" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx&amp;amp;title=Intraeducation" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx&amp;amp;;title=Intraeducation" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx&amp;amp;;title=Intraeducation&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/18/intraeducation.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13709" width="1" height="1"&gt;</description><category domain="http://www.atalasoft.com/cs/blogs/stevehawley/archive/tags/coding+learning/default.aspx">coding learning</category></item><item><title>Making Noise</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx</link><pubDate>Wed, 02 Apr 2008 16:27:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13590</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>1</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13590.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13590</wfw:commentRss><description>&lt;p&gt;I was reading a number of articles about using noise for image generation.&amp;nbsp; I came across &lt;a href="http://www.noisemachine.com/talk1/index.html"&gt;this set of web&lt;/a&gt; slides by Ken Perlin, who pretty much invented the use of noise for surface texturing and pattern deformation.&amp;nbsp; In addition to some delicious eye candy, it is one of the most succinct and understandable descriptions of the process of noise generation.&lt;/p&gt;&lt;p&gt;&lt;a href="http://mrl.nyu.edu/%7Eperlin/doc/oscar.html#noise"&gt;Here is&lt;/a&gt; Perlin's original source code for generating noise in C and &lt;a href="http://www.gamedev.net/reference/articles/article2085.asp"&gt;an application&lt;/a&gt; that uses his techniques to generate clouds.&lt;br&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx&amp;amp;;subject=Making+Noise" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx&amp;amp;;title=Making+Noise" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx&amp;amp;title=Making+Noise" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx&amp;amp;;title=Making+Noise" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx&amp;amp;;title=Making+Noise&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/04/02/making-noise.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13590" width="1" height="1"&gt;</description></item><item><title>More Unit Test Tricks</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx</link><pubDate>Mon, 24 Mar 2008 12:35:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13532</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13532.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13532</wfw:commentRss><description>&lt;p&gt;I've posted &lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/archive/2006/04/21/9957.aspx" target="_blank"&gt;before &lt;/a&gt;about some &lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/archive/2006/11/10/11088.aspx" target="_blank"&gt;tricks &lt;/a&gt;you can do to play with NUnit and get more out of your testing.&amp;nbsp; Today I'm going to pass in some more tricks I came up with recently to use reflection to verify correctness.&lt;/p&gt;&lt;p&gt;Recently, we had a defect that involved the properties of a Control object that were lacking the appropriate categories.&amp;nbsp; In the VS designer, they all showed up as "Misc".&amp;nbsp; This is not a big deal and is fairly easy to fix, but it is also fairly easy for recidivation on this bug as it is easy to add a new property and forget to add a category.&lt;/p&gt;&lt;p&gt;So let's formally define a property that appears in the UI designer.&amp;nbsp; A complete property in the UI designer is marked with a Browseable attribute and contains exactly one Category attribute.&lt;br&gt;&lt;/p&gt;&lt;p&gt;Given that, we can write predicates for the conditions upon which our definition hinges:&lt;br&gt;&lt;/p&gt;








&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; 
IsBrowsable(&lt;span style="color:blue;"&gt;object&lt;/span&gt;[] 
attrs)&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // returns true 
if the set of attributes on a Type indicate browsable&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color:blue;"&gt;object&lt;/span&gt; o 
&lt;span style="color:blue;"&gt;in&lt;/span&gt; attrs)&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (o &lt;span style="color:blue;"&gt;is&lt;/span&gt; &lt;span&gt;BrowsableAttribute&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
{&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;BrowsableAttribute&lt;/span&gt; br = (&lt;span&gt;BrowsableAttribute&lt;/span&gt;)o;&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; br.Browsable;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;


&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;In this case, we search the collection of attributes for a BrowseableAttribute.&amp;nbsp; If we find one, we return its setting.&amp;nbsp; Otherwise, without the attribute the property must be browseable so we return true by default.&lt;/p&gt;











&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; 
IsCategorized(&lt;span style="color:blue;"&gt;object&lt;/span&gt;[] 
attrs)&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // returns true 
if a property has a category&lt;o:p&gt;&lt;/o:p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach&lt;/span&gt; (&lt;span style="color:blue;"&gt;object&lt;/span&gt; o 
&lt;span style="color:blue;"&gt;in&lt;/span&gt; attrs)&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt; (o &lt;span style="color:blue;"&gt;is&lt;/span&gt; &lt;span&gt;CategoryAttribute&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CategoryAttribute&lt;/span&gt; ca = (&lt;span&gt;CategoryAttribute&lt;/span&gt;)o;&lt;o:p&gt;&lt;/o:p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/span&gt; ca.Category != &lt;span style="color:blue;"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ca.Category.Length &amp;gt; 
0;&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/span&gt; &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;In this predicate, a property is considered categorized if it has a CategoryAttribute, the attribute's Category property is non-null and it's length is greater than zero.&lt;/p&gt;&lt;p class="MsoNormal"&gt;Given that, we can use the following stub to test a UI object:&lt;/p&gt;&lt;p class="MsoNormal"&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;// get only the props declared by the final object (not base classes) that are 
public&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;PropertyInfo&lt;/span&gt;[] props =&lt;br&gt;objectUnderScrutiny.GetType().GetProperties(&lt;span&gt;BindingFlags&lt;/span&gt;.DeclaredOnly |&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;BindingFlags&lt;/span&gt;.Public | &lt;span&gt;BindingFlags&lt;/span&gt;.Instance);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;







&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (&lt;span&gt;PropertyInfo&lt;/span&gt; prop &lt;span style="color:blue;"&gt;in&lt;/span&gt; props)&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; object&lt;/span&gt;[] attrs = prop.GetCustomAttributes(&lt;span style="color:blue;"&gt;false&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/span&gt; (!IsBrowsable(attrs))&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // 
skip if not browseable&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;continue&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;




&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (!IsCategorized(attrs))&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;Assert&lt;/span&gt;.Fail(&lt;span&gt;"property 
"&lt;/span&gt; + prop.Name +&lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; " is missing 
category."&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;br&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Lest I forget - there's a solid why this category of test is useful - with dispassionate calm, it will flag very human, future errors that are easy to make.&amp;nbsp; When you implement a process, write code, etc. Be on the lookout "mandatory" steps that do not cause compile errors.&amp;nbsp; Applying Category attributes is exactly such a step - without it, a control object would not be professional quality, but applying attributes is purely optional.&amp;nbsp; It would be nice if you could flag in a base class rules for the existence of certain attributes in subclasses as well as to mark the error as fatal or non-fatal.&amp;nbsp; This way an abstract class could not only dictate interface, but semantics as well.&lt;/p&gt;&lt;p class="MsoNormal"&gt;In the meantime, unit tests will have to serve.&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx&amp;amp;;subject=More+Unit+Test+Tricks" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx&amp;amp;;title=More+Unit+Test+Tricks" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx&amp;amp;title=More+Unit+Test+Tricks" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx&amp;amp;;title=More+Unit+Test+Tricks" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx&amp;amp;;title=More+Unit+Test+Tricks&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/24/more-unit-test-tricks.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13532" width="1" height="1"&gt;</description><category domain="http://www.atalasoft.com/cs/blogs/stevehawley/archive/tags/code+nunit+gui+testing/default.aspx">code nunit gui testing</category></item><item><title>Parallelism</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx</link><pubDate>Tue, 18 Mar 2008 12:20:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13501</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13501.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13501</wfw:commentRss><description>&lt;p&gt;Threading in current programming models is one of the hardest things to get right.&amp;nbsp; It appears to be a fabulous tool waiting to be exploited, but it is instead one of the hardest things to get right.&amp;nbsp; Mike Stall has &lt;a href="http://blogs.msdn.com/jmstall/archive/2008/01/30/why-threading-is-hard.aspx"&gt;an interesting take&lt;/a&gt; on the combinatorial nature of multithreading and how the possible areas for bugs balloon as the number of threads increase.&amp;nbsp; Similarly Jeff Atwood &lt;a href="http://www.codinghorror.com/blog/archives/000169.html"&gt;goes into details&lt;/a&gt; about it as well.&lt;/p&gt;&lt;p&gt;Some people say that the solution is in the languages.&amp;nbsp; Fix the languages and then you've fixed the threading problem.&amp;nbsp; I don't know if I believe in that silver bullet.&amp;nbsp; You get some benefit in purely functional languages.&amp;nbsp; When I was in college nearly 20 years ago (eep!), I took a seminar course about functional programming.&amp;nbsp; In the class, we were presented with the graph reduction approach to program evaluation.&amp;nbsp; Essentially, the approach is to represent the code as a graph which can be reduced to a single node.&amp;nbsp; Part of the approach is one that allows for multiple processors/threads to work on the same graph at the same time with a minimum of critical sections.&amp;nbsp; &lt;a href="http://research.microsoft.com/%7Esimonpj/"&gt;Simon Peyton Jones&lt;/a&gt; visited campus as a guest lecturer and honors examiner and talked about this as well.&amp;nbsp; Jones has his hands in a number of interesting technologies, including Haskell.&lt;br&gt;&lt;/p&gt;&lt;p&gt;In DotImage, we added threading into our image processing.&amp;nbsp; To do this, I created a meta-command called ThreadedCommand.&amp;nbsp; This command acts like an ImageCommand but does no image processing.&amp;nbsp; Instead it breaks an image into bands, and throws worker threads at the bands.&lt;/p&gt;&lt;p&gt;Rather than deal with full concurrency, we limited the domain of the problem instead.&amp;nbsp; Not every ImageCommand can be effectively threaded.&amp;nbsp; Instead, we use the following rules.&amp;nbsp; An ImageCommand can be threaded if:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;It implements IConeable.&amp;nbsp; We do not use the same command on every thread.&amp;nbsp; Instead, we use clones so as to avoid internal state issues within the command.&lt;/li&gt;&lt;li&gt;It does not modify the source image outside a given scanline and if it does modify within a given scanline, it requires no state outside of a given scanline.&lt;/li&gt;&lt;li&gt;It requires no state calculated from one band for use in another&lt;/li&gt;&lt;li&gt;It implements IThreadableCommand (our interface)&lt;/li&gt;&lt;/ol&gt;By abiding by these rules, it is possible to thread many ImageCommands without a deep knowledge of threading, which is the way I think it should be.&lt;br&gt;&lt;br&gt;Now, in implementing this we built a worker thread library and it was far more painful than it should've been.&amp;nbsp; We looked for support code that we could use in our environment (we had to support .NET 1.1 and above) and found nothing usable, which is a crime because our needs are simple: this code needs a set of workers, a queue of jobs, a way to start workers running, a way for them to report completion, and a way to kill them instantly.&amp;nbsp; Every single one of these things was hard to do right, even when we stacked the deck in our favor.&amp;nbsp; That tells me that the underlying threading tools need other support classes on top of them - badly.&lt;br&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx&amp;amp;;subject=Parallelism" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx&amp;amp;;title=Parallelism" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx&amp;amp;title=Parallelism" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx&amp;amp;;title=Parallelism" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx&amp;amp;;title=Parallelism&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/18/parallelism.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13501" width="1" height="1"&gt;</description><category domain="http://www.atalasoft.com/cs/blogs/stevehawley/archive/tags/functionalprogramming+threading+imageprocessing+multithreaded/default.aspx">functionalprogramming threading imageprocessing multithreaded</category></item><item><title>Immutability</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx</link><pubDate>Mon, 17 Mar 2008 15:00:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13496</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13496.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13496</wfw:commentRss><description>
&lt;p&gt;Functional programming is in.&amp;nbsp; There is a lot of buzz around the future of functional programming as applications look to leveraging multiple processors and multiple cores for their tasks.&amp;nbsp; One of the things that makes this easier is to work with immutable data structures.&amp;nbsp; &lt;a href="http://blogs.msdn.com/ericlippert/default.aspx"&gt;Eric Lippert&lt;/a&gt; has written a number of thoughtful blog entries on immutability, in particular this entry on an &lt;a href="http://blogs.msdn.com/ericlippert/archive/2007/12/04/immutability-in-c-part-two-a-simple-immutable-stack.aspx"&gt;immutable stack&lt;/a&gt; caught my eye.&lt;/p&gt;

&lt;p&gt;In essence, if Eric had written this in Scheme (and my scheme is rusty, so bear with me), it would've been something like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(define empty-stack '())&lt;br&gt;(define stack empty-stack)&lt;br&gt;(define stack-push (lambda (a stack) (cons a stack)))&lt;br&gt;(define stack-pop (lambda (stack)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (if (eq? stack empty-stack)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (empty-stack)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (cdr stack))))&lt;br&gt;&lt;br&gt;(define stack-peek (lambda (stack)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (if (eq? stack empty-stack)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; '()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (car stack))))&lt;br&gt;&lt;br&gt;(define x stack)&lt;br&gt;(define x (stack-push 'a x))&lt;br&gt;(define x (stack-push 'b x))&lt;br&gt;(stack-peek x)&lt;br&gt;(define x (stack-pop x))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;So why am I bringing up Scheme?&amp;nbsp; Because Eric's code is starting to look hauntingly like Scheme and not like C#.&amp;nbsp; This is not necessarily a bad thing - there are a lot of great things to learn from Scheme.&amp;nbsp; By the way, &lt;a href="http://jscheme.sourceforge.net/jscheme/contrib/jswebapp/jscheme/demo/JSchemeEvaluator.html"&gt;here is a Java implementation of Scheme&lt;/a&gt; where you can try out that code.&lt;br&gt;&lt;/p&gt;
&lt;p&gt;I have an important semantic quibble, though.&amp;nbsp; Eric's Pop is not Pop.&amp;nbsp; Since it violates the Principle of Least Astonishment, it should have a different name.&amp;nbsp; The history of Pop indicates that two things happen - an object gets removed (and I get it) and the stack gets changed (and I get that too).&amp;nbsp; I would suggest Drop instead.&amp;nbsp; I do question the usefulness of this definition, though.&amp;nbsp; Here is some code that I have in production that is run on a stack machine:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; private void SetColorRGB()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; double c3 = ((Number)stack.Pop()).Value;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; double c2 = ((Number)&lt;/code&gt;&lt;code&gt;stack.&lt;/code&gt;&lt;code&gt;Pop()).Value;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; double c1 = ((Number)&lt;/code&gt;&lt;code&gt;stack.&lt;/code&gt;&lt;code&gt;Pop()).Value;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _g.SetColor(c1, c2, c3);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&lt;/code&gt;So this code reads three numbers of the stack and calls a library routine to set the color.&amp;nbsp; My changed code would have to look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; private void SetColorRGB()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; double c3 = ((Number)&lt;/code&gt;&lt;code&gt;stack.P&lt;/code&gt;&lt;code&gt;eek()).Value;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;  &amp;nbsp; stack = stack.Drop();&lt;br&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; double c2 = ((Number)&lt;/code&gt;&lt;code&gt;stack.P&lt;/code&gt;&lt;code&gt;eek()).Value;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;  &amp;nbsp; stack = stack.&lt;/code&gt;&lt;code&gt;Drop&lt;/code&gt;&lt;code&gt;();&lt;br&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; double c1 = ((Number)&lt;/code&gt;&lt;code&gt;stack.P&lt;/code&gt;&lt;code&gt;eek()).Value;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;  &amp;nbsp; stack = stack.&lt;/code&gt;&lt;code&gt;Drop&lt;/code&gt;&lt;code&gt;();&lt;/code&gt;&lt;code&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _g.SetColor(c1, c2, c3);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&lt;/code&gt;&amp;nbsp;which is starting to get a little ugly.&amp;nbsp; In reality, it doesn't have to be so bad.&amp;nbsp; In my own case, I don't actually have an unprotected call to Pop in my code.&amp;nbsp; Since this is part of a stack machine, it has protective wrapping to make sure unexpected things happen and handles them with aplomb.&amp;nbsp; Therefore I could hide the lower-level implementation of IStack from the world and use wrapper methods.&lt;/p&gt;&lt;p&gt;Things that need to be in the definition of stack, however, include some more real-world usage methods:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;dup (duplicate the top most entry) - in Eric's definition, this will be return Push(Peek());&lt;/li&gt;&lt;li&gt;Swap (swap the top two items) - in Eric's definition, this is more difficult - you'd need a peek, a pop, a peek, a pop and two pushes.&lt;/li&gt;&lt;li&gt;Depth (returns the total number of items) - this is easy you would have an immutable int which is incremented on push&lt;/li&gt;&lt;li&gt;Index (get the nth item) - you have rip n Pops then a peek&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;There are some more esoteric ones like Roll, Over and so on.&amp;nbsp; The problem I see is that anything that is beyond the simplest definitions starts to get disproportionately complicated.&lt;/p&gt;&lt;p&gt;Yes, there are clear benefits to the immutability, but we start to get further and further from the world where push and pop were a single instruction and that bothers me. It's also the reason why languages like Scheme even have back doors to allow coders to violate immutability via set!, set-car! and set-cdr!&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx&amp;amp;;subject=Immutability" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx&amp;amp;;title=Immutability" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx&amp;amp;title=Immutability" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx&amp;amp;;title=Immutability" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx&amp;amp;;title=Immutability&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/17/immutability.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13496" width="1" height="1"&gt;</description><category domain="http://www.atalasoft.com/cs/blogs/stevehawley/archive/tags/functionalprogramming+immutable+C_2300_/default.aspx">functionalprogramming immutable C#</category></item><item><title>6.0 Features - Tiff Gets Ready for ECMi</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx</link><pubDate>Wed, 05 Mar 2008 21:28:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13418</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13418.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13418</wfw:commentRss><description>&lt;p&gt;DotImage supports TIFF images in a number of different ways.&amp;nbsp; In prior releases we've provided feature-rich tools that allow our users to get at all the nitty gritty details of TIFF images and TIFF files.&amp;nbsp; With those tools you can do just about anything you want to a TIFF, provided that you fully understand the TIFF specification.&lt;/p&gt;&lt;p&gt;For this release, we decided to think about TIFFs at a much higher level.&amp;nbsp; We looked at customer requests, knowledge base articles and sample code and decided that we could solve many customer problems with classes that hide as much of the complexity of TIFFs as possible.&lt;/p&gt;&lt;p&gt;In 6.0, we've added two classes, TiffDocument and TiffPage, that allow easy, efficient manipulation of TIFFs.&amp;nbsp; The things that've gotten better:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Finding information about each page.&amp;nbsp; When you construct a TiffDocument, all the page information is retrieved in one shot, and it's &lt;i&gt;very&lt;/i&gt; efficient.&lt;/li&gt;&lt;li&gt;Combining multiple TIFFs into one. This is a one liner now - it's easy to do.&lt;/li&gt;&lt;li&gt;Rearranging the pages in an existing TIFF is now done through the manipulation of a collection&lt;/li&gt;&lt;li&gt;Mixing and matching pages from multiple sources or inserting a page from a new image is, again, just manipulating a collection.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This type of object design is vital for ECMi.&amp;nbsp; If you want to deliver customized documents to your clients on the fly, there is no better way to do it than this.&lt;/p&gt;&lt;p&gt;Imagine an insurance agent who wants to assemble a policy for a customer on the fly - what better way to implement this than to be able to grab stock document pieces, assemble them and then deliver to a web browser with the &lt;a href="http://www.atalasoft.com/ajaxannotations/" target="_blank"&gt;Atalasoft AJAX Document Viewer&lt;/a&gt;?&lt;/p&gt;&lt;p&gt;Check it out in the &lt;a href="http://www.atalasoft.com/Products/DotImage/Default.aspx"&gt;DotImage 6.0&lt;/a&gt; release.&amp;nbsp; There is also a free Windows App that lets you combine multiple TIFFs and reorder the pages by dragging and dropping thumbnail images.&amp;nbsp; We give you the source, too.&lt;br&gt;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx&amp;amp;;subject=6.0+Features+-+Tiff+Gets+Ready+for+ECMi" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx&amp;amp;;title=6.0+Features+-+Tiff+Gets+Ready+for+ECMi" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx&amp;amp;title=6.0+Features+-+Tiff+Gets+Ready+for+ECMi" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx&amp;amp;;title=6.0+Features+-+Tiff+Gets+Ready+for+ECMi" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx&amp;amp;;title=6.0+Features+-+Tiff+Gets+Ready+for+ECMi&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/05/6-0-features-tiff-gets-ready-for-ecmi.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13418" width="1" height="1"&gt;</description></item><item><title>Learn from the Past</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx</link><pubDate>Tue, 04 Mar 2008 15:26:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13397</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13397.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13397</wfw:commentRss><description>&lt;p&gt;I was on a Google hunt for a &lt;a href="http://spinroot.com/pico/pjw.html"&gt;picture of Peter Weinberger&lt;/a&gt; (the 'W' in &lt;a href="http://cm.bell-labs.com/cm/cs/awkbook/"&gt;awk&lt;/a&gt;) on a water tower and I ran across a book I had seen once many years earlier called "Beyond Photography - The Digital Darkroom".&amp;nbsp; &lt;a href="http://www.spinroot.com/pico/"&gt;This book is available online&lt;/a&gt; in a series of PDF files.&amp;nbsp; In the book it describes the image processing and a little language that can be used for image processing.&lt;/p&gt;&lt;p&gt;There are a number of elements that are built into the language that are fantastic.&amp;nbsp; It has the ability to describe a set of transformations that map pixel values from one or more source images to a destination image as well as to manipulate the image data on the way through.&lt;/p&gt;&lt;p&gt;Transformations can be done in Cartesian or polar coordinates or both.&lt;/p&gt;&lt;p&gt;The language itself has implicit looping, so you never need to worry about that.&lt;/p&gt;&lt;p&gt;In essence, your job is to use the language to write an expression that will be evaluated for each pixel in the image and it does the rest.&lt;/p&gt;&lt;p&gt;There are a number of things in the base implementation that are, well, quaint by today's standards.&amp;nbsp; For example, the image dimensions are compiled into the application and default to 248x248, which is tiny.&amp;nbsp; The language has a hard-coded recursive-descent parser, which is based on a spelled-out grammar.&amp;nbsp; In fact, the chapter which describes the language is an excellent tutorial on how to write a parser.&lt;/p&gt;&lt;p&gt;The program has the facility for JIT compilation to boost performance, and is extensible to include display support.&lt;/p&gt;&lt;p&gt;There are a lot of nice goodies in there including recipes for image processing.&lt;/p&gt;&lt;p&gt;Translating this to .NET wouldn't be too hard - even easier if you used dotImage to do the image reading and writing.&amp;nbsp; I would make an abstract descendant of ImageCommand that includes a method for performing the image processing.&amp;nbsp; The use the expression parser to JIT compile it to CLI and instantiate a new command.&amp;nbsp; This is not trivial work, but it is straightforward.&amp;nbsp; It's actually not that different from the DotImage UserTransform command that lets you do any coordinate transform from one space to another, using a delegate.&lt;br&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx&amp;amp;;subject=Learn+from+the+Past" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx&amp;amp;;title=Learn+from+the+Past" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx&amp;amp;title=Learn+from+the+Past" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx&amp;amp;;title=Learn+from+the+Past" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx&amp;amp;;title=Learn+from+the+Past&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/03/04/learn-from-the-past.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13397" width="1" height="1"&gt;</description></item><item><title>Learning to Program</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx</link><pubDate>Wed, 13 Feb 2008 21:13:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13212</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13212.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13212</wfw:commentRss><description>&lt;p&gt;Short entry - &lt;a href="http://norvig.com/21-days.html"&gt;this blog post&lt;/a&gt; is an interesting take on what you should consider doing to become an effective programmer.&amp;nbsp; I agree for the most part.&amp;nbsp; I would add a couple things, though.&lt;/p&gt;&lt;p&gt;Historically, I've discovered that I can learn the syntax/grammar of a typical programming language by reading a book in a weekend. I did it with Java, PostScript, and C#.&amp;nbsp; However, in each case, I had a previous language under my belt that was close enough that I could abstract that capabilities of one language to another.&lt;/p&gt;&lt;p&gt;While I was, in each case, up and writing code after the weekend with the book by my side, the code did not demonstrate fluency.&amp;nbsp; That came by writing code and lots of it.&lt;/p&gt;&lt;p&gt;I remember a guy who had been to a comic book convention and was waiting in an autograph line to meet some prominent artist. He overheard a fanboy ask him the question, "how do you become a comic book artist."&amp;nbsp; The answer was, "get a really big stack of paper and a lot of pencils and start drawing."&amp;nbsp; The same is true for coding or for just about anything else you want to become proficient in.&lt;/p&gt;&lt;p&gt;I would add a couple things to his list of things to do to become a proficient programmer:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Learn a non-trivial file specification.&amp;nbsp; Learn it to the point where you can parse the files by looking at them.&amp;nbsp; You will almost assuredly have to have that depth of knowledge of some spec at some point in your career.&amp;nbsp; Being able to interpret a specification and, better yet, learning how to right one is valuable.&lt;/li&gt;&lt;li&gt;Write an interpreter or a compiler for a little language, or better yet, a complete language.&amp;nbsp; Having an intrinsic understanding of how a language is implemented will improve how you write code.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx&amp;amp;;subject=Learning+to+Program" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx&amp;amp;;title=Learning+to+Program" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx&amp;amp;title=Learning+to+Program" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx&amp;amp;;title=Learning+to+Program" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx&amp;amp;;title=Learning+to+Program&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/02/13/learning-to-program.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13212" width="1" height="1"&gt;</description></item><item><title>Never Forget - Floating Point Sucks</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx</link><pubDate>Fri, 25 Jan 2008 15:28:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13035</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13035.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13035</wfw:commentRss><description>
&lt;p&gt;There are a number things in software engineering that look like great ideas and look like the obvious and perfect solution to a particular problem.&amp;nbsp; Ultimately, they fail in practice.&lt;/p&gt;

&lt;p&gt;Floating point numbers are just such an example.&amp;nbsp; It looks like they are a great way to represent elements of the set of Real numbers, so much so that diligent engineers have built silicon devices to perform operations on them in ways that are efficient.&lt;/p&gt;

&lt;p&gt;There is a problem, though.&amp;nbsp; Floating point numbers have holes in them.&amp;nbsp; Even though I can write out a constant in C or Java or C# as 1.371, there is no guarantee that the actual number represented in the final executable is actual 1.371.&amp;nbsp; I might get 1.37099999997 or 1.37100000000001 or something else that is very close to 1.371, but really isn't.&lt;/p&gt;

&lt;p&gt;So let's say that you're weighting a vector like this:&lt;/p&gt;

&lt;code&gt;double final = cx * x + cy * y + cz * z;&lt;/code&gt;

&lt;p&gt;let's also say that x, y, and z have a known upper limit k, such that x + y + z &amp;lt;= 3x and each of the three coefficients is greater than or equal to 0 and less than or equal to 1 and that cx + cy + cz = 1&lt;/p&gt;

&lt;p&gt;Under these conditions you should be able to say that final &amp;lt;= k&lt;br&gt;&lt;br&gt;Great.&amp;nbsp; Now lets consider one of the standard formulae for calculating perceptual gray:&lt;/p&gt;

&lt;p&gt;gray = 0.299 * r + 0.587 * g + 0.114 * b&lt;/p&gt;

&lt;p&gt;the coefficients add up nicely to 1, so this looks like it is a good formula to put into code:&lt;/p&gt;

&lt;code&gt;static int Luminance(BYTE r, BYTE g, BYTE b)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (int)(0.299 * r + 0.587 * g + 0.114 * b); &lt;br&gt;}&lt;br&gt;&lt;/code&gt;

&lt;p&gt;This works great - we're assuming 8 bits per component in the colors and Luminance gives me 0 for black and 255 for white.&amp;nbsp; The problem happens when you bump up to 16 bit per component color:&lt;/p&gt;

&lt;code&gt;static int Luminance(UNS16 r, UNS16 g, UNS16 b)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (int)(0.299 * r + 0.587 * g + 0.114 * b); &lt;br&gt;
}&lt;/code&gt;

&lt;p&gt;When you apply this to white, you get 65534 not 65535.&amp;nbsp; The problem is that the intermediate result is 65534.999999997 (or something like that).&amp;nbsp; The rules in C for casting to int call for truncation, so that fractional part goes away and you have the wrong answer.&amp;nbsp; So you say, "ah-ha! clearly you should be rounding!".&amp;nbsp; I say this is the wrong solution, primarily for performance reasons, but also because you only really want to round if you need to, but the issue is hardware/type related, so since this is a platform issue, the code should be set up to be conditionally compiled for the platform.&lt;/p&gt;

&lt;p&gt;Fixed point, which offers the hope of greater performance, fails.&amp;nbsp; 16 bits of fractional part, the maximum you can use for 16 bit per component color, isn't nearly enough, again due to holes.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;I've found that by treating this like a first semester calculus problem, I can get to an more appropriate solution.&amp;nbsp; So I defined an epsilon that when put into the calculation creates a delta that will give us the effect that we want:&lt;/p&gt;

&lt;p&gt;Not only that, I can use the compiler to tell me if I even need it:&lt;/p&gt;

&lt;code&gt;#define needRgbEpsilon&amp;nbsp; ((int)(rCoef * 65535 + gCoef * 65535 + bCoef * 65535) &amp;lt; 65535)&lt;br&gt;&lt;/code&gt;

&lt;p&gt;Then I change my luminance code to:&lt;/p&gt;

&lt;code&gt;return (int)(rCoef * r + gCoef * g + bCoef *b + (needRgbEpsilon ? rgbEpsilon : 0));&lt;/code&gt;

&lt;p&gt;and I get the expected results.&amp;nbsp; Now, how about performance?&amp;nbsp; Well - that needRgbEpsilon #define is constant at compile time, therefore that conditional in the return folds to a constant 0 or rgbEpsilon.&amp;nbsp; If it's not needed, the addition doesn't happen.&amp;nbsp; If it is needed, I get the addition and pay the penalty of one additional floating point add - no more.&amp;nbsp; That will be far less expensive than calling round or ceil or your other favorite library routine.&lt;/p&gt;

&lt;p&gt;What is my rgbEpsilon?&amp;nbsp; That would be telling.&lt;br&gt;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx&amp;amp;;subject=Never+Forget+-+Floating+Point+Sucks" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx&amp;amp;;title=Never+Forget+-+Floating+Point+Sucks" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx&amp;amp;title=Never+Forget+-+Floating+Point+Sucks" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx&amp;amp;;title=Never+Forget+-+Floating+Point+Sucks" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx&amp;amp;;title=Never+Forget+-+Floating+Point+Sucks&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/25/never-forget-floating-point-sucks.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13035" width="1" height="1"&gt;</description></item><item><title>Hypogastric Joggle</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx</link><pubDate>Tue, 22 Jan 2008 18:18:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:13012</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/13012.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=13012</wfw:commentRss><description>&lt;p&gt;I've been very busy tracking down and fixing bugs, but I thought I'd pass this on from the instructions to a radio controlled helicopter:&lt;/p&gt;&lt;p&gt;&lt;img src="http://www.atalasoft.com/cs/photos/techtalkgallery/images/13011/original.aspx" height="191" width="591"&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx&amp;amp;;subject=Hypogastric+Joggle" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx&amp;amp;;title=Hypogastric+Joggle" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx&amp;amp;title=Hypogastric+Joggle" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx&amp;amp;;title=Hypogastric+Joggle" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx&amp;amp;;title=Hypogastric+Joggle&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2008/01/22/hypogastric-joggle.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=13012" width="1" height="1"&gt;</description></item><item><title>I'm Special!</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx</link><pubDate>Fri, 07 Dec 2007 14:24:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:12849</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/12849.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=12849</wfw:commentRss><description>&lt;p&gt;&lt;img src="http://www.atalasoft.com/cs/photos/techtalkgallery/images/12848/original.aspx" height="91" width="466"&gt;&lt;/p&gt;&lt;p&gt;It was very thoughtful of this company to send me this e-mail, but they spelled my name wrong.&amp;nbsp; Really, if you're going to get null data, handle it gracefully.&amp;nbsp; "To whom it may concern," or "Dear customer," are much better alternatives.&lt;/p&gt;&lt;p&gt;I already know that to the company I'm just an entry in a database.&amp;nbsp; There's no need to rub it in my face.&lt;br&gt;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx&amp;amp;;subject=I%27m+Special!" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx&amp;amp;;title=I%27m+Special!" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx&amp;amp;title=I%27m+Special!" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx&amp;amp;;title=I%27m+Special!" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx&amp;amp;;title=I%27m+Special!&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/12/07/i-m-special.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=12849" width="1" height="1"&gt;</description></item><item><title>Disgusting C-ism</title><link>http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx</link><pubDate>Mon, 29 Oct 2007 20:27:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:12718</guid><dc:creator>Steve Hawley</dc:creator><slash:comments>0</slash:comments><comments>http://www.atalasoft.com/cs/blogs/stevehawley/comments/12718.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/stevehawley/commentrss.aspx?PostID=12718</wfw:commentRss><description>&lt;p&gt;I wrote some code that makes some assumptions about the length of int when converted to a string.&amp;nbsp; This is in code that is strictly internal and is only ever called by internal code in very controlled circumstances.&amp;nbsp; Still, when I wrote that assumption, it made me a little bit itchy.&amp;nbsp; I asked myself a question I frequently ask, "what can I do to make sure that the compiler will catch an error for me?"&lt;/p&gt;&lt;p&gt;Essentially, what I wanted was to see if sizeof(int) == 4 like this:&lt;/p&gt;&lt;p&gt;#if sizeof(int) == 4&lt;br&gt;#error Call Steve - his assumption on sizeof(int) was wrong and this code will fail&lt;br&gt;#endif&lt;/p&gt;&lt;p&gt;Actually - it's better than that - the code has enough information to make it clear how to fix the code, should this arise.&lt;/p&gt;&lt;p&gt;I could do a runtime check wherein I count the number of bits/bytes in an int and use that, but I'd rather make this a compiler check.&lt;/p&gt;&lt;p&gt;I could also use:&lt;/p&gt;&lt;p&gt;#if MAXINT &amp;gt; MY_ASSUMED_MAXINT&lt;br&gt;#error Call Steve...&lt;br&gt;#endif&lt;/p&gt;&lt;p&gt;but I found this little gem:&lt;/p&gt;&lt;p&gt;#define CCASSERT(predicate) _x_CCASSERT_LINE(predicate, __LINE__)&lt;br&gt;#define _x_CCASSERT_LINE(predicate, line) \&lt;br&gt;typedef char constraint_violated_on_line_##line[2*((predicate)!=0)-1];&lt;br&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;This defines a new type which is an array of a length that depends on the value of a predicate and will generate an illegal type on a false predicate.&amp;nbsp; Nice.&lt;/p&gt;&lt;p&gt;the usage in my case is:&lt;/p&gt;&lt;p&gt;CCASSERT(sizeof(int) == 4)&lt;/p&gt;&lt;p&gt;which stops the compiler cold.&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx&amp;amp;;subject=Disgusting+C-ism" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx&amp;amp;;title=Disgusting+C-ism" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx&amp;amp;title=Disgusting+C-ism" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx&amp;amp;;title=Disgusting+C-ism" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx&amp;amp;;title=Disgusting+C-ism&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/stevehawley/archive/2007/10/29/disgusting-c-ism.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=12718" width="1" height="1"&gt;</description></item></channel></rss>