Thursday, August 07, 2008

YAMAHA PSR-S700

I always wanted to get a keyboard. Finally I bought this.

PSRS700

Wednesday, July 09, 2008

The Pencil Project

I came across this cool FireFox plug-in while browsing reddit. It lets you prototype your UI's within FireFox

 

pencil

 

It can be downloaded from http://www.evolus.vn/Pencil/Home.html

Friday, June 27, 2008

Writing Testable Code - Part I

In the current project that I am working on we decided that we will strive to write as many unit tests as possible. Here I will try to share some lessons learned from this experience.

The application was broken down to following layers, A DAL that communicates with the underlying database, a service layer that implements business rules and the UI layer.

We started with writing the DAL and some services. Since our services didn't have any state we decided to go with static classes. A typical service class might look like this.

public static class OrderService
{
public static void ProcessOrder(int orderId)
{
OrderHeaderDAL headerDAL = new OrderHeaderDAL();
OrderDetailDAL detailDAL = new OrderDetailDAL();
CustomerDAL customerDAL = new CustomerDAL();

//Do the processing.

}
}


We managed to write unit tests for the DAL without any issues. But as soon as we wanted to write unit it was apparent that we cannot do this because the service classes are directly coupled to the DAL. Clearly we needed to decouple the Services from the DAL and the first solution that came to my mind was dependency injection. To do this we needed to make the following changes




  • Make the service class methods instance based rather than static


  • Define a set of interfaces that will decouple the DAL from services


  • Add a factory class that will assemble the service classes


service classes instance based rather than static and add a layer of DAL interfaces that the services will depend on instead of the concrete classes . Now the above example will look like this.



public class OrderService
{
public IOrderHeaderDAL OrderHeaderDal
{
get;
set;
}

public IOrderDetailDAL OrderDetailDal
{
get;
set;
}

public ICustomerDAL CustomerDal
{
get;
set;
}

public void ProcessOrder(int orderId)
{

//use the injected DAL's
CustomerDal.DoWhatEver();
}

//Whenver you want to use the order service you call the ServiceFactory
OrderService service = ServiceFactory.CreateOrderService();


This solution worked. now we can mock the DAL and write unit tests for the service classes easily. But this had the following issues. Some methods in a service don't use all the DAL classes that the service depends on. But when the service factory creates the service it injects all dependant objects regardless of weather they are used or not. In the next post I will describe how I fixed those issues.

Thursday, June 05, 2008

SysInternals tools available on a Internet file share

All SysInternals tools can be now run from \\live.sysinternals.com\tools. This is very handy when you are troubleshooting productions servers and don't want to download everything on to the server.

Monday, April 21, 2008

Integrating VS 2008 unit tests with CCNET

In my current project we are using VS 2008 unit tests. We have a CI environment configured using CruiseControl.NET. When we tried to integrate the unit tests into the CI build process we found out that it does not work out of the box. The main reason was that the XSL files that ship with the current version of CCNET only supports generating build reports off VS 2005 unit test results. So I had to modify the style sheets a bit. I wrote a code project article on setting up CCNET to run the unit tests. The modified XSL files are also available for download with the article. Please find it at http://www.codeproject.com/KB/tips/VSTS2008_Tests_With_CCNET.aspx.

Tuesday, April 15, 2008

KeyedCollection class

If you follow a entity object based design in your applications you frequently need to maintain lists of your objects. You can use List<T> class to do that. I was using the same method until I ran code analysis on one of the projects and got the warning  for violating rule "CA1002:DoNotExposeGenericLists". The following blog post explains the background behind the rule http://blogs.msdn.com/fxcop/archive/2006/04/27/585476.aspx

A better alternative is to use the KeyedCollection <TKey, TItem> class. As the documentation states it provides an abstract base class for a collection whose keys are embedded in the values. For example you can have an Employee class that has the key EmployeeNumber as a field. In this example you want to be able to do operations on your collection class (lets say EmpleyeeCollection) based on the employee number. Since the KeyedCollection class has to know how to get a key from an item it is an abstract class. You have to derive your own class and override the GetKeyForItem method. The following blog post has a clever method to avoid creating a collection class for every object that utilizes lambda expressions http://vaultofthoughts.net/keyedcollectionlambdaexpressionway.aspx

Working for a new place

I left the previous workplace and joined CalCey Technologies (www.calcey.com). I made the move in February. The major reason behind joining CalCey was that its a small company. All this time I was working for companies that are considered big players in Sri Lankan IT industry (hSenid, Virtusa, Eurocenter).

There are advantages working for a big company, you get a good knowledge about process and get a lot of training opportunities, traveling etc. But at the same time when the company is big its very easy to loose focus on the core business which is developing software and focus more on the other things. The obvious "other thing" here is process, add to that internal politics and bureaucracy and it can be a nightmare. Having a good process is essential to a software company but it should support the software development work not the other way round. I feel the fundamental problem with big organizations is that teams don't scale well.

Working for a small company on the other hand will give you the flexibility and the freedom the geek inside you desire. It will be easier to introduce new ideas and make changes. But sometimes you can end up with a bunch of  below average colleagues especially in Sri Lanka where people prefer to work for big companies.

There are pro's and con's in both worlds. My personal opinion is that you should start your career at a big company and work for 5-6 years then move on to a small company and after some time you can decide where you want to stay.

Friday, March 28, 2008

Passed a couple of Brainbench tests

Passed the free ASP and ASP.NET Brainbench tests last week. The classic ASP test was cool and helped me to find out if I still remember it from the good (or bad) old days of working with ASP.