Camel casing private members is a violation of the DRY principal.

I have been having an interesting discussion with my boss regarding this element of our coding convention (I'm for dropping it). Can anyone give any me some concrete advantages of the practice?

daenet is hosting CommunityServer 2.0!

My company's blog server just came online today. daenet is hosting the brand new version of CommunityServer and it looks like the guys at Telligent have really done some good work. I have not yet decided how I am going to organise my blogging but for the time being I think that I will blog in parallel. This means that you might want to check out my www.developers.de blog to make sure you catch all of my posts. My most recent post provides some information on why you are wasting your time when you initialize your variables with default values.

A 'Folder Size' column for Windows Explorer.

As impressed as I was with FolderSizes. I have found that Folder Sizes for Windows is much less intrusive, solves the same problem, and is free! Now when I find that my hard drive has been filled by the Visual Studio testing framework, all I need is to open Windows Explorer to solve the problem!

The semantic difference between 'throw ex' and 'throw'.

I was not aware that there was any semantic difference between 'throw ex' and 'throw' until I heard it on The Polymorphic Podcast. Craig explained that with the first variant, the stack trace of the exception will be lost. The second version preserves this valuable debugging resource!

The Polymorphic Podcast right here on DotNetJunkies!

I just listened to the latest episode of one of my favourite podcasts - The Polymorphic Podcast - and was pleasantly surprised to hear that Craig has started blogging right here on DotNetJunkies! I can highly recommend his podcast and it looks like he is off to a great start with his blog too. Thanks for all the work you put in Craig.

Hard drive fed up with testing in Visual Studio 2005?

I have noticed that my hard drive is slowly filling up since I have been using Visual Studio 2005. The culprit? The testing framework which takes a copy of binaries that are required to run the tests. The following folder contained 3.74 GB of the stuff!

I found it using FolderSizes within a couple of minutes of installing an evaluation copy. It is one really well designed piece of software.

Null Object is a special case... but of what?

I just read a comment that dfaceved left on my The Null Object Design Pattern post which got me thinking a little deeper about the pattern itself. He asked if I would implement the pattern in cases where the data model did not allow for nulls to exist. My answer is yes if we use a generic version of the pattern. The example that first came to mind - I will get to that shortly - was based on something in one of the links I included in my Null Object post. In a nutshell the author was saying that Null Object is a special case of either State or Strategy. Basically, 'Null' could be thought of as single State/Strategy in a in a continuum of other State/Strategies. On rereading these patterns, I am not sure that I agree.

Strategy is an 'encapsulated algorithm' while State allows an object to appear as if it has 'changed its class'. A common theme here is that the State/Strategy is encapsulated by a context object and not directly exposed to client code. This is in stark contrast to Null Objects which are designed to be used directly by client code. Could there in fact be another design pattern which is a super set of the Null Object design pattern waiting to be discovered?

No, it looks like Exceptional Value fits the bill even though it is a little light on for details. I would be interested to see if anyone has seen a full 'Gang of Four format' version of this pattern...

Anyway, onto my example of using Null Object(Exceptional Value) where the data model does not allow for null values. Lets assume that an Employee table has a self referencing foreign key relationship - the MangerId field holds a reference to another Employee record. Also assume that the ManagerId field does not allow Null values. In this case, a NullEmployee will never be returned from the Manager property of an Employee object. There is no reason here to implement a NullEmployee other than in anticipation of future changes to the data model.

When we consider that Null Object is a special case of Exceptional Value the fact that Null Object does not apply does not mean that Exceptional Value can not add some value. Lets further assume that a standard user can access their own employee record and those of any employees that they manage. With this setup, sooner or later, a user will attempt to access data for which they are not authorised by using the Manager property. In this case, a NotAuthorisedEmployee object could be returned. Just as the NullEmployee object would provide behaviour for the case where a record does not exist, the NotAuthorisedEmployee would provide behaviour for the case in which the user is not authorised to view the record.

The Null Object Design Pattern

Since I first read Martin Fowler's book - Refactoring: Improving the Design of Existing Code - I have been a big fan of the Introduce Null Object refactoring. It is an elegant solution for a problem that - to be honest - I didn't really know I had. One of the symptoms is code that checks whether a variable is null and provides some default behaviour in this case. Once you use the same default behaviour in more than a couple of locations, your code would be better off with the Null Object Design Pattern.

If you liked the catalogue style used by the Gang of Four, in Design Patterns: Elements of Reusable Object-Oriented Software then check this out. I recently came across a situation though which should hammer home the benefits for anyone who has played around with databinding in ASP.Net 2.0.

In ASP.Net 2.0, you are able to use binding expressions that navigate the object model in which your data source finds itself. Say for example, that I am databinding to a collection of Customer objects. The Customer class defines an Address property which returns an Address object. For convenience, the ToString() method of this class returns a one line version of the complete address such as the following.

One Microsoft Way, Redmond, WA 98052, USA

I could then use a binding expression such as the following to display my customers' addresses in a data bound control.

Eval("Address.ToString()")

This works great until a customer that does not have an address turns up in my list. In this case data binding would fail because it would attempt to evaluate the ToString() function of a null reference. A solution incorporating the Null Object design pattern would involve modifying the Address property on the Customer class to return a 'Null Address' for customers that do not have an address. The 'Null Address' would support the same interface as a real Address object and would implement the ToString() method to return a string such as "Not Available".

The result would be a list of addresses with some "Not Available"s sprinkeled amungst them. From this point forward, you can throw away any checks that you make to see if a Customer object's Address property is null. Your client code can just assume that it will receive a valid Address object. Try it out for yourself. Don't be surprised when, the report you write that normally would have choked on a missing address gracefully displays a "Not Available".

Didn't make it to the PDC? Don't miss the presentations...

You can view the presentations and download the powerpoints here.

Team Foundation Server Web Casts

We are going through the process of installing Team Foundation Server. I have found some of the following web casts to be very useful for getting my head around the whole thing...

http://www.microsoft.com/events/series/msdnvsts2005.mspx

Community Server Trackback Experiment Results

I just finished an experiment to test the Trackback feature of Community Server. Here are the results of this experiment.

Excerpt: This text is used as the body of the comment that results from a trackback. Leaving the Excerpt  field empty results in the first hundred characters or so of the post being used.

Name: This doesn't seem to play any role in trackbacks. It is used in the URL for the post.

I noticed that although a valid link to my original post shows up as a comment on the post that I trackback to, the link text is Anonymous. Does anyone know how I can get the link text to display my name for example?

Community Server Trackback Experiment

I conducted an experiment a little while back when DotNetJunkies were still running .Text. Since then they have installed Community Server and I noticed that a couple of links stopped working after the migration. So here goes with my second trackback experiment.

Excerpt: 'My Trackback Experiment - This is my excerpt.'

Name: 'MyTrackbackExperiment'

I have the link above to my old experiment (an old post in this blog) and I will link to Tarik to initiate an external trackback (external to this blog at least - he is also on DotNetJunkies). I noticed that a previous trackback to one of his posts showed up as anonymous. Hopefully that will not be the case this time...

DotNetJunkies community still reeling from comment spam.

I just noticed that the comment spam that we were getting with .Text seems to have put at least a temporary damper on my workmate Tarik's blogging career. He turned off comments and has not posted since April. I will be giving a presentation on rss related topics at our next employee meeting which will hopefully inspire him to start blogging again!

I have an ulterior motive for this post which is to set up some trackbacks for the presentation.

Link for Microsoft's Atlas Web Site

There has been a whole lot written about Microsoft's Atlas project which will make Ajax style programming easier. I would suggest visiting the project site for the most current details.

The appSettings file attribute and the 'Root element is missing.' SystemConfigurationException.

The documentation had me on a wild goose chase here.

I am using the feature of App.config files that allows you to specify appSettings elements in a file other than the App.config file itself. This is achieved with the file attribute of the appSettings element. You are supposed to provide a relative path there to the file containing your appSettings elements and they will be merged with any that are in your App.config file.

Here is an excert from the MSDN2 appSettings Element documentation which discusses the format of the file specified in the file attribute.

Configuration files that are specified in a file attribute must have the appSettings element rather than the configuration element as the root node.

The following code example demonstrates how to use the correct form for a configuration file that is specified in the file attribute.

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="Application1" value="MyApplication1" />
<add key="Setting1" value="MySetting" />
appSettings>

I started getting SystemConfigurationExceptions stating that the "Root element is missing." I tried all sorts of things until I eventually removed the "<?xml version="1.0" encoding="utf-8" ?>" tag included in the documentation above. Having done this, my code worked as expected. I confirmed that this is the cause of the problem by simply re-adding the element to generating the exception.

I am pretty sure that the behaviour here has changed (as I have used this format successfully in the past) but I have been unable to pin down in which version of the framework this occurred.

Trick for Generating Connection Strings

Brahim Benbachir provided a link to www.connectionstrings.com. It looks like a useful resource but I thought that I would share a little trick I use to generate connection strings.

  1. Create a new text file.
  2. Change the extension of the file to 'udl'.
  3. Double click on the file which will open the 'Data Link Properties' dialog box.
  4. Configure and test the connection that you require.
  5. Close the dialog.
  6. Reopen the file but this time use Notepad (or some other text editor).
  7. Copy everything under the line containing the text '; Everything after this line is an OLE DB initstring'.

I like to keep a udl file handy on the desktop for example so that I can skip the first couple of steps.

Steps to create a config file for a Test Project.

If you are testing code that needs access to configuration settings in a config file, you will need to add a config file to your Test Project. This is not very difficult to do but does involve some non-obvious steps.

  1. Add a new Application Configuration File to your test project.
  2. Change the name to the following format. Visual Studio looks for a file with this name and uses it to provide configuration settings to the tests.
    <Project Name>.dll.config
  3. Add any required configuration settings such as AppSettings and ConnectionStrings to the file.
  4. Set the 'Copy to Output Directory' property of the config file to 'Copy Always'.

Podcasts for Tech Stuff

I have been a long time listener of DotNetRocks and also get over to IT Conversations pretty regularly. I recently noticed a set of links at IT Conversations titled 'Other IT/Geek Audio'. I clicked through a few and quickly realised that if I was going to make the most of this new found resouce that I would need to get organised. Carl from DotNetRocks has been talking about Podcasting for some time now and I decided to check it out.

Firstly Podcasting is similar to RSS. The difference is that a Podcast feeds have tags that contain the URL for an audio file - usually MP3. You subscribe to various podcast feeds and your reader will download the files that are referenced there.

I saw that iTunes acts as a Podcasting client and that it allows you to synchronise the files that it downloads... if your MP3 player is an iPod (mine is not). It also doesn't help with the DotNetRocks podcast as they require a BitTorrent client. The DotNetRocks crew put together a little description (including a quick video of them going through the installation) of how to get up and running with their podcast. It involves installing a Java application - Azureus - and one of its plugins to support RSS feeds.

So, that done I successfully had DotNetRocks shows being downloaded to my laptop.

But IT Conversations and the other feeds that it has in its list of links are not in BitTorrent format so I went back and downloaded iTunes too; I like it so far. ...I just realised that I forgot to check if Azureus can hangle non BitTorrent feeds... oops... lets just assume for the sake of this post that it can't... I especially like that some sites have an iTunes link that will automatically subscribe you to the feed (normally you would need to cut and paste the URL).

OK. Now I have all of the feeds that I am interested in being downloaded without me needing to navigate to each site and manually download them. Now I just have to get them over to my MP3 player.

I wanted to move away from any manual work here too. So I set up MediaPlayer to syncronise the target folders for the Podcast readers with my player. This involved setting up an Auto Playlist based on a File Name criteria for each of the folders. I was then able to check a box on the Synchronise tab to include this PlayList while synchronising. I use the readers to delete files that I am finished with and MediaPlayer looks after replacing those files on my player with new ones.

It doesn't exactly all happen by itself as I still have to start up the readers to initiate the download. Although I prefer this to getting complaints from my consulting customers that I am hogging too much bandwidth when the readers kick in while I am connnected to their network.

Now the only problem I have is that if I only get halfway through a file while on the running machine that my player does not let me easily scroll to the point where I left off next time I go running. I have heard bits and pieces about tools that allow you to chop up a file. Anyone have any recommendations there?

Microsoft goes one up on Google

I used Visual Studio 2005 on my last few projects and have for the first time in years found that there is a better place to go to investgate bugs than Google. The MSDN Forums and the MSDN Product Feedback Center have some really useful information. What's more Microsoft employees regularly reply to posts there.

I wonder how long it will take Google to regain the title...

Community server to the rescue. No more comment spam?

I was getting inundated with comment spam in the old .Text blog and had even resorted to turning off comments. I have been hanging out for the Community Server installation at DotNetJunkies in the hope that it would mean an end to the problem. I had not really thought so much about how this would be implemented but had assumed that a Captcha control (or something along those lines) would be used.

I did a quick check by temporarily adding a comment to one of my previous posts. I didn't see any obvious indications that spam prevention was being used. Does anyone know what method Community Server uses?