June 2006 - Posts

Follow the Germany World Cup with Microsoft Scoreboard

Earlier today, Microsoft launched (JIT-style) Microsoft Scoreboard. I have this vague idea that, from tomorrow on, many Ecuadorean software developers screens will look like this:

You can download Microsoft Scoreboard from here, it's free.

¡Fuerza Ecuador!

Posted by Edgar Sánchez with 5 comment(s)
Filed under:

Friendly Web sites, design patterns, and metacognition

First of all, you just have to love the guys that created these register policies:

Isn't that all what you expect from a Web community member? Who needs lawyers anyway? Before you start laughing, note that JavaRanch gets millions of entries in its forums every month and they have won a Jolt Productivity Award on the Web Site and Developer Networks category twice in a row. When you know that, you are not surprised that these same guys created the Head First book series, of which I started to read Head First Design Patterns today, a book where, for example, the possibilities of the decorator pattern are illustrated in this way:

Does that chap looks like an object decorator or what? Wink [;)] The authors use in funny ways the results of metacognitive research (that is, the research on how people learn), so you will laugh while you learn. Now, the authors write all of their examples in Java (nothing is perfect Stick out tongue [:P]), but luckily a good soul already translated the samples to .NET Cool [H]. Recommended reading.

Datasets are not for everything (and neither XML)

First of all, let me tell you that datasets are wonderful, especially if you have to do CRUD operations on relational records. But that doesn't mean they are always the best choice. Ditto for XML. With the obvious statement out of the way, let me tell you this little tale:

My pal Sandra needed to execute a process except for a group of operations, moreover, this group of "forbidden" operations could be changed at runtime. So, to begin with, Sandra defined an XML file with the forbidden operations:

<ForbiddenOperations>

  <Operation>Destroy</Operation>

  <Operation>Kill</Operation>

  <Operation>Maime</Operation>

</ForbiddenOperations>

Then, she populated a dataset with the contents of the XML file:

DataSet dataSet = new DataSet();

dataSet.ReadXml(@"..\..\ForbiddenOperations.xml");

And now, she could execute the process, except for forbidden operations, like so:

DataTable operationsTable = dataSet.Tables[0];

DataRow[] foundRows = operationsTable.Select("Operation_Text='" + operation + "'");

if (foundRows.Length == 0)

{

  // It isn't a forbidden operation, so do the process

}

It works, and it uses just a few lines of code. OTOH, it's terribly inefficient. To begin with, reading an XML file to populate a dataset demands a lot of resources and the file becomes a semaphore. Furthermore, the Select() method scans the table linearly, interpreting the expression for every row. If the table has many rows or the process is invoked many times, the response time will suffer noticeably.

Which is the alternative? First, let's put the forbidden operations in the App.config file:

<appSettings>

  <add key="forbiddenOperations" value="Destroy,Kill,Maime"></add>

</appSettings>

Then, populate a string dictionary with those operations:

string[] forbiddenOperations = ConfigurationSettings.AppSettings["forbiddenOperations"].Split(',');

StringDictionary forbiddenOperationsDictionary = new StringDictionary();

foreach (string operation in forbiddenOperations)

{

  forbiddenOperationsDictionary.Add(operation, operation);

}

And finally, you can execute the process, except for forbidden operations, like so:

if (!forbiddenOperationsDictionary.ContainsKey(operation))

{

  // It isn't a forbidden operation, so do the process

}

The first and last parts are more compact than in the first solution, even though the second part takes more lines. But the whole process is far more efficient and fast.

So, even though datasets are great, don't use them for everything, in particular don't use them as a dictionary or a cache, if you want to find objects or records by a certain key it's far better to use a dictionary. Ditto, for XML.

Posted by Edgar Sánchez with no comments
Filed under: ,

C# Expression Evaluators

Warning: this is not the usual code sample ready to be cut and pasted in your homework due for tomorrow.

OTOH, if you are one of those guys that just have to understand why and how you can implement an expression evaluator in C#, then boy has Chuck Jazdzewski some interesting information for you. Chuck likes to propose interesting problems/challenges (often useless yet fascinating) and then discuss at detail various approaches to the problem, in the case of expression evaluators, Chuck offers us four alternatives:

  1. The classic procedural solution (á la plain old Visual Basic)
  2. The object oriented solution (at the best 199x Smalltalk/Java style)
  3. The visitor pattern solution (for the guys one stair above average Java or C# programmers)
  4. The layered solution using partial classes (for the neoteric programmers using C# 2.0 or VB.NET 2005)

As I said, don't expect a complete solution ready to be run but some pseudo-code and an interesting discussion of pros and cons. It may not help you with tomorrow's homework but it sure will help you impress the geek gal on the next cubicle.

The Art of Project Management

Today I'm going to make an obvious point: the stars in a software project are the programmers (well, the architects a little bit too [;)]) no doubt about it. But the scenario is not unlike that of a music concert: the stars are the singers and musicians for sure but in order for the concert to be a success you require of far more people in many different fields, some of them totally unrelated to music.

In order for a software project to be a success you require users, domain experts, IT people, testers, etc. And above all, you require project managers, this is a job hated poorly understood by programmers: a manager is a pointy haired boss utterly clueless about the fine art of programming.

As I said, the stars are the programmers, but just as a concert produced by musicians is doomed to be a failure, a software project made only by programmers will be a nightmare. To avoid such chaos, to have everything ready for the programmers to write their masterpiece and let the users ecstatic, we need a great project manager.

So what is it that a project manager is supposed to do? The answer is neither short nor simple, so it's great when a witty and candid book on the subject appears: The Art of Project Management, written by Scott Berkun, which got a Jolt Productivity Award in the Books General category. A recommended reading, for programmers and managers alike.

Programmer fonts, do they matter?

May be I pay attention to silly things, but some fonts are easier to read than others and if you keep writing or reading code during hours and hours, the font that you use may very well affect your productivity (just a theory Geeked [8-|], besides, far more ridiculous stuff has made it's way in the Internet). Anyways, this is a code section with the standard Visual Studio font (Courier New Size 10):

The Consolas font was created for Windows Vista but you can download and install it for Visual Studio 2005, at size 10 it looks like this:

Note how more code fits in the same region and, IMHO, it's somewhat more readable. Finally, the Anonymous font was born in the Mac but you can download it free for Windows. The same code section in a smaller size (9 point) looks like this:

Before Consolas debut, Anonymous was the one that I used. There are many fonts for programmers available (free, expensive, nice, silly, ...) What do you think? What font do you prefer for code? Does it even matter?

More Posts « Previous page