January 2008 Blog Posts

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).

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 alphaCTP 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.

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.

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).

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 codeclimber.net.nz.

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.)

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.

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).

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...

RowTest

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.

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.

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).

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

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.

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:

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:

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):

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.

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, TransmissionxTorrent, 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.

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.