I always wanted to get a keyboard. Finally I bought this.
Thursday, August 07, 2008
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
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.
Wednesday, March 12, 2008
.NET Framework Library source code available
You can configure Visual Studio 2008 to step into framework source code as you debug. You can find detailed information on how to achieve this from http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx
Sunday, November 18, 2007
Check how your web site looks in different browsers
If you have ever developed web sites you know how difficult to get them to look correctly on different web browsers. Given the no of web browsers and operating systems available it is very difficult to test on all sites. Now http://browsershots.org/ provides a free service where you can enter the URL of the web site and it will take the screen shots of how the web site looks in each browser. The downside is you wont be able to check the dynamic behavior of the site (JavaScript etc..).
Sunday, October 07, 2007
Great site to find singhala song chords
If you are into playing the guitar you will find the following site very usefull http://chords.orgfree.com. According to site statistics it has 257 songs now and its growing. If you have chords for songs please share them.
Friday, August 03, 2007
Threads and Cultures
When you create a new thread you would expect it to inherit the culture information from the original thread since this is the sensible behaviour because you want that thread to access the correct resources and use culture specific formatting etc... But I discoverd in dotnet this is not the case. This also applies to the BackgroundWorker component. So every time you create a thread you have to copy the culture info from the original thread. Strange ......
Friday, July 20, 2007
SQL Server Sri Lanka User Group - July Meeting
We had the SS SLUG july meeting on the 18th. I did a session on SSIS Custom components and dinesh priyankara conducted a session on transaction management. The presentations and samples can be downloaded from here.
Friday, May 18, 2007
MissingManifestResourceException
I came through this strange exception today while refactoring a windows forms application in VS 2005. This was a VB.NET application. I had to move a usercontrol between projects and doing so I changed the namespace. Suddenly I was getting a MissingManifestResourceException when the control is loaded. The strange thing is there were some other user controls in the same namespace and they worked fine.
Then I inspected the generated assemblies using reflector and discovered that the failing controls resource didn't have any namespace.
After a bit of googling I found this blog entry http://jameswho.blogspot.com/2004/06/missingmanifestresourceexception.html#links this entry suggested changing the default namespace. But I always keep it blank and specify the namespace in each file. Scrolling through the comments there were some suggestions to remove any class or enum declarations that came before the control class. This was exactly the problem I had, there were a couple of enum declarations and a delegate before the control class; after moving them to the bottom of the file it worked fine.
I think this is a bug in visual studio that you have to watch out. It is always a good practice to have only one type in a given source file.
Tuesday, January 02, 2007
ASP.NET 2.0 CSS Friendly Control Adapters
They have released the CSS Friendly control adapters 1.0. If you have ever looked at the code generated by ASP.NET 2.0 controls like the menu and were shocked by the huge tables and inline CSS they generate then these control adapters are for you. They replace the table based layout of the controls with with CSS based implementations using lists/div's/span's and styles. This decreases the amount of markup generated and reduces the page size. Using style sheets also lets you easily change the layout of the controls.
ASP.NET control adapters let you customize the rendering of server controls without writing a new control from scratch of deriving from existing controls. Adapters can be applied based on the user agent and are configured using a browsers configuration file in the App_Browsers special folder. This lets you integrate the CSS friendly adapters into existing web sites with minor or no modification to the existing pages.
The source code can be downloaded from http://www.asp.net/cssadapters
Tuesday, December 19, 2006
Visual Studio 2005 SP1 Released
Finally Microsoft has released a service pack for visual studio. It claims to have fixed many bugs and has performance improvements in the build process. This will certainly be helpful for developers using VB.NET since the original VB.NET compiler crashed frequently and it took unnecessarily long time to compile solutions. Release notes for the service pack is available at http://support.microsoft.com/kb/928957/.
Web application projects are now built in to the IDE. You will have to uninstall the web application projects add on to install SP1.
If you plan to install SP1 its better to go through the release notes first, it can save you a lot of frustration because it seems that there are many workarounds you have to do to get it installed depending on your current configuration.
Tuesday, December 05, 2006
Typed datasets and VS 2005
Recently I had to use typed datasets in a project for the first time. I always preferred using custom entity objects but due to time constraints there was no option on this one. One thing I don't like about the new typed datasets is that it combines the data access code with the data itself if you drag a table from the server explorer into the dataset it creates the connection and the table adapter in the dataset itself, so much for tiered architecture. So I decided the best thing to do is to delete the table adapter from the dataset and just use it as a container.
Another issue that you have to keep in mind when you use typed datasets is that sooner or later you are going to create datasets that share tables among them. If you create the table in each and every dataset its going to create a maintenance nightmare. A better option is to add a xml schema to your project and define all the tables there and include that schema in each of your datasets using the xs:include element. This way you only have to change one file if your table definitions change.
One disadvantage of the above method is that you cannot define keys in the schema, you have to add the keys to each and every dataset. Another minor issue is that the graphical dataset designer gets a bit messed up with this approach. Lets hope the next version of VS comes with a better dataset designer.
Tuesday, November 28, 2006
Auto Door, Please close gently
I saw the above sign pasted on the sliding door of a van while I was on my way to work. It reminded me of hiring a van to go on a trip sometime back. It also had an automatic door and the driver was always screaming at us for slamming the door (I think its bad for the door closing mechanism) but we kept on doing it .
The fundamental principle that the designers of this door violated is that when people get used to something it's very difficult to change. I think that goes double for software UI's, people are used to the existing familiar concepts and that's something we have to keep in mind before we design our next snazzy application.
Saturday, October 21, 2006
Back to SL
Finally its time to go back home to Sri Lanka. I will be leaving for SL tomorrow (20th) a week ahead of schedule. Everything went ok and the project was a success (despite been deployed on Friday the 13th ;-) ). Norway is a nice place to be but the alcohol is too damn expensive.