<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Numerical .NET</title><link>http://blogs.extremeoptimization.com/jeffrey/</link><description>Experiences with technical computing on the Microsoft .NET platform.</description><managingEditor>Jeffrey Sax</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Jeffrey Sax</dc:creator><title>My .NET Framework Wish List</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2007/05/07/42374.aspx</link><pubDate>Mon, 07 May 2007 13:03:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2007/05/07/42374.aspx</guid><description>&lt;P&gt;This is now the fifth year I've been writing numerical software for the .NET platform. Over these years, I've discovered quite a few, let's call them 'unfortunate', design decisions that make writing solid and fast numerical code on .NET more difficult than it needs to be.&lt;/P&gt;
&lt;P&gt;What I'd like to do in the coming weeks is list some of the improvements that would make life easier for people in our specialized field of technical computing. The items mentioned in this post aren't new: I've written about them before. But it's nice to have them all collected in one spot.&lt;/P&gt;
&lt;P&gt;&lt;FONT size=4&gt;&lt;STRONG&gt;Fix the &amp;#8220;Inlining Oroblem&amp;#8220;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;First on the list: the &amp;#8220;inlining&amp;#8220; problem. Method calls with parameters that are value types do not get inlined by the JIT. This is very unfortunate, as it eliminates most of the benefit of defining specialized value types. For example: it's easy enough to define a complex number structure with overloaded operators and enough bells and whistles to make you deaf. Unfortunately, none of those operator calls are inlined. You end up with code that is an order of magnitude slower than it needs to be.&lt;/P&gt;
&lt;P&gt;Even though it has been the top performance issue for several years, there is no indication yet that it will be fixed any time soon. You can &lt;A href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=93858"&gt;add your vote&lt;/A&gt; to the already sizeable number on Microsoft's product feedback site.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size=4&gt;Support the IEEE-754 Standard&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Over 20 years ago, the IEEE published a &lt;A href="http://grouper.ieee.org/groups/754/"&gt;standard for floating-point arithmetic&lt;/A&gt; that has since been adopted by all major manufacturers of CPU's. So, platform independence can't be an issue. Why then is it that the .NET Framework has only the most minimal support for the standard? Surely the fact that people took the time to come up with a solid standard, and the fact that it has enjoyed such wide support from hardware vendors should be an indication that this is something useful and would greatly benefit an important segment of the developer community.&lt;/P&gt;
&lt;P&gt;I've written about the&amp;nbsp;benefits of &lt;A href="http://blogs.extremeoptimization.com/jeffrey/archive/2006/01/30/6736.aspx"&gt;floating-point exceptions&lt;/A&gt; before, and I've discussed my proposal for a &lt;A href="http://blogs.extremeoptimization.com/jeffrey/archive/2006/02/08/7074.aspx"&gt;FloatingPointContext class&lt;/A&gt;. I've added a suggestion to this effect in LadyBug. Please go over there and&amp;nbsp;&lt;A href="https://connect.microsoft.com/VisualStudio/feedback/Vote.aspx?FeedbackID=276107"&gt;vote&lt;/A&gt; for this proposal.&lt;/P&gt;
&lt;P&gt;&lt;FONT size=4&gt;&lt;STRONG&gt;Allow Overloading of Compound Assignment Operators&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This is another topic I've written about &lt;A href="http://blogs.extremeoptimization.com/jeffrey/archive/2005/02/19/153.aspx"&gt;before&lt;/A&gt;. In a nutshell: C# and VB.NET don't support custom overloaded assignment operators at all. C++/CLI supports them, and purposely violates the CLI spec in the process - which is a good thing! One point I would like to add: performance isn't the only reason. Sometimes there is a semantic difference. Take a look at this code:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;RowVector pivotRow = matrix.GetRow(pivot)&lt;BR&gt;&lt;FONT color=#0000ff&gt;for&lt;/FONT&gt;(row = pivot+1; row &amp;lt; rowCount; row++)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp; RowVector&amp;nbsp;currentRow = matrix.GetRow(row);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentRow -= factor * pivotRow&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;which could be part of the code for&amp;nbsp;computing the&amp;nbsp;LU Decomposition of a matrix. The &lt;FONT face="Courier New" size=2&gt;GetRow&lt;/FONT&gt; method returns the row of the matrix without making a copy of the data. The code inside the loop subtracts a multiple of the pivot row from the current row. With the current semantics where x&amp;nbsp;-=&amp;nbsp;y is equivalent to x&amp;nbsp;=&amp;nbsp;x&amp;nbsp;-&amp;nbsp;y, this&amp;nbsp;code does not perform as expected.&lt;/P&gt;
&lt;P&gt;What I would like to see is have the CLI spec changed to match what C++/CLI does. Compound assignment operators should be instance members.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Still&amp;nbsp;to come: a proposal for some (relatively) minor modifications to .NET generics to efficiently implement generic arithmetic, better support for arrays, and more.&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/42374.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Dynamic times two with the Dynamic Language Runtime</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2007/04/30/42278.aspx</link><pubDate>Mon, 30 Apr 2007 14:52:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2007/04/30/42278.aspx</guid><description>&lt;P&gt;Microsoft today &lt;A href="http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamic-language-runtime-dlr.aspx"&gt;announced&lt;/A&gt; their latest addition to the .NET family: the Dynamic Language Runtime (DLR). As Jim Hugunin points out, it is based on the IronPython 1.0 codebase, but has been generalized so it can support other dynamic languages, including Visual Basic.&lt;/P&gt;
&lt;P&gt;Now, the word 'dynamic' here is often misunderstood. Technically, the word dynamic refers to the type system. The .NET CLR is statically typed: every object has a well-defined type at compile time, and all method calls&amp;nbsp;and property references are resolved at compile time. Virtual methods are somewhat of an&amp;nbsp;in-between case, because which code is called depends on the runtime type, a type which may not even existed when the original code was compiled. But still, every type that overrides a method must inherit from a specific parent class.&lt;/P&gt;
&lt;P&gt;In dynamic languages, the type of variables, their methods and properties may be defined at runtime. You can create new types and add properties and methods to existing types. When a method is called in a dynamic language, the &lt;EM&gt;runtime &lt;/EM&gt;looks at the object, looks for a method that matches, and calls it. If there is no matching method, a run-time error is raised.&lt;/P&gt;
&lt;P&gt;Writing code in dynamic languages can be very quick, because there is&amp;nbsp;rarely a&amp;nbsp;need to specify type information. It's also very common to use dynamic languages interactively. You can execute IronPython scripts, but there's also a Console that hosts interactive IronPython sessions.&lt;/P&gt;
&lt;P&gt;And this is where it gets confusing. Because leaving out type information and interactive environments come naturally to dynamic languages, these features&amp;nbsp;are often thought of as properties of dynamic languages. They are not.&lt;/P&gt;
&lt;P&gt;Ever heard of &lt;A href="http://research.microsoft.com/fsharp"&gt;F#&lt;/A&gt;? It is&amp;nbsp;a statically typed, compiled language created by &lt;A href="http://blogs.msdn.com/dsyme/"&gt;Don Syme&lt;/A&gt; and others at Microsoft Research. It can be used to build libraries and end-user applications, much like C# and VB. But it&amp;nbsp;also has an interactive console and eliminates the need for most type specifications through a smart use of type inference.&lt;/P&gt;
&lt;P&gt;F# is not a dynamic language in the technical sense: it is statically typed. But because it has an interactive console and you&amp;nbsp;rarely have to specify types, it is a dynamic language in the eyes of a lot of people. In fact, at&amp;nbsp;the Lang.NET symposium&amp;nbsp;hosted by Microsoft last August, people were asked what their favorite dynamic language is. Many&amp;nbsp;answered with&amp;nbsp;F#. And these were programming language designers and compiler writers!&lt;/P&gt;
&lt;P&gt;Anyway, the point I wanted to make with this post is that the new Dynamic Language Runtime has great support for both the technically dynamic languages (dynamic types) and the perceived as dynamic features like interactive environments. I hope the distinction between these two aspects will be clarified in the future.&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/42278.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Latest Supercomputer Top 500</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2006/07/10/17752.aspx</link><pubDate>Mon, 10 Jul 2006 15:45:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2006/07/10/17752.aspx</guid><description>&lt;P&gt;Last week, the latest edition of the list of the &lt;A href="http://www.top500.org/"&gt;500 fastest supercomputers&lt;/A&gt; was released. Two recent developments make this list interesting.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The arrival of multicore processors. Even though their presence is still modest on the current list, expect their share to rise. Intel is targeting 32 cores on a chip by 2010.&lt;/LI&gt;
&lt;LI&gt;Microsoft made its entry on the scene with &lt;A href="http://www.microsoft.com/windowsserver2003/ccs/default.mspx"&gt;Windows Compute Cluster Server 2003&lt;/A&gt;, an enhanced Windows 2003&amp;nbsp;Enterprise Server version tweaked for High Performance Computing. The first (and so far the only) entry on the Top500 list is at the &lt;A href="http://access.ncsa.uiuc.edu/Releases/06.28.06_Top500_deb.html"&gt;National Center&amp;nbsp;for SuperComputing&lt;/A&gt; at the &lt;A href="http://www.uiuc.edu/"&gt;University of Illinois&lt;/A&gt;. It will be interesting to see how this number grows in the coming years. At the very least, it will give some indication of the headway Microsoft is making in the HPC&amp;nbsp;market.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Some trivia:&lt;/P&gt;
&lt;P&gt;The #1 spot is still held by IBM's BlueGene/L supercomputer at&amp;nbsp;the &lt;A href="http://www.llnl.gov/"&gt;Lawrence Livermore National Laboratory&lt;/A&gt;. At over 280TFlops, this monster is faster than an IBM PC with 8087 co-processor by a factor of roughly one billion.&amp;nbsp;That's right: it's as fast as 1,000,000,000 original IBM PC's!&lt;/P&gt;
&lt;P&gt;The first Top500 list&amp;nbsp;was published in &lt;A href="http://www.top500.org/list/1993/06/"&gt;June 1993&lt;/A&gt;.&amp;nbsp;It's interesting to note that one dual processor machine based on Intel's&amp;nbsp;latest dual-core&amp;nbsp;processors would, at &lt;A href="http://www.intel.com/performance/server/xeon/hpcapp.htm"&gt;34.9GFlops&lt;/A&gt;,&amp;nbsp;take the #2 spot on that original list. Today's average desktop would make it into the top 100...&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/17752.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Double trouble: an interesting puzzle</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2006/06/16/16647.aspx</link><pubDate>Fri, 16 Jun 2006 09:22:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2006/06/16/16647.aspx</guid><description>&lt;P&gt;I've written before about some of the strange looking&amp;nbsp;behavior you can find when working with&amp;nbsp;numbers on a computer. As &lt;A href="http://www.extremeoptimization.com/resources/articles/FPDotNetConceptsAndFormats.aspx"&gt;this article&lt;/A&gt; explains at length, this&amp;nbsp;behavior is a completely logical consequence of the need to use a finite set of values to represent potentially infinitely many numbers.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/kathykam/default.aspx"&gt;Kathy Kam&lt;/A&gt; of the Microsoft CLR team recently posted another interesting piece of &lt;A href="http://blogs.msdn.com/kathykam/archive/2006/05/08/592888.aspx"&gt;floating-point wierdness&lt;/A&gt;. The question boils down to this. When you run this code:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;Console.WriteLine(4.170404 == Convert.ToDouble(&lt;FONT color=#ff0000&gt;&amp;#8220;4.170404&amp;#8220;&lt;/FONT&gt;));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;why does it print &lt;FONT face="Courier New" color=#0000ff size=2&gt;false&lt;/FONT&gt; instead of the expected &lt;FONT face="Courier New" color=#0000ff size=2&gt;true&lt;/FONT&gt;?&lt;/P&gt;
&lt;P&gt;The answer turns out to be not trivial and comes down to the different ways that the .NET framework and the C# compiler convert text strings to numbers.&lt;/P&gt;
&lt;P&gt;The C# compiler uses the Windows API function &lt;FONT face="Courier New" size=2&gt;VarR8FromStr&lt;/FONT&gt; to convert the literal value to a double. The documentation isn't very precific about its inner workings. The C# spec says in section 9.4.4.3 that doubles are rounded using IEEE &amp;#8220;round to nearest&amp;#8220; mode.&lt;/P&gt;
&lt;P&gt;So what happens here? First, the number is 'normalized': the number is scaled by&amp;nbsp;a power of two so that the number is between 1 and 2. The scale factor is moved to the exponent. Next, the number is rounded to double precision, which has 52 significant binary digits.&lt;/P&gt;
&lt;P&gt;Here, 4.170404 is divided by 4, which gives 1.042601. The binary representation of this number is:&lt;/P&gt;
&lt;P&gt;1.0000101011100111111001100010110111000110111000101...&lt;/P&gt;
&lt;P&gt;The part that interests us starts at digit #52 after the &amp;#8220;binary point,&amp;#8220; so let's show everything after, say, the 40th digit:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;BR&gt;1234567890 1234567890 1234567890&lt;BR&gt;1110001010 1010000000 0000011001&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;To round to 52 binary digits, we need to round upwards:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;1234567890 12&lt;BR&gt;1110001010 11&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This result is used to compose the double precsion number.&lt;/P&gt;
&lt;P&gt;If we follow the path of the &lt;FONT face="Courier New" size=2&gt;Convert.ToDouble&lt;/FONT&gt; call, we find that it passes its string argument on to &lt;FONT face="Courier New" size=2&gt;Double.Parse&lt;/FONT&gt;. This&amp;nbsp;method prepares an internal structure called a &lt;FONT face="Courier New" size=2&gt;NumberBuffer&lt;/FONT&gt; and eventually calls a function named &lt;FONT face="Courier New" size=2&gt;NumberBufferToDouble&lt;/FONT&gt; internal to the CLR. In the Shared Source CLI implementation (Rotor) code, we find the following comment&amp;nbsp;for the function that does all the hard work:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The internal integer representation of the float number is&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UINT64 mantisa + INT exponent. The mantisa is kept normalized&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ie with the most significant one being 63-th bit of UINT64.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This is good news - extra precision is used to ensure we get the correct result. Looking further, we find that this function uses a helper function appropriately called &lt;FONT face="Courier New" size=2&gt;Mul64Lossy&lt;/FONT&gt;: which multiplies two 64bit values. In the comments, we find this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // it's ok to losse some precision here - Mul64 will be called&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // at most twice during the conversion, so the error won't propagate&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // to any of the 53 significant bits of the result&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This is bad news. If you look at the binary representation of 4.170404/4 above, you'll see that all digits from the 54th up to the 65th are zero. So it is very much possible that there &lt;EM&gt;was&lt;/EM&gt; some loss of precision here, and that it &lt;EM&gt;did&lt;/EM&gt; propagate to the last significant digit of the final result. The assumption made by the developer of this code is mostly right, but sometimes wrong.&lt;/P&gt;
&lt;P&gt;But why risk loss of precision when it can be avoided? The (misguided) answer is: speed. The Rotor code contains a function, &lt;FONT face="Courier New" size=2&gt;Mul64Precise&lt;/FONT&gt; which&amp;nbsp;doesn't suffer from this loss of precision. However, it does use a few extra instructions to do some more shifting and multiplying. The function is only used in debug mode to verify that some internal conversion tables are correct.&lt;/P&gt;
&lt;P&gt;In the grand scheme of things, the few extra instructions that would be used to get a correct result have only a very small effect on performance.&amp;nbsp;The &lt;FONT face="Courier New" size=2&gt;Convert.ToDouble&lt;/FONT&gt; method&amp;nbsp;that started it all ends up spending most of its time parsing according to the specified locale, checking for currency symbols, thousands separators, etc. Only a tiny fraction of the time is spent in the &lt;FONT face="Courier New" size=2&gt;Mul64&lt;/FONT&gt; functions.&lt;/P&gt;
&lt;P&gt;Let's estimate how common this error is. For a&amp;nbsp;conversion&amp;nbsp;error to occur, the 12 bits&amp;nbsp;from&amp;nbsp;the 53rd to the 64th must all be zero. That's about 1 in 4000. Also, the rounding&amp;nbsp;must be affected, which gives us another factor of 2 or 4. So, as many as&amp;nbsp;1 conversion out of every 10000&amp;nbsp;may suffer from this effect!&lt;/P&gt;
&lt;P&gt;The moral of the story: Be very careful with your assumptions about how errors will propagate. Don't compromise for the sake of a few CPU cycles, unless performance is&amp;nbsp;absolutely critical and is&amp;nbsp;more important than accuracy.&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/16647.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Fast, Faster, Fastest</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2006/04/26/13824.aspx</link><pubDate>Wed, 26 Apr 2006 10:05:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2006/04/26/13824.aspx</guid><description>&lt;P&gt;One of my favourite pass-times is getting the most out of a piece of code. Today, I got an opportunity to play a bit from a comment on Rico Mariani's latest performance challenge: how to format the time part of a DateTime structure in the form &amp;#8220;hh:mm:ss.mmm&amp;#8220; in the fastest possible way.&lt;/P&gt;
&lt;P&gt;Apparently, &lt;A href="http://geekswithblogs.net/akraus1/archive/2006/04/23/76146.aspx"&gt;Alois Kraus&lt;/A&gt; and &lt;A href="http://geekswithblogs.net/gyoung/archive/2006/04/24/76187.aspx"&gt;Greg Young&lt;/A&gt; have been at it for a bit. Their solution&amp;nbsp;already gives us more than a five-fold increase in speed compared to the simplest solution using &lt;FONT face="Courier New" size=2&gt;String.Format&lt;/FONT&gt;. But could we do even better?&lt;/P&gt;
&lt;P&gt;As it turns out, we could. Here's the code that we can improve:&lt;/P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;long&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt; ticks = time.Ticks;&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt; hour = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;)((ticks / 0x861c46800L)) % 24;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; minute = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;)((ticks / 0x23c34600L)) % 60;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; second = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;)(((ticks / 0x989680L)) % 60L);&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; ms = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt;)(((ticks / 0x2710L)) % 0x3e8L);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The tick count is the number of 100 nanosecond (ns) intervals since the zero time value. For each of the hour, minute, second and millisecond parts, this code divides the number of ticks by the number of 100ns intervals in that time span, and reduces that number to the number of units in the larger time unit using a modulo. So, for example, there are 60x60x10000000&amp;nbsp;ticks in an hour, which is 0x861c46800 in hex, and there are 24 hours in a day.&lt;/P&gt;
&lt;P&gt;What makes the above code less than optimal is that it starts from the number of ticks to compute every time part. This is a long (64 bit) value. 64-bit calculations are slower than 32-bit calculations. Moreover, divisions (or modulos) are much more expensive than multiplications.&lt;/P&gt;
&lt;P&gt;We can fix both these issues by first finding the total number of milliseconds in the day. That number is always smaller than 100 million, so it fits in an &lt;FONT face="Courier New" size=2&gt;int&lt;/FONT&gt;. We can calculate the number of hours&amp;nbsp;with a simple division. We can &amp;#8220;peel off&amp;#8221; the hours from the total number of milliseconds in the day to find the total milliseconds remaining in the hour. From this, we can calculate the number of minutes with a simple division, and so on. The improved code looks like this:&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT face="Courier New"&gt;long&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New" color=#000000&gt; ticks = time.Ticks;&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; ms = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;)((ticks / 10000) % 86400000);&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt; hour = ms / 3600000;&lt;BR&gt;ms -= 3600000*hour;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt; minute = ms / 60000;&lt;BR&gt;ms -= 60000 * minute;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt; second = ms / 1000;&lt;BR&gt;ms -= 1000*second;&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;This change decreases the running time by about 28 percent from the fastest previous solution. We can shave off another 4% or so by replacing the modulo calculation by a subtraction in the code that computes the digits.&lt;/P&gt;
&lt;P&gt;The question now is: can we do even better, still?&lt;/P&gt;
&lt;P&gt;Once again, the answer is: Yes: by as much as another 25%!&lt;/P&gt;
&lt;P&gt;The single most time consuming calculation is a division.&amp;nbsp;Dividing by large numbers is an order of magnitude slower than multiplying. For smaller numbers, the difference is smaller, but still significant.&amp;nbsp;Since we know the numbers we are dividing by in advance, we can do a little bit shifting magic and eliminate the divisions altogether.&lt;/P&gt;
&lt;P&gt;Let's take dividing by 10 as an example. The basic idea is to approximate the ratio 1/10 by another rational number with a power of two as the denominator.&amp;nbsp;Instead of dividing, we can then multiply by the numerator, and shift by the exponent in the denominator. Since shifting chops off digits, it effectively rounds down the result of the division, so we always have to find an approximation that is larger than the ratio.&lt;/P&gt;
&lt;P&gt;We see, for example, that&amp;nbsp;13/128 is a good approximation to 1/10. We can rewrite &lt;FONT face="Courier New" size=2&gt;x/10&lt;/FONT&gt; as &lt;FONT face="Courier New" size=2&gt;(x*13) &amp;gt;&amp;gt; 7&lt;/FONT&gt;&amp;nbsp;as long as &lt;FONT face="Courier New" size=2&gt;x&lt;/FONT&gt;&amp;nbsp;is not too large. We run into trouble as soon as the error time &lt;FONT face="Courier New" size=2&gt;x&lt;/FONT&gt; is larger than 1. In this case, that happens when &lt;FONT face="Courier New" size=2&gt;x&lt;/FONT&gt; is larger than 13/(13-12.8) = 65.&amp;nbsp;Fortunately, this is larger than the number of hours in a day, or the number of minutes in an hour, so we can use it for most calculations in our code. It won't work for numbers up to a 100, so to get the second digit of the millisecond, we need the next approximation, 205/2048, which is good for values up to 10,000.&lt;/P&gt;
&lt;P&gt;To get the first digit of the milliseconds, we need to divide by 100. We find that 41/4096 works nicely.&lt;/P&gt;
&lt;P&gt;Implementing this optimization, we go from (for example):&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;*a = (&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(hour / 10 + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;a++;&lt;BR&gt;*a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(hour % 10 + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;to:&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt; temp = (hour * 13) &amp;gt;&amp;gt; 7;&lt;BR&gt;*a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;a++;&lt;BR&gt;*a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(hour - 10 * temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;FONT size=2&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Our running time for 1 million iterations goes down from 0.38s to 0.28s, a savings of almost 18% compared to the original.&lt;/P&gt;
&lt;P&gt;The larger divisors give us a bit of a challenge. To get the number of seconds, we divide a number less than 60000 by 1000. Doing this the straight way has us multiplying by 536871, which would require a long value for the result of the multiplication. We can get around this once we realize that 1000 = 8*125. So if we shift the number of milliseconds by 3, we only need to divide by 125. As an added benefit, the numbers we're multiplying are always less than 7500, so our multiplier can be larger. This gives us the simple expression good for numbers up to almost 4 million:&amp;nbsp;((x&amp;nbsp;&amp;gt;&amp;gt;&amp;nbsp;3)&amp;nbsp;*&amp;nbsp;67109)&amp;nbsp;&amp;gt;&amp;gt;&amp;nbsp;23.&lt;/P&gt;
&lt;P&gt;The same trick doesn't work for getting the minutes and hours, but it does allow us to fit the intermediate result into a long. We can use the &lt;FONT face="Courier New" size=2&gt;Math.BigMul&lt;/FONT&gt; method to perform the calculation efficiently.&lt;/P&gt;
&lt;P&gt;The final code is given below. It is doubtful it can be improved by much. It runs&amp;nbsp;in as little as 0.221s for one million iterations, 2.5 times faster than the previous fastest code and over 25 times faster than the original.&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;private&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;unsafe&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;static&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; FormatFast6(&lt;/FONT&gt;&lt;FONT color=#c0c0c0 size=2&gt;DateTime&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt; time)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;fixed&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;* p = dateData)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;long&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt; ticks = time.Ticks;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;* a = p;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; ms = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;)((ticks / 10000) % 86400000);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; hour = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt;)(&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt;Math&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;.BigMul(ms &amp;gt;&amp;gt; 7, 9773437) &amp;gt;&amp;gt; 38);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ms -= 3600000 * hour;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; minute = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt;)((&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt;Math&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;.BigMul(ms &amp;gt;&amp;gt; 5, 2290650)) &amp;gt;&amp;gt; 32);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ms -= 60000 * minute;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt; second = ((ms &amp;gt;&amp;gt; 3) * 67109) &amp;gt;&amp;gt; 23;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ms -= 1000 * second;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt; temp = (hour * 13) &amp;gt;&amp;gt; 7;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a++;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(hour - 10 * temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a += 2;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = (minute * 13) &amp;gt;&amp;gt; 7;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a++;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(minute - 10 * temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a += 2;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = (second * 13) &amp;gt;&amp;gt; 7;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a++;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(second - 10 * temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a += 2;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = (ms * 41) &amp;gt;&amp;gt; 12;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a++;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ms -= 100 * temp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp = (ms * 205) &amp;gt;&amp;gt; 11;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ms -= 10 * temp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a++;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *a = (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;char&lt;/FONT&gt;&lt;FONT size=2&gt;)(ms - 10 * temp + &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;'0'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;return&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#c0c0c0 size=2&gt;String&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;(dateData);&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/13824.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Visual Studio as an interactive technical computing environment</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2006/02/19/7355.aspx</link><pubDate>Sun, 19 Feb 2006 18:18:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2006/02/19/7355.aspx</guid><description>&lt;P&gt;A year ago, we were experimenting with an extensive sample that would illustrate the linear algebra capabilities of our math library. Unfortunately, &lt;A href="http://www.extremeoptimization.com/mathematics/samples/MSharp.aspx"&gt;M#, the .NET Matrix Workbench&lt;/A&gt; didn't get very far. We're technical guys. Building user interfaces just isn't our cup of tea, and the IDE we built wasn't stable enough to make it into an end-user product.&lt;/P&gt;
&lt;P&gt;At the time, I realized that much of the functionality needed for this kind of interactive computing environment was already present in Visual Studio .NET. For example, we already have an excellent&amp;nbsp;code editor, a project workspace, and&amp;nbsp;tool windows that display variables and their values. Moreover,&amp;nbsp;in the &lt;A href="http://msdn.microsoft.com/vstudio/extend/default.aspx"&gt;Visual Studio SDK&lt;/A&gt;, we have a framework for extending that environment with visualizers for specific types of variables, intellisense,&amp;nbsp;custom project items, and so on.&lt;/P&gt;
&lt;P&gt;Plus, you have a great library (the .NET Base Class Libraries) that you can use to do just about anything you'd like.&lt;/P&gt;
&lt;P&gt;In short,&amp;nbsp;Visual Studio is the ideal starting point to build a great technical computing IDE.&lt;/P&gt;
&lt;P&gt;A couple of recent news items bring this vision closer to reality. Aaron Marten &lt;A href="http://blogs.msdn.com/aaronmar/archive/2006/02/16/533273.aspx"&gt;reports&lt;/A&gt; that the February 2006 CTP of the Visual Studio 2005 SDK now contains a tool window that hosts an&amp;nbsp;IronPython console. And just a few days ago, Don Syme gave us a &lt;A href="http://blogs.msdn.com/dsyme/archive/2006/02/19/534925.aspx"&gt;taste&lt;/A&gt; of what is to come in the next release of F#. The screen shot is the kind you would expect from &lt;A href="http://www.mathworks.com/products/matlab/index.html"&gt;Matlab&lt;/A&gt;. (I guess I was right when I &lt;A href="http://blogs.extremeoptimization.com/jeffrey/archive/2005/06/27/380.aspx"&gt;wrote&lt;/A&gt; that Don gets what scientists and engineers need.)&lt;/P&gt;
&lt;P&gt;Now, all we need is a Matlab-like language for the .NET platform...&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/7355.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Yahoo Finance miscalculates monthly average daily volume</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2006/02/17/7272.aspx</link><pubDate>Fri, 17 Feb 2006 20:32:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2006/02/17/7272.aspx</guid><description>&lt;P&gt;Am I missing something here?&lt;/P&gt;
&lt;P&gt;While testing some time series functionality in the new version of our &lt;A href="http://www.extremeoptimization.com/statistics/default.aspx"&gt;statistics library&lt;/A&gt;, we came across a rather curious discrepancy. We used the historical quotes available from&amp;nbsp;&lt;A href="http://finance.yahoo.com/"&gt;Yahoo Finance&lt;/A&gt; as a reference resource. As it turns out, comparison with our data appears to show that Yahoo miscalculates some summary statistics.&lt;/P&gt;
&lt;P&gt;The error occurs on the Historical Prices page when using a monthly timeframe. Take the &lt;A href="http://finance.yahoo.com/q/hp?s=MSFT&amp;amp;a=00&amp;amp;b=1&amp;amp;c=2005&amp;amp;d=11&amp;amp;e=31&amp;amp;f=2005&amp;amp;g=m"&gt;monthly data for 2005&lt;/A&gt;&amp;nbsp;for Microsoft's stock (symbol MSFT). This shows an average daily volume for January of 79,642,818 shares. According to the &lt;A href="http://help.yahoo.com/help/us/fin/quote/quote-12.html"&gt;help document&lt;/A&gt;, this is &amp;#8220;the average daily volume for all trading days in the reported month.&amp;#8221;&lt;/P&gt;
&lt;P&gt;When we look at the &lt;A href="http://finance.yahoo.com/q/hp?s=MSFT&amp;amp;a=00&amp;amp;b=1&amp;amp;c=2005&amp;amp;d=00&amp;amp;e=31&amp;amp;f=2005&amp;amp;g=d"&gt;daily prices for January 2005&lt;/A&gt;, we find 20 trading days. When we add up all the daily volumes, we find 1,521,414,280 shares changed hands that month. That should give an average daily volume of 76,070,714 shares, more than &lt;EM&gt;3 million shares less &lt;/EM&gt;than Yahoo's figure. Why the difference?&lt;/P&gt;
&lt;P&gt;A brief investigation showed that the difference can be explained because Yahoo includes the volume on the last trading day of the month &lt;U&gt;twice&lt;/U&gt;. If you add the volume of Jan. 1st to the total, we get 1,592,856,376. Dividing by the number of trading days (20) gives 79,642,818.8.&lt;/P&gt;
&lt;P&gt;When we look at other months, we find the same pattern: Yahoo consistently overstates the average daily volume for the month by a few percentage points. Each time, this difference can be explained by the&amp;nbsp;double inclusion of the volume of the last trading day in the total volume for the month.&lt;/P&gt;
&lt;P&gt;Here's a&amp;nbsp;random sample: Research in Motion for June 2000. &lt;A href="http://finance.yahoo.com/q/hp?s=RIMM&amp;amp;a=05&amp;amp;b=1&amp;amp;c=2000&amp;amp;d=05&amp;amp;e=30&amp;amp;f=2000&amp;amp;g=m"&gt;Yahoo&lt;/A&gt; gives&amp;nbsp;an average daily volume of 4,262,160 shares. Our calculation shows an average of 3,870,800 shares corresponding to a total volume of 77,416,000 for the month. Yahoo's&amp;nbsp;total&amp;nbsp;corresponds to&amp;nbsp;85,243,200 shares. The difference of 7,820,200 shares is exactly the &lt;A href="http://finance.yahoo.com/q/hp?s=RIMM&amp;amp;a=05&amp;amp;b=1&amp;amp;c=2000&amp;amp;d=05&amp;amp;e=30&amp;amp;f=2000&amp;amp;g=d"&gt;volume for June 30th&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The weekly average daily volume appears to be correct.&lt;/P&gt;
&lt;P&gt;I find it hard to believe that a service that is as widely used as Yahoo would show such an error. So, my question to the experts in technical analysis out there is: What am I missing???&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/7272.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Overload resolution in C#</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2006/02/10/7134.aspx</link><pubDate>Fri, 10 Feb 2006 22:34:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2006/02/10/7134.aspx</guid><description>&lt;P&gt;Programming language design is a very tough discipline. You can be sure that every feature will be used and just as often abused in unexpected ways. Mistakes are close to impossible to fix.&lt;/P&gt;
&lt;P&gt;C# is a great language. It's my language of choice for most applications. It derives a lot of its quality from the cautious nature of its lead&amp;nbsp;architect, Anders Hejlsberg, who tries to guide programmers into writing good code. That's why unsafe code is called unsafe. Not because it is a security risk, but because it is really easy to get yourself into a buggy mess with it. It is why methods and properties have to be explicitly declared virtual, because people tend to override methods when it is not appropriate.&lt;/P&gt;
&lt;P&gt;In some cases, however,&amp;nbsp;this protecting&amp;nbsp;developers against themselves&amp;nbsp;can go to far. Overload resolution is one example I came across recently.&lt;/P&gt;
&lt;P&gt;Consider a &lt;FONT face="Courier New" size=2&gt;Curve&lt;/FONT&gt; class that represents a mathematical curve. It has a &lt;FONT face="Courier New" size=2&gt;ValueAt&lt;/FONT&gt; method which gets the value of the curve at a specific x-value, which is passed in as a &lt;FONT face="Courier New" size=2&gt;Double&lt;/FONT&gt; argument. This is a virtual method, of course, and specific types of curves, like &lt;FONT face="Courier New" size=2&gt;Polynomial&lt;/FONT&gt; or &lt;FONT face="Courier New" size=2&gt;CubicSpline&lt;/FONT&gt;, provide their own implementation.&lt;/P&gt;
&lt;P&gt;Now, for polynomials in particular, it is sometimes desirable to get the value of the polynomial for a complex argument. So we define an overload that takes a &lt;FONT face="Courier New" size=2&gt;DoubleComplex&lt;/FONT&gt; argument and also returns a &lt;FONT face="Courier New" size=2&gt;DoubleComplex&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;So far so good.&lt;/P&gt;
&lt;P&gt;But now we want to add a conversion from &lt;FONT face="Courier New" size=2&gt;Double&lt;/FONT&gt; to &lt;FONT face="Courier New" size=2&gt;DoubleComplex&lt;/FONT&gt;. This is a widening conversion: every real number is also a complex number. So it is appropriate to make the conversion implicit. We can then write things like:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;DoubleComplex a = 5.0;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;instead of&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;DoubleComplex a = &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; DoubleComplex(5.0);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Unfortunately, this change breaks existing code. The following snippet will no longer compile:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;Polynomial p = &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; Polynomial(1.0, 2.0, 3.0);&lt;BR&gt;double y = p.ValueAt(1.0);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;On the second line, we get an error message: &amp;#8220;Cannot implicitly convert type DoubleComplex to Double.&amp;#8221; Why? Because of the way C# resolves method overloads. &lt;/P&gt;
&lt;P&gt;Specifically, C# considers methods declared in a type before anything else, including override methods. &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_7_3.asp"&gt;Section 7.3&lt;/A&gt; of the C# spec (&amp;#8220;Member lookup&amp;#8220;) states:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 12pt"&gt;First, the set of all accessible &lt;A href="http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_3_5.asp"&gt;&lt;FONT color=#002c99&gt;(Section 3.5)&lt;/FONT&gt;&lt;/A&gt; members named &lt;CODE class=ce&gt;N&lt;/CODE&gt; declared in &lt;CODE class=ce&gt;T&lt;/CODE&gt; and the base types &lt;A href="http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_7_3_1.asp"&gt;&lt;FONT color=#002c99&gt;(Section 7.3.1)&lt;/FONT&gt;&lt;/A&gt; of &lt;CODE class=ce&gt;T&lt;/CODE&gt; is constructed. Declarations that include an &lt;CODE class=ce&gt;&lt;FONT size=2&gt;override&lt;/FONT&gt;&lt;/CODE&gt; modifier are excluded from the set. If no members named &lt;CODE class=ce&gt;N&lt;/CODE&gt; exist and are accessible, then the lookup produces no match, and the following steps are not evaluated. &lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In this case, because there is an implicit conversion from &lt;FONT face="Courier New" size=2&gt;Double&lt;/FONT&gt; to &lt;FONT face="Courier New" size=2&gt;DoubleComplex&lt;/FONT&gt;, the &lt;FONT face="Courier New" size=2&gt;ValueAt(DoubleComplex)&lt;/FONT&gt; overload is applicable. Even though there is an overload whose parameters match exactly, it isn't even considered here, because it is an override.&lt;/P&gt;
&lt;P&gt;This highly unintuitive behavior is justified by the following two rules:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Whether or not a method is overridden is an implementation detail that should be allowed to change without breaking client code.&lt;/LI&gt;
&lt;LI&gt;Changes to a base class that don't break an inherited class should not break clients of the inherited class.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Even though neither of these actually applies to our example, I can understand that these rules are useful in&amp;nbsp;many situations. In this case, however, it essentially hides the &lt;FONT face="Courier New" size=2&gt;ValueAt(Double)&lt;/FONT&gt; overload I defined, unless I use an ugly upcast construct like&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;double y = ((Curve)p).ValueAt(1.0);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;My problem is this: If I&amp;nbsp;define an overload&amp;nbsp;that takes a specific argument type, clearly my intent is for that&amp;nbsp;overload to be called whenever the argument is of that exact type. This rule violates that intent.&lt;/P&gt;
&lt;P&gt;In my view, it was a mistake to&amp;nbsp;violate developer intent in this way and not&amp;nbsp;give an exact&amp;nbsp;signature match precedence over every other overload candidate.&amp;nbsp;Unfortunately, this is one of those choices that&amp;nbsp;in all likelihood is&amp;nbsp;next to impossible to fix.&lt;/P&gt;
&lt;P&gt;Visual Basic has a different set of &lt;A href="http://msdn2.microsoft.com/en-us/library/tb18a48w.aspx"&gt;overload resolution rules&lt;/A&gt;. It looks for the overload with the least widening conversion, and so would pick the correct overload in this case.&lt;/P&gt;
&lt;P&gt;Thanks to &lt;A href="http://blogs.msdn.com/nealho/archive/2006/01/19/515173.aspx"&gt;Neal Horowitz&lt;/A&gt; for helping me clear up this issue.&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/7134.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Accessing floating-point context from .NET applications</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2006/02/08/7074.aspx</link><pubDate>Wed, 08 Feb 2006 14:29:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2006/02/08/7074.aspx</guid><description>&lt;P&gt;A&amp;nbsp;few days&amp;nbsp;ago, I wrote about &lt;A href="http://blogs.extremeoptimization.com/jeffrey/archive/2006/01/30/6736.aspx"&gt;the need for the .NET framework to support floating-point exceptions&lt;/A&gt;. Although the solution I proposed there goes some way towards fixing the problem, it would create a few of its own as well.&lt;/P&gt;
&lt;P&gt;The main issue is that the processor's FPU (floating-point unit) is a global resource. Therefore it should be handled with extreme care.&lt;/P&gt;
&lt;P&gt;For an example of what can go wrong if you don't, we can look at the story of Managed DirectX. DirectX is the high-performance multimedia/graphics/gaming API on the Windows platform. Because performance is of the essence, the DirectX guys decided to ask the processor to do its calculations in single precision by default. This is somewhat faster than the default, and all that is generally needed for the kinds of applications they encountered.&lt;/P&gt;
&lt;P&gt;When people started using the .NET framework to build applications&amp;nbsp;using Managed DirectX, some people found that it &lt;A href="http://blogs.msdn.com/tmiller/archive/2004/06/01/145596.aspx"&gt;broke the .NET math functions&lt;/A&gt;. The reason:&amp;nbsp;the precision setting of the FPU is global. It therefore affected all floating-point code in the application, including the calls into the .NET Base Class Libraries.&lt;/P&gt;
&lt;P&gt;The problem with our initial solution is that it doesn't behave nicely. It doesn't isolate other code from changes to the floating-point state. This can affect code in unexpected ways.&lt;/P&gt;
&lt;P&gt;So how do we fix this?&lt;/P&gt;
&lt;P&gt;One option is to flag code that uses special floating-point settings with an attribute like &amp;#8220;FloatingPointContextAware.&amp;#8221; Any code that has this attribute can access floating-point state. However, any code that does not have this attribute would require the CLR to explicitly save the floating-point state.&lt;/P&gt;
&lt;P&gt;Unfortunately, this fix suffers from&amp;nbsp;a number of drawbacks:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In some applications, like error analysis, you &lt;EM&gt;want&lt;/EM&gt; to set global state. For example, one way to check whether an algorithm is stable is to run it twice using different rounding modes. If the two results&amp;nbsp;are significantly different, you have a problem.&lt;/LI&gt;
&lt;LI&gt;It is overkill in most situations. If you're going to use special floating-point features, you should be able to isolate yourself properly from any changes in floating-point state. If you have no knowledge such features exist, chances are your code won't break if, say, the rounding mode is changed.&lt;/LI&gt;
&lt;LI&gt;It is a performance bottleneck. You can't require all your client code to also have this attribute. Remember the goal was to allow 'normal' calculations to be done as fast as possible while making the&amp;nbsp;edge cases&amp;nbsp;reasonably fast as well. It is counter-productive to impose a performance penalty on &lt;EM&gt;every&lt;/EM&gt; call.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;The best solution I can think of is to actually treat the floating-point unit for what it is: a resource. If you want to use its special features, you should inform the system when you plan to use them, and also when you're done using them.&lt;/P&gt;
&lt;P&gt;We make floating-point state accessible only through instances of a FloatingPointContext class, which implements IDisposable and does the necessary bookkeeping. It saves enough of the floating-point state when it is constructed, and restores it when it is disposed. You don't always have to save and restore the full floating-point state, including values on the stack, etc. In most cases, you only need to save the control word, which is relatively cheap.&lt;/P&gt;
&lt;P&gt;A typical use for this class would be as follows:&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face="Courier New" color=blue size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt; (FloatingPointContext context = &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&lt;/FONT&gt; FloatingPointContext())&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;{&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.RoundingMode = RoundingMode.TowardsZero;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.ClearExceptionFlags();&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=green&gt;&lt;SPAN style="COLOR: green"&gt;// Do some calculations&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;&lt;/FONT&gt; (context.IsExceptionFlagRaised(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;FloatingPointExceptionFlag.Underflow))&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=green&gt;&lt;SPAN style="COLOR: green"&gt;// Do some more stuff&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;}&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I have submitted a proposal for&amp;nbsp;a FloatingPointContext class to the CLR team. So far they have chosen to keep it under consideration for the next version. Let's hope they'll choose to implement it.&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/7074.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Floating-point exceptions and the CLR</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2006/01/30/6736.aspx</link><pubDate>Mon, 30 Jan 2006 19:21:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2006/01/30/6736.aspx</guid><description>&lt;P&gt;I've decided to share some of&amp;nbsp;our experiences during the development of our &lt;A href="http://www.extremeoptimization.com/mathematics/default.aspx"&gt;math&lt;/A&gt; and &lt;A href="http://www.extremeoptimization.com/statistics/default.aspx"&gt;statistics&lt;/A&gt; libraries in the hope that they may contribute to improvements in the .NET platform as the next version is being designed.&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;CLR&amp;nbsp;is a general-purpose runtime environment, and cannot be expected to support every application at the fastest possible speed. However, I do expect it to perform reasonably well, and if a performance hit can be avoided, then it should be. The absence of any floating-point exception mechanism incurs such a performance hit in some fairly common situations.&lt;/P&gt;
&lt;P&gt;As an example, let&amp;#8217;s take an implementation of complex numbers. This is a type for general use, and has to give accurate results whenever possible. For obvious reasons, we want the core operations to be as fast as possible. This means we want to inline when we can, and make our code fast, too. Most operations are fairly straightforward, but division isn&amp;#8217;t. Let&amp;#8217;s start with the &amp;#8216;na&amp;#239;ve&amp;#8217; implementation:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=blue size=2&gt;&lt;SPAN&gt;struct&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt; Complex&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;{&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;private&lt;/SPAN&gt;&lt;/FONT&gt; re, im;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;public static operator&lt;/SPAN&gt;&lt;/FONT&gt;/(Complex z1, Complex z2)&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;&amp;nbsp; {&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; d = z2.re*z2.re + z2.im*z2.im;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; resultRe = z1.re * z2.re + z1.im * z2.im;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; resultIm = z1.im * z2.re &amp;#8211; z1.re * z2.im;&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;return new&lt;/SPAN&gt;&lt;/FONT&gt; Complex(resultRe / d, resultIm / d);&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;&amp;nbsp; }&lt;BR&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/FONT&gt; 
&lt;P&gt;If any of the values &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;d&lt;/SPAN&gt;&lt;/FONT&gt;,&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt; resultRe&lt;/SPAN&gt;&lt;/FONT&gt;, and&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt; resultIm&lt;/SPAN&gt;&lt;/FONT&gt; &lt;I&gt;&lt;SPAN&gt;under&lt;/SPAN&gt;&lt;/I&gt;flow, the result will lose accuracy, because subnormal numbers by definition don&amp;#8217;t have the full 52 bit precision. The CLR also offers no indication that underflow has occurred.&amp;nbsp;This can be fixed, mostly, by modifying the above to:&lt;/SPAN&gt;&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&lt;FONT color=blue&gt;&lt;SPAN&gt;public static operator&lt;/SPAN&gt;&lt;/FONT&gt;/(Complex z1, Complex z2)&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;/FONT&gt; (Math.Abs(z2.re) &amp;gt; Math.Abs(z2.im)&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; {&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; t = z2.im / z2.re;&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; d = z2.re + t * z2.im;&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; resultRe = (z1.re + t * z1.im);&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; resultIm = (z1.im &amp;#8211; t * z1.re);&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=blue&gt;&lt;SPAN&gt;return new&lt;/SPAN&gt;&lt;/FONT&gt; Complex(resultRe / d, resultIm / d);&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; }&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; {&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; t = z2.re / z2.im;&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; d = t * z2.re + z2.im;&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; resultRe = (t * z1.re + z1.im);&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; resultIm = (t * z1.im &amp;#8211; z1.re);&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=blue&gt;&lt;SPAN&gt;return new&lt;/SPAN&gt;&lt;/FONT&gt; Complex(resultRe / d, resultIm / d);&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; }&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;}&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;This will give accurate results in a larger domain, but is slower because of the extra division. Worse still, some operations that one would expect to give exact results now aren&amp;#8217;t exact. For example, if &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;z1 = 27-21i&lt;/SPAN&gt;&lt;/FONT&gt; and &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;SPAN&gt;z2 = 9-7i&lt;/SPAN&gt;&lt;/FONT&gt;, the exact result is 3, but the round-off in the division by 9 destroys the exact result.&lt;/SPAN&gt;&lt;/FONT&gt; 
&lt;P&gt;IEEE-754 exceptions would come to the rescue here &amp;#8211; if they were available. Exceptions (a term with a specific meaning in the IEEE-754 standard - not to be confused with CLR exceptions) raise a flag in the FPU&amp;#8217;s status register, and can also be trapped by the operating system. We don&amp;#8217;t need a trap here. We can do what we need to do with a flag. The code would look something like:&lt;/SPAN&gt;&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&lt;FONT color=blue&gt;&lt;SPAN&gt;public static operator&lt;/SPAN&gt;&lt;/FONT&gt;/(Complex z1, Complex z2)&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;FloatingPoint.ClearExceptionFlag(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FloatingPointExceptionFlag.Underflow);&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; d = z2.re*z2.re + z2.im*z2.im;&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; resultRe = z1.re * z2.re + z1.im * z2.im;&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;double&lt;/SPAN&gt;&lt;/FONT&gt; resultIm = z1.im * z2.re &amp;#8211; z1.re * z2.im;&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;/FONT&gt; (FloatingPoint.IsExceptionFlagRaised(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FloatingPointExceptionFlag.Underflow)&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; {&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=green&gt;&lt;SPAN&gt;// Code for the special cases.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; }&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp; &lt;FONT color=blue&gt;&lt;SPAN&gt;return new&lt;/SPAN&gt;&lt;/FONT&gt; Complex(resultRe / d, resultIm / d);&lt;/SPAN&gt;&amp;nbsp;&lt;BR&gt;&lt;SPAN&gt;}&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Note that the CLR strategy to &amp;#8220;continue with default values&amp;#8221; won&amp;#8217;t work here, because complete underflow is defaulted to 0, which can not be distinguished from the common case when the result is exactly zero (and therefore no special action is required). The only way to do it right would be a whole series of ugly comparisons, which would make the code slower and harder to read/maintain. Even if a language supported a mechanism to check for underflow (by inserting comparisons to a suitable small value before and after storing the value), this would bloat the IL, introduce unnecessary round-off (by forcing a conversion from extended to double on each operation), and slow things down unnecessarily.&lt;/P&gt;
&lt;P&gt;This type of scenario occurs many times in numerical calculations. You perform a calculation the quick and dirty way, and if it turns out you made a mess, you try again but you&amp;#8217;re more cautious. The complex number example is the most significant one I have come across while developing our numerical libraries.&lt;/P&gt;
&lt;P&gt;Nearly all hardware that the CLR (or its clones) run on, supports this floating-point exception mechanism. I found it somewhat surprising that a &amp;#8216;standard&amp;#8217; virtual execution environment would not adopt another and well-established standard (IEEE-754) for a specific subset of its functionality.&lt;/P&gt;
&lt;P&gt;For more on the math jargon used in this post, see my article &lt;A href="http://www.extremeoptimization.com/resources/Articles/FPDotNetConceptsAndFormats.aspx"&gt;Floating-Point in .NET Part 1: Concepts and Formats&lt;/A&gt;.&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/6736.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>The future of games</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2006/01/28/6678.aspx</link><pubDate>Sat, 28 Jan 2006 22:19:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2006/01/28/6678.aspx</guid><description>&lt;P&gt;Board games that is...&lt;/P&gt;
&lt;P&gt;Once upon a time, a board game consisted of a board, some pawns and some dice. Over the years, game designers added more and more props. Dynamic game play was possible, but you had to do all the work.&lt;/P&gt;
&lt;P&gt;Now, Philips Research have developed the &lt;A href="http://www.entertaible.com/"&gt;Entertaible&lt;/A&gt;. Pawns and dice are still around, but now the board itself can change during play. My friend Peter Sels did some of the programming.&lt;/P&gt;
&lt;P&gt;Since&amp;nbsp;they're only at the prototype stage,&amp;nbsp;the price tag will&amp;nbsp;likely be too high for some time, even for&amp;nbsp;Santa.&amp;nbsp;Maybe in a few years they'll sell a &amp;#8220;1000 in 1&amp;#8221; board game for $19.95...&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/6678.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Bill Gates on Technical Computing</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2005/12/08/5226.aspx</link><pubDate>Thu, 08 Dec 2005 12:52:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2005/12/08/5226.aspx</guid><description>&lt;P&gt;At the recent supercomputing conference in Seattle, Bill Gates gave a keynote address (&lt;A href="http://www.microsoft.com/billgates/speeches/2005/11-15SuperComputing05.asp"&gt;transcript&lt;/A&gt;) where he announced that Microsoft had re-discovered its interest in scientific computing. (Microsoft's second product was a Fortran compiler for CP/M, released in August 1977.) The motive is obviously commercial, but the statement is still significant. Microsoft has treated technical computing as a second class citizen for too long.&lt;/P&gt;
&lt;P&gt;A couple of points I found of particular interest:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The primary interest appears to be in smoothing out the process of scientific discovery, with a lot of emphasis on data integration (using XML, of course), transparent distributed computing, and enhanced collaboration.&lt;/LI&gt;
&lt;LI&gt;There is no mention at all of the nuts and bolts programming of numerical applications. He briefly mentions 'visual programming,' but that's about it.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Improving workflow is one of Microsoft's strengths. Scientific computing, on the other hand, is not, which probably explains Gates' silence on the subject. Many people applauded DEC's acquisition of Microsoft Fortran, which is now being phased out in favour of Intel Visual Fortran.&lt;/P&gt;
&lt;P&gt;The .NET platform doesn't exactly make it easy to write good numerical software. Even aside from the lack of support for rounding modes and standard floating-point exception mechanisms, the standard .NET languages (C# and Visual Basic) are not technical-computing friendly. There is no doubt in my mind that the .NET platform delivers a major improvement in developer productivity for general line-of-business applications.&lt;/P&gt;
&lt;P&gt;Unfortunately, where technical computing is concerned, the productivity promise remains largely unfulfilled. It takes more than a keynote speech to win over the hearts of a community that has been ignored for so long. &lt;EM&gt;&amp;#8220;Developers, developers, developers!&amp;#8221;&lt;/EM&gt;, Bill. Make writing numerical software for .NET a joy for developers.&lt;/P&gt;
&lt;P&gt;What we need is a .NET language specifically targeted at technical computing. Will &lt;A href="http://blogs.extremeoptimization.com/jeffrey/archive/2005/06/27/380.aspx"&gt;F#&lt;/A&gt; be it? Don Syme is obviously doing a lot of great work there. But&amp;nbsp;functional programming for everyone?&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/5226.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>.NET Framework support for compliance with guidelines</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2005/10/02/3105.aspx</link><pubDate>Sun, 02 Oct 2005 11:51:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2005/10/02/3105.aspx</guid><description>&lt;P&gt;One of the biggest issues facing developers of reusable libraries is backward compatibility. When you get to work on version 2.0 or later, you will inevitably regret some of the choices you made in the previous version. Typical&amp;nbsp;issues include:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;We should have named this method XXX instead.&lt;/LI&gt;
&lt;LI&gt;This should have been a method, not a property.&lt;/LI&gt;
&lt;LI&gt;We should have put these types in their own namespace.&lt;/LI&gt;
&lt;LI&gt;We should have used an enum instead of a bool for that parameter.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Unfortunately, fixing any of these issues could break existing code. Even though you may have very good reasons to change the API, your customers won't be happy.&lt;/P&gt;
&lt;P&gt;I read a &lt;A href="http://spaces.msn.com/members/EmilyAliceComments/Blog/cns!1plSoI7JqL4RX0bSvW6TQadA!183.entry"&gt;suggestion&lt;/A&gt; recently to use the &lt;A href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemobsoleteattributememberstopic.asp"&gt;Obsolete&lt;/A&gt; attribute to aid in the conversion. This class has a &lt;A href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemobsoleteattributeclassmessagetopic.asp"&gt;Message&lt;/A&gt; property that can be used to inform the user of the recommended alternative.&lt;/P&gt;
&lt;P&gt;Now, wouldn't it be nice if, in addition to this message,&amp;nbsp;you could specify the required changes in a formal&amp;nbsp;manner using attributes. With Visual Studio 2005's refactoring support, it should then be relatively easy to write an add-in that interprets this information and performs the necessary changes for you. This would work only for relatively simple modifications. But it would still be a big help, and make the transition to compliant code a lot easier.&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/3105.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>A blog on every desk and in every home</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2005/08/02/1754.aspx</link><pubDate>Tue, 02 Aug 2005 14:29:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2005/08/02/1754.aspx</guid><description>&lt;P&gt;If &lt;A href="http://www.technorati.com/weblog/2005/08/34.html"&gt;this trend&lt;/A&gt; continues, and the number of blogs doubles every five months, then within the next four years, every person on this planet will have a blog...&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/1754.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Jeffrey Sax</dc:creator><title>Where is the Built For .NET logo program?</title><link>http://blogs.extremeoptimization.com/jeffrey/archive/2005/07/06/818.aspx</link><pubDate>Wed, 06 Jul 2005 19:52:00 GMT</pubDate><guid>http://blogs.extremeoptimization.com/jeffrey/archive/2005/07/06/818.aspx</guid><description>&lt;P&gt;With the creation of the .NET platform, Microsoft has taken the potential for developer productivity to the next level. .NET is much more than a Virtual Machine environment with an extensive class library. It is a platform for efficient programming. Here at &lt;A href="http://www.extremeoptimization.com"&gt;Extreme Optimization&lt;/A&gt;, we have completely &lt;A href="http://www.extremeoptimization.com/mathematics/usability.aspx"&gt;embraced&lt;/A&gt; this side of the framework.&lt;/P&gt;
&lt;P&gt;Yet, as the &lt;A href="http://blogs.msdn.com/brada/archive/2005/07/06/435649.aspx#436042"&gt;comments&lt;/A&gt; to a recent &lt;A href="http://blogs.msdn.com/brada/archive/2005/07/06/435649.aspx"&gt;blog entry&lt;/A&gt; from Brad Adams show, not everyone cares like we do. (He rightly points out that compliance with the Design Guidelines should be a requirement.)&lt;/P&gt;
&lt;P&gt;What is surprising is that even some of the big names in component development, like &lt;A href="http://www.infragistics.com"&gt;Infragistics&lt;/A&gt; and &lt;A href="http://www.componentone.com"&gt;ComponentOne&lt;/A&gt;, get bad marks.&lt;/P&gt;
&lt;P&gt;Currently, Microsoft's &lt;A href="http://msdn.microsoft.com/vstudio/extend/vsipoverview/default.aspx"&gt;partnership programs&lt;/A&gt; for ISV's are based solely on what the ISV is prepared to pay for the co-marketing opportunities that come with them. There is no consideration whatsoever for the quality of the products.&lt;/P&gt;
&lt;P&gt;I believe it would be in the interest of Microsoft as well as the developer community as a whole to create some kind of &amp;#8220;Built for .NET&amp;#8221; logo program, with strong quality and guideline compliance requirements. This would encourage good design, and increase the effectiveness of developers across the board, giving the .NET platform a distinct advantage over its competition.&lt;/P&gt;
&lt;P&gt;Now, software design is somewhat subjective, and the design guidelines should not be taken as absolutes. &lt;A href="http://www.extremeoptimization.com/products.aspx"&gt;Our own libraries&lt;/A&gt; violate some of the guidelines, because some general assumptions simply don't work well for numerical software. However, a core set of design rules should be mandatory (for example: require enums instead of numerical codes), while a certain number of violations of less stringent requirements would be allowed. Alternatives should be provided for violations, and the violations themselves should be marked with the Obsolete attribute. Etc., etc.&lt;/P&gt;
&lt;P&gt;Just my 2 cents...&lt;/P&gt;&lt;img src ="http://blogs.extremeoptimization.com/jeffrey/aggbug/818.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>