Archive for November, 2009

null considered harmful

By incident I stumbled accross the book “Clean Code: A Handbook of Agile Software Craftsmanship” by Robert C. Martin. In this book there is a section on exception handling which is a worthwhile read. It states some obvious things – like handle exceptions there where you know what to do with them — but it is good to be remembered by these best practices once in a while…

One of the more interesting things in that section I found the usage, or better should-not-usage, of null values. Return null is typically a sign of something that doesn’t work. Returning null values clutters op code with all kinds of “if null” checks. Moreover, who hasn’t seen a NullReferenceException lately? Instead of returning null, a number of alternatives can be thought of:

First, if the null is actually the result of an error conditions, throw an exception containing thate error condition. If the error is actually based on a deeper lying exception, simply don’t handle that exception and have it bubble upwards. This way it is clear to the user of our object/method that an error condition has been met. Moreover, the exception should contain the necessary information to aid the programmer in preventing that condition.

Second, if the null value is the result of an expected situation, implement the “Null Object Pattern”, or “Special Case Pattern” instead. Using these patterns you return an object that implements the expected interface, but which implementation is empty. For example, a search for files in an empty directory should return an empty list instead of null. The empty list can be iterated, checked for presence of files, but does not have to be explicitly checked for null.

Development in SharePoint 2010

Developers have been a major audience for Microsoft’s SharePoint team. Developing for SharePoint 2010 got a lot easier. An incomplete list of features added to aid developers: Read more

New in SilverLight 3

Currently I’m at the Microsoft TechEd 2009 in Berlin. There is a lot of talk and demo’s on the new SilverLight release. There are a fiew features that make it much more interesting than the previous versions. My top 3:

  1. Writable Bitmaps: These allow you to create bitmaps from inside the SilverLight applications. This functionality forms the basis for many new SilverLight effects. A cool feature of the writeable bitmap classes is that you render a portion of your XAML into the bitmap and act upon that rendering. Here at TechEd I’ve seen some cool demos like magnifying glasses, or video frame capturing that use this.
  2. Communication framework: SilverLight applications can now communicate with each other. This allows you to modularize your pages. For example, I can think of a set of SilverLight based SharePoint WebParts that communicate about the range of data that they are showing.
  3. Offline capabilities. SilverLight becomes true RIA… You can now take SilverLight applications offline. This allows you to start a SilverLight application from your start-menu or desktop. You do not even have to be online to work with the SilverLight apps.

This is just a top 3. There are much more features and improvements like improved development support in Visual Studio 10 and Microsoft Blend, improved integration into SharePoint, improved data binding, RIA services for data access, etc… SilverLight is developing fast!

 

Linq to anything

LINQ is probably one of the most compelling features of .NET3.5. I love the way you can query your data models and how that is automatically converted to queries to the underlying datasources. If you are not familiar with it, do have a look at MSDN…

Apparently I’m not the only one who loves LINQ. You may already know about Linq2Sql, Linq2Objects and Linq2Entities. However, did you know that there is now also …

  • Linq2RiaServices, allowing simple access to data in the middle tier from SilverLight applications
  • Linq2ADODataServices, providing similar functionality as the Linq2RiaService, but utilizing the ADO.NET Data Services framework.
  • Linq2SharePoint, allowing you to query SharePoint lists and sites from within a SharePoint WebPart, and
  • Linq2Azure, which is used to query Azure storage.

 Seems that every locally or remotely stored set of object  gets a Linq interface…

Return top