January 2009 Entries

What’s Wrong With This Code? (#21)

This version of WWWTC is dedicated to closures. We can use closures and functional programming in general to create elegant, succinct solutions, but sometimes we can also create subtle bugs.  Exhibit A. The C# developer who wrote this code expected DoSomething to be invoked with the values 0 through 9, but something is terribly wrong. for (int counter = 0; counter < 10; counter++) { ThreadPool.QueueUserWorkItem( state => DoSomething(counter) ); } What’s the problem? Bonus Round A JavaScript developer is working with the following markup.<div class="header"> <div class="detail">Detail...

The Software Cure For A Financial Meltdown

In my role as amateur financial analyst I like to read the publications taking an in depth look at the current financial turmoil. I then try to imagine the software tool that could have prevented the turmoil and saved the world millions billions trillions gazillions of dollars. This seems like no small feat for software considering the intricate world built by modern financial engineering - a world where terms like “collateralized debt obligation” are tossed around like dice at a craps table. However, I never imagined the answer could be so simple … First, some background. I find...

Routing and Rewriting

ASP.NET 3.5 includes a URL routing engine and IIS 7.0 can use a URL re-writing engine (x86) (x64). Routing and rewriting sound very similar, but so do robbing and rewarding – you can’t judge features using phonetics. Ruslan Yakushev wrote a great article on this very topic last year: “IIS URL Rewriting and ASP.NET routing”. Ruslan outlines the conceptual differences between the two URL hacking approaches as: URL rewriting is used to manipulate URL paths before the request is handled by the Web server. The URL-rewriting module does not know anything about what handler will eventually process the...

Astonishment Principles and Framework Behavior

The “Principle of Least Astonishment” (a.k.a the principle of least surprise (POLS)) is a guiding design principal for UIs, APIs, and interfaces of all types. Peter Seebach says: Throughout the history of engineering, one usability principle seems to me to have risen high above all others. It's called the Principle of Least Astonishment -- the assertion that the most usable system is the one that least often leaves users astonished. POLS plays a role in framework design, too. One framework behavior that I’ve always felt violated POLS was the ToString implementation of the System.Xml.XmlDocument class. XmlDocument document = CreateSomeXml(); string...

App Configuration and Databases

Jeffrey “Party With” Palermo recently posted on “Separating configuration from data lowers total cost of ownership”: My recommended progressions of configuration locations are as follows.  Specific requirements should be the driving factor that cause you to move configuration from one medium to the next costly alternative. In the code In a file In a database Some other system-specific external configuration store I wanted to call out option #3, which is to put configuration information in the database. Over the years, I’ve heard numerous proposals for putting configuration information in the database. Nearly every proposal has...

Dates and Times - Software's Bane

I’ve always been amused by date and time problems in software, and in my mind I often juxtapose “real” time against “software” time.  Real time inexorably marches forward, while software time can go forwards, backwards, left, right, and sometimes belly up. Inside this theater of my brain, real world time is played by a dead panning Steve Martin, while software’s interpretation of time is a buffoonish John Candy. You can’t help but laugh at the contrast – it’s a classic comedic recipe. Naturally, I chuckled when last week’s Zunicide turned out to be leap year related. I also giggled at...

A Message For You

This year’s silly, obfuscated, console mode C# program is brought to you by LINQ. using System.Linq; using Electricity = System.Collections.Generic.IEnumerable<char>; using here = System.Collections.Generic.Dictionary<int, char>; namespace Message{static class __{ static Electricity Transform(this here collection) { return new int[] { 16, 22, 28, 28, 7, 0, 20, 9, 11, 0, 7, 9,22,13,5 } .Select(i => collection[i]);} static void Main()...