First time here? You are looking at the most recent posts. You may also want to check out older archives or the tag cloud. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS. Thank you for visiting! (hide this)

January 2008 Blog Posts

Code smells also in SQL server system tables and StoredProcs

Almost 2 months ago Steve Harman, showed a ugly character map used in a database field to store the week's working days.

Today I came across something similar, or maybe even worse, since the super-smelly database field is used in some system SPs in SQL Server 2000.

I found a few examples of inconsistencies and "strange" implementations but let's focus on just one system stored proc: sp_help_job.

This SP is used to retrieve a list of jobs or, if called specifying a GUID, it returns 3 result sets with the steps and schedules of a single job.

Let's see some examples:

enabled, which can be only 0 or 1 in the list of jobs is returned as tinyint, while in the list of steps and schedules is returned as int.

notify_level_****, which accepts values from 0 to 3, is an int in the result set with the detail of a job, but a similar field in the result set with the list of steps, named on_success_action, is a nvarchar(4000). Why a string 4000 chars long for a value that can range from 1 to 4? Because the actual value returned by the SP is the value followed by the meaning: "1 (quit with success)". This is cool if the SP is run by a DBA that read the screen, but not if the results are read by a software. And also, why 4000 chars? And there are other fields using this mixed value + description approach.

And let's see one last example: if you want to return the start date of a scheduled task what datatype will you return? A datetime as you use when you pass the start date into the sp_add_job? No... that would be too easy. A string representation of the date, like 20070131, so a nvarchar(8)? Here you are getting closer to the result. The SP returns a value that is written 20070131, but it's read 20 millions, 70 thousands and one hundred 31, so it's an int. And the same applies to the start time and end date/time, but not with the creation date, which is a real datetime.

Once you know and once you find out all the details it's not complicate to deal with all that strangeness, but these are the weirdest approaches I've seen in life.

Here is an online version of the SQL Book with the description of the sp_help_job stored procedure. It's for SQL Server 7, but the sp is the same in SQL Server 2000 (and hopefully 2005).

ASP.NET MVC Link collection

Together with playing around with Silverlight, lately I started to have a look at the MVC framework that the ASP.NET released as part of ASP.NET 3.5 extensions. Here is a list of some of the best links I found on the topic:

Probably I might have missed some other interesting posts, but these are more than enough to get you started on the topic.

UPDATE: I added some other links, thanks to Simone Busoli for reminding me that Internet is not text-only any more.

kick it on

Technorati Tag: ,

Italian Silverlight Competition: no go

As I said last week, Daniela and I were developing a small application to take part in the Italian and INETA EU Silverlight competition.

This morning I tried to upload the ugly proof of concept we came out with, but it was not possible to upload projects any more (probably I misunderstood and the final date was Jan 28th in the morning, and not at midnight). Too bad since I checked yesterday and there was no other application submitted to the contest (actually one, but without the application).

But, this post is not about me not being able to take part into the competition - which is not a big issue since the application is still ugly at the moment and not competitive - : the real problem is that NO application were submitted to the Italian Competition (and looking at the sites of other countries I counted at most 10 applications submitted in the whole European competition). What does this mean?

I don't think it means there is lack of interest in the technology itself, probably just the wrong time for this kind of competition:

  • it's still in alpha CTP version, and in a bit more than one month there will be a new beta version that will have a lot a changes and will include a lot of enhancements: probably lot of people thought it was a useless loss of time trying to fight with all the problems of a CTP when in 2 months they will be able to do the same things (like using a real textbox) without tons of work-arounds.
  • the competition has been announced at the end of November and the final submission date was the end of January: less than 2 months, during an usually hectic period of the year (with the Christmas in the middle). Probably not many people had time to experiment with it and come out with a decent application in that little time. (To prove this point, the Spanish competition, that started in August, is the one with the highest number of submissions)
  • a Silverlight application must be well crafted but also must look good: not many developers are good at drawing nice UIs, and the designer world is not interested in this new UI technology yet. Was there any point in submitting the best application with the best algorithm ever but that looked as ugly as death?

I hope there will be another competition once the Silverlight 2.0 will be released after the MIX.

Anyway, regardless of any competition, we will release the Silverlight control we are developing as soon as it's ready for public usage.

kick it on

Sharing some Silverlight's bits: how to make a dashed line

In the last weeks I started playing around a bit with Silverlight in order to build something decent of the Italian Silverlight competition, so I decided to start sharing something of the things I found out while doing it.

The first one is about drawing dashed lines.

Here is how to do it in code:

Line line = new Line();
line.StrokeThickness = 1;
double[] dashArray = new double[2];
dashArray[0] = 2;
dashArray[1] = 4;
line.StrokeDashArray = dashArray;

All you need is to define an array of double, size 2, and set the length of the dash as first element and the spacing between to dashes as second element of the array.

Both values are specific to the thickness of the line being drawn, so {1,1} will draw a dotted line (actually a dashed lines with square dashes).

And you want to draw more complex dashed lines, for example like the ones used in technical drawings, you can add to the array other couples of doubles, and draw dash-dot sequences: every even values is the length of dashes, odd values specifies gaps.

I'll try to post some more bits in the next weeks (even if the competition deadline is in 3 days, I'll go on developing the control Daniela and I are building).

Technorati Tag: ,

On the press

On today's online edition of The Globe And Mail, a Canadian national newspaper, in their selection of "RECOMMENDED LINKS: BETTER I.T. IN 10 CLICKS OR LESS", they included also my post about the 18 applications for Mac.

Make Macs useful

Last week's Macworld Conference & Expo showcased a lot of new Apple products, including its superlight and thin MacBook Air laptop computer. In most companies, however, IT departments stick to Windows-based machines, but Simone Chiaretta may be able to change that.

MsMr. Chiaretta, an Italian .Net developer, recently published "18 (almost) free applications" for the Mac, which includes text editors, FTP software, spreadsheets and a lot more. Browse the entire list, with links to the applications, at

Thank you to Shane Schick for including my post into his selection, even if mistakenly believed Simone was a female name. (I edited my quote correcting the original Ms. to Mr.)

Technorati Tag: ,

Working Draft of HTML 5 released

As you might have already read somewhere else, the W3C published the first working draft of the specs of the next version of HTML, version 5.

The specs are quite long and I'm starting to have a glance at them, so for the moment I'll just publish some links while I'll write the first impressions as I finish reading them.

Some of the most interesting new features for authors are APIs for drawing two-dimensional graphics, embedding and controlling audio and video content, maintaining persistent client-side data storage, and for enabling users to edit documents and parts of documents interactively. Other features make it easier to represent familiar page elements, including <section> <footer>; <nav> (for navigation), and <figure> (for assigning a caption to a photo or other embedded content). Authors write HTML 5 using either a "classic" HTML syntax or an XML syntax, according to application demands.

The HTML 5 specification helps to improve interoperability and reduce software costs by giving precise rules not only about how to handle all correct HTML documents but also how to recover from errors.

Technorati Tag: ,

The Ballad of the Programmer

I just found a modified version of a famous song by Francesco De André called "Il Pescatore".

The name of this remake is: The Ballad of the Programmer and it's about a poor programmer dealing with a client that wants "everything by yesterday, wants absurd features and wants to pay as little a possible" (pretty standard behavior for small and medium sized software companies in Italy), so he has to work day and night without eating and dreaming of a tropical beach (also standard dream of every developer working in the grey and foggy Milano).

The lyrics are in Italian but here is the translation made by Google Translation.

And here you can listen to the MP3.

[via M.kino]

Minority Report-like interaction in WPF

Microsoft Surface and Jeff Han's multi-touch UI seem to be ages behind if compared to Project Maestro, developed by Cynergy, a RIA development company based in Washington, DC.

What Project Maestro is?:It's a prototype of a no-touch interface, developed with WPF, XAML and using the WII remote with some custom-built IR gloves. And they say they built it in 8 days.

Here is the video of how it works:

If you want to do it yourself, here are some pointers to get you started: Connecting the Wii Control to WPF and the Wiimote project.

Seems like we are not far from revolutionizing the way we interact with computers: how long before we connect directly to the user's mind?

kick it on

18 (almost) free applications on my Mac

A bit more than 2 weeks passed since my post with some considerations on the Mac applications available and I had a bit more time experimenting and reading some advices from other and I think I almost decided my toolbox of must-have applications, so here I'm sharing my list of apps Read More... closed a few days ago

Do you remember the scandal behind the release of, the website developed by IBM for 45.000.000 euro to promote the tourism in Italy?

Well, a few days ago the site has been closed as the vicepremier Francesco Rutelli said back in October. And still no answers to the questions of transparency.

How to simulate RowTest with MS Test

One of the best feature that is in mbUnit since 2004 is RowTest, which is the ability to perform the same test using different input data and expected results.


public void SumTest(int a1, int a2, int result)
    Assert.AreEqual(a1 + a2, result);

The cool thing is that each "row" is treated as a different test, and if the test fails for one set of data, the others might not. And this helps pinpointing the data that are making the test to fail.

This week I was adding some unit tests to a project that is managed by TFS, so I decided to use the "core" unit testing framework available with VS2008, and unfortunately it doesn't support RowTests. But it has a similar feature called Data-Driven Unit Test. With this approach it's a bit more complicate to implement the "simple" RowTest scenario, but it allows also to implement more complicate ones.

Let's have a look at how to simulate a RowTest using the Data-Driven approach of MS Test.

Data-Driven Test

A Data-Driven test is a test that is performed once for each of the rows in the datatable configured as source for the test.

This is just the same as RowTest in mbUnit but with a different source for the parameters to use: instead of specifying the parameters as attributes of the test method, you have to write them inside one of the three types of DataSources that are supported by the MS Test framework:

  • CSV text file
  • XML file
  • any DataBase that have a provider for .NET

For this example I'll use a XML file, but in case of more complicate scenarios you might want to use a Database.

The XML file


This it the XML file with one "row" for each set of data that I want the test to run on. Notice that the last row will cause the test to fail (1-1=0, not 1)

Unit Test

First you have to create a normal unit test (either authoring it manually or generating with VS) and then for each test which you want to use the RowTest-like approach for, you have to write a small caller method that read the parameters from the datasource and calls the real test method.

public void SumTest()
    int a1 = Int32.Parse((string)TestContext.DataRow["A1"]);
    int a2 = Int32.Parse((string)TestContext.DataRow["A2"]);
    int result = Int32.Parse((string)TestContext.DataRow["Result"]);
    ExecSumTest(a1, a2, result);

private static void ExecSumTest(int a1, int a2, int result)
    Assert.AreEqual(a1 + a2, result);

As you see, there are two methods: the second one is the "real" test method, while the first one is there only to read from the datasource and call the real method.

The wrapper method is decorated with 3 attributes:

  • TestMethods that tells the test runner that this method must be called during the test run
  • DeploymentItem that tells the test runner which files it has to deploy for the test to run (replace ProjectName with the real name of your project)
  • DataSource which configures the type of datasource, the connection string, the table name and whether execute the test following the order of the data, or randomly

Then it reads from the DataRow the parameters needed, casts them to the right type (here passing through a string since the XML file returns only strings), and finally calls the real method.

If you want you can select the DataSource to use also in the configuration file of the test or using the wizard available in the property window of the Test List Editor.

Test Results

Unfortunately, when run this way, you see only one line in the Test Results pane, but each row is accounted separately (in the image below, 2 out of 4 failed since it counts one test per row plus the group of all rows)


But if you click on the line with the test, you go to the details view, that tells you exactly which row made the test fail.


And here you see that row line 3 failed (the test fails since 1-1=0 not 1)

Wrapping up

The RowTest approach can be achieved also with MS Test and, even it's more complicate than with mbUnit for simple scenarios, it allows an higher degree of flexibility since it allows the tester to change the set of test parameters without the need to recompile the test.

First ALT.NET (mini)conference in Italy


At the end of October the was born in Italy (where UGI stands for User Group Italiano).

Now we are organizing our first conference, on February 23th, in Brescia.

In the title I say "mini" because the place in which we decided to gather is not very big, only around 10-15 people can fit into the conference room of ABSistemi. But I'm pretty sure we will end with a lot of great discussion on "good ways" of building software and for sure we will have a lot of fun watching at the CI traffic light they built (using a real temporary traffic light).

kick it on

Technorati tags:

Sun buys MySQL

This is fresh news, Sun just bought MySQL. Here is the the official press release: Sun Microsystems Announces Agreement to Acquire MySQL, Developer of the World's Most Popular Open Source Database

Kay Arnö, responsible of the community behind MySQL, writes about what this means for the opensource community, both developers and users: Sun acquires MySQL

Sun has a proven track record of supporting OpenSource as whole, so I guess this will help (if it ever needed) an even better development of MySQL DB engine.

Congratulations MySQL!!

Technorati Tag: ,

Buy 11 cool Mac apps for just $49

If you are like me and you followed the live coverage of the MacWorld 08 keynote you might have already seen it, but if you missed the live announcement of the MacBook Air, there is a nice offer going on at MacHeist: they are selling a bundle of 11 Mac apps, priced $368,75, for just $49.

Among the many apps, I want to highlight the one I'm interested in:

  • 1password. a password storage app integrated with all the browsers available on the Mac
  • CoverSutra: a iTunes controller
  • AppZapper: uninstaller for the Mac. Makes sure all the files associated with an app are removed when you remove the app
  • CSSEdit: the app that won the Apple Design Award as Best Developer Tool in 2007. A powerful CSS editor
  • Snapz Pro X: screen capture, both still and video
  • Pixelmator: a image editor, similar to Paint.NET on Windows

With all these apps I (almost) completed my list of applications for my Mac. But if you want to take advantage of this promotion you have to harry up, since it lasts only for other 8 days (January 23th). The promotion is no over.

Something I forgot to mention: 25% of each bundle will be given for charity.

UPDATE: as of January 20th, still 3 days to go, and the number of free apps raised to 14 (2 new games and one vector graphic software)

UPDATE: the offer had ended, hope there will be another one next year

Doing something creative

I've always been attracted by wine, especially by the kind of magic that is behind his production. By how a small change in the weather, a small change in how the vines are handled, small changes in the composition of the ground can lead to totally different wines.

A few years ago I also started an OpenSource project to help vineyards and winemakers to better track these small changes and collect data to help them make better wine, I even collect a lot on information and gathered requirements, but unfortunately I had to stop working on it.

And yesterday, to try and understand the "magics" behind the wine, I started attending a course to become a sommelier. Of course I'm not thinking of becoming a professional sommelier, but just in case I want to change career, being a cook or working with wine is my next choice.

My favorite wine? Pinot Noir, better if from Sud Tirol or Otago.

PS: Picture on top by Eric Strauss on Flickr.

Sir Edmund Hillary died today

Hillary.jpgIt's a sad news for all Kiwis and mountain climber worldwide: today Sir Edmund Hillary, the first man to climb Mt. Everest, died today at the age of 88.

All the words of the World will not be enough to say something about this great man, that 55 years ago achieved a result that is still only a dream for many other men now: just that he will be missed

To know more about this great mountaineer, explorer and philanthropist you can have a look at his article on wikipedia: Edmund Hillary.


Migrating from Outlook to Mail on the Mac (from a non en-US PC)

One of thing I'm doing these days is to try and keep all the 35.000 email I received and sent in the last 10 years. So I looked at how to move the contents of my pst files to the standard mbox mail format.

Looking on the web I found a quite interesting explanation on the Microsoft KnowledgeBase:

ENT2001: How to Use IMAP to Move Messages Between a PC and a Macintosh in Entourage, Outlook, or Outlook Express

What the KB article says is that you just have to create an account on an IMAP mail server, configure both clients to get emails from the IMAP account. Then copy all your email from Outlook to the IMAP server and then back to Mail on the Mac.

Seems to be good if you have access to an IMAP server and you don't have 3GB of pst file to move. A solution for both problem could be to setup an IMAP server on your local network: no need for a real IMAP server, and transferring 3GB over the local network should be way faster than doing it over the internet.

But the "Move to Mac" tutorial on the Apple site provided also the link to small software called Outlook2Mac that can do the migration without the need of setting up a IMAP account.

Technically speaking it connects to the mail storage of Outlook, cycles through all folders and email, and dumps each folder into a file formatted following the mbox specifications. And it also exports contacts and calendars appointments.

Yesterday I let the tool run all the night and this morning I had my 3GB pst file converted to a bunch of mbox files, this evening I tried to import them but all the emails had the wrong date, and many were recognized as today's emails: quite hidden in the FAQ of the product I found this "answer":

Mail shows the wrong date for imported emails:
It may be your email has non-US date formats to begin with. If this is the case, you may want to change your date settings on both your Windows and Macintosh machines to US/English before performing your conversion and importing operations.

O2M converts US/English dates to the standard MBOX format. If the date in the header is formatted differently from the US/English version of Outlook, the dates may not convert well. We don't currently support date formats other than US/English.

Unfortunately changing the locale on the Mac didn't work, so I tried changing the locale on my PC, export all the mailboxes again and then try the import: an this time it worked.

So, wrapping up, if you want to export all your email from Outlook (not Express, but only the one that comes with Office) to any mbox based mail client like Mail on the Mac, and you don't have an en-US locale here are the steps:

  1. Buy Outlook2Mac (it costs only 10 USD)
  2. Set the locale on the originating PC to en-US
  3. Run O2M selecting all the folders you want to export
  4. Move the generated folders on your Mac
  5. from Mail, "Import Mailboxes", select "mbox files" and select the files you copied from the PC

2007 year's book and Top 5 post

Already 10 days are gone in 2008 and I just realized I didn't have time to write a post looking back at what happened during last year:

Quite a busy year, isn't it?

How is going 2008 to be? Hopefully I'll not change 2 jobs in less than one year as I did in 2007.

And now let's talk about this blog. I posted quite a detailed overview of my first year of blogging last month, so I'm just going to re-apply Ayende's formula to calculate the most popular posts of 2007.

Title V A C Popularity P/Age
How to make a Gmail-like loading indicator with ASP.NET Ajax 17519 718 33 271120 1139
How to refresh an UpdatePanel from javascript 9188 830 15 146645 740
Ajax TreeView 6883 789 12 111555 569
.NET Ajax Survey results 6259 500 9 99200 4960
Vista Gadget for CruiseControl.NET - CC.NET Monitor for Vista Sidebar 0.5 4502 549 11 73405 273

I also added to the formula an indicator of popularity/age of post, and as you can see, using this last counter, the winner is the post with the results of the survey about the usage of Ajax among .NET developers (also thanks to the link in CodeProject Insider newsletter which brought to the post around 3500 visitors in 2 days).

I wish you all a wonderful 08.

Technorati tags: , ,

How to query a XPath doc that has a default namespace

I just spent a few hours banging my head against a XPath query that didn't return the node I was trying to select using the right xpath string: to make a long story short, if your XML document has a default namespace without any prefix, to make XPath queries on it you have to use a NamespageManager, add the default namespace with a fake prefix, and then query the document specifying the namespace manager in the SelectNodes method.

But let's explain a bit more in detail. Imagine you want to make a XPath query on a VisualStudio project (the following is just a part of a real csproj file):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="2.0" DefaultTargets="Build"
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="Microsoft.Practices.EnterpriseLibrary.Common">
    <Reference Include="Microsoft.Practices.EnterpriseLibrary.Data">

If the xml document didn't have the default namespace


we could have queried the document to select the node with the reference for the Enterprise Library Data dll with the following XPath query string:

XmlNode entlibDataNode = doc.SelectSingleNode(

But unfortunately our xml document has a default namespace, so this query doesn't work: in order to make it work we need to instruct the XPath query engine to use the default namespace as follows:

XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);

The code above creates a XmlNamespaceManager and then add the document namespace with the fictitious prefix "a".

Once the XmlNamespaceManager has been set up we can go and query the document, but this time adding "a:" prefix before every node name:

XmlNode entlibDataNode = doc.SelectSingleNode(

I also noticed that this approach is probably used also by the XML Notepad 2007. If you open a VisualStudio project file with the XML Notepad and open the Find dialog selecting "Use XPath", and then you select a node of the XML, in the search string you will notice that it generates the XPath string using the prefix "a" before every node name.


Not sure if it's a bug or a feature, but this way it works. Hope this will save a bit of your time.

kick it on

Technorati Tag: ,,

A funny picture from my camera blogged with Ecto

Here is a funny picture I just took off my digital camera: all my ice climbing tools, hanging drying with my clothes


This is also a test of Ecto 3 beta: after my post of yesterday about my thoughts on the applications available on the Mac, I exchanged a few emails with Adriaan Tijsseling, the developer of Ecto, and he was very nice, and immediately released a new build (b20) that fixed the problem with the categories not being downloaded (actually it was a problem in Subtext MetaWeblog API implementation, that is missing the method blogger.getUserInfo). He also pointed me to how to do the tasks I was used to do with WLW in Ecto. And we are also working to have Ecto support Subtext out-of-the-box, not as a "Other" blogging platform.

I guess I decided which blogging application to use on the Mac.

Technorati tags: , , ,

Random thoughts after one week of Mac

It's now a week since I started using my Mac and I wanted to share some random thoughts:

  • The MacBook trackpad... WOW... it's the way trackpad should be: if configured correctly you can right-click, left-click, double-click, drag&drop and scroll (both horizontally and vertically) using only the touch surface, no need to use the only button: the most usable trackpad I ever used
  • I'm trying to use for all my day to day tasks (reading email, browsing, chatting, blogging, reading feeds, editing HTML and text, and so on) native Mac applications, so I've not installed Vista yet. I'd like to use Windows only to run Visual Studio.
  • All the best applications for Mac are commercial ones: TextMate, Transmission xTorrent, Transmit, Ecto, MarsEdit, NetNewsWire, costs all something between 20$ and 50$. Not a lot of money but using Windows I never had to pay to get a text editor (Notepad++ or other dozens of free/oss text editor), a BitTorrent client (uTorrent), a FTP client (SmartFTP), a blogging software (WLW), or a RSS Reader (RSSBandit). I know there are other applications that do the same and are free, but not as good as those ones.
  • Aot many opensource apps for Mac: probably this comes from the fact that people that used a Mac are more willing to pay for supported and commercial applications and less likely to try and spend time trying to figure out how to make an OpenSource app works.
  • The only two blogging applications for OS X (Ecto and MarsEdit) both suck: Ecto 2 is very limited in the tags you can enter, removes the tags he doesn't like (even the ones you add in the HTML view), Ecto 3 beta requires some strange methods to be implemented in the MetaBlogAPI (blogger.getUserInfo or something similar) so the "add blog" operation partially fails and it doesn't retrieve the blog categories, so useless. MarsEdit is not WYSIWYG and doesn't support tags. So, since I've not installed Fusion/Parallels with Vista yet, I think I'll go with TextMate even if it cannot be automated like WLW and is not WYSIWYG, but at least I've full control of the HTML and TextMate is one of the best text editor I've ever used.
  • I tried using Adium as IM client, but it doesn't support Skype, and I never really like multi-protocol clients, so I'm using MSN Messenger, iChat for Gtalk and Skype. Too bad since the icon of this app is awesome
  • iPhoto is just great: you put a card in, it detects the insertion, asks you if you want to import the pics, and automatically creates an event for the pics.

All those thoughts led to a consideration: a OS is as good as the applications that run on it. And the more the apps, the higher, the probability that there is a great app for your needs. This is true for Windows, but a little bit less true for OS X: probably because there are less developers willing to develop on the Mac, and I guess it's because of the horrible Objective-C needed to develop native Mac Apps.

What guys do you think?

kick it on

Technorati tags: ,

Tips for switching from Win to a Mac

If you are like me and just bought a Mac coming from ages of Windows you might be having an hard time loosing all your habits and learning to walk again.

Today I found a reference to a post of one year ago that compared how the easy things are done on a Mac and on a PC: things like what the "Apple" key is used for, why when you click on the "X" in the application bar the window is not closed but only "hidden", why there is no "Delete" key, how to install an app, and so on.

I still have to understand how to emulate the "home" or "end" keys on my MacBook keyboard tho.

Here is the nice post: Hack Attack: A guide for switching to a Mac.

Technorati tags: ,