h1

VB Extension Methods > C# Extension Methods =(

July 31, 2008

As my title childishly explains VB extension methods seem to have one over c# extension methods. Yesterday I found the following limitation in c#: You cannot modify the object you are calling the extension method on by ref. you must create a copy of the object and pass it as a return value. An example will make this clearer. You CAN do this:

public static IEnumerable<T> AddRange<T>(this IEnumerable<T> list, IEnumerable range)
{
List<T> totalList = new List<T>();

foreach (T t in list)
{
totalList.Add(t);
}

foreach (T t in range)
{
totalList.Add(t);
}

return totalList;
}

You can NOT do this

public static void AddRange<T>(this IEnumerable<T> list, IEnumerable range)
{
List<T> totalList = new List<T>();

foreach (T t in list)
{
totalList.Add(t);
}

foreach (T t in range)
{
totalList.Add(t);
}

list = totalList;
}

It’s a sad day today my c# friends ;p

h1

WPF Findings

July 28, 2008

Here at work I am currently on my first commercial WPF project. Some of the things that I have learnt about wpf (the hard way)

* There is no Paging or Sorting support in the gridview (unbelievable isn’t it?)

* There are no validators!

* The WPF Binding Engine uses reflection when binding against Dependency Properties and as such your properties need to be public. If not, you will get a silent exception in the output screen

* When binding to a dropdown list ComboBox you cannot bind against a nullable int. Why? I have no idea, but you will find that the selected index changed event will not fire

* There is no Gif Animation Support in the Image control. (expected to be supported in next release of wpf)

I have quite a few more points but they were the top few that I could think of that were easy to list out.

Overall I am loving what WPF has to offer and it is quite a different thinking approach as to web development. Although I must admit I feel a bit home sick (asp.net)

h1

Unit Testing Internal methods.

July 10, 2008

Today I did some pair programming with Richard Banks from Readify.

When I explained to him that I use the IDE to generate these property accessors that use reflection to test internal and private methods he showed me a nicer way around it:

  http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx

Basically all I had to do was [assembly: InternalsVisibleTo(“Assembly Name”)] to the assembly.cs file and make sure that the “Assembly Name” was pointing to the unit tests assembly name.

This worked perfectly! Thanks Richard!

P.S I should state the obvious note that this approach doesn’t work for private methods

h1

Frustrated and Disappointed.

July 1, 2008

<frustrated rant>

So on Monday night, a project that I have been working on for 3 months goes live. The project it self was very exciting and fun but unfortunately, it was managed very poorly and as a result, had scope creep and was not finished in time. It was not ready to go live yet it was rushed and tightly managed by Business Analysts and IT General Managers to ensure it still went out and made the deadline. Towards the middle of the project I had raised my conerns many times to the relevant business sponsors but it was ignored. Now, the applications launch (although it was reasonably successful) has lost a lot of credability because it keeps erroring. There have been over 1 million hits to the website with about a 60% error rate/unacceptable user experience. They have had an enormous amount of purchases made through the online store but I don’t think they realise (or chose to care) about the fact that those numbers could have been doubled. It is a frustrating feeling when IT Managers don’t choose to accept the advise of IT Professionals around them. I believe it is called micro managing. I strongly believe an Agile environment would solve these issues I have been experiencing as of late.

</frustrated rant>

h1

Results of SourceMonitor on my current project

June 29, 2008

Well last week Richard from Readify had been called in to help us here at my current engagement – Carlson Marketing. While he was here he pointed me to a few programs that I had not known about. One of them was called SourceMonitor. What it does is basically run some metrics against your code to see how clean and how well/poorly written your code is. Before I start keep in mind that the max code complexity and average code complexity should be between 5 and 15. We ran it against some of the code that was contracted off to an offshore company in india and the results that came back were extremely poor (max code complexity of 80). Rather than bagging out what a poor job they had done I decided to see if my own code that I had written myself was any better. I consider myself to be fairly padantic about the way code is written and try to keep it simple as best I can. I decided to run it against one of my more complex projects here to try and get my worst case scenarios. Here are the results SourceMonitor-profile-code-complexity-metrics

 

as I suspected one of my methods is too long and is too complex. The method basically maps a business object from a web service that’s hosted somewhere across the world. There are many properties on the class that need to be mapped each with fairly complex business logic(s). From this we can see that I have not written enough comments and have a single method that is slightly too complex. On average tho we can see that the rest of the code is fine. It is one problematic method that is throwing everything off a little. I have not gone back to refactor this code as it has been code reviewed by fellow senior devs and we agree that it is an exceptional case and that it is written well. The idea isn’t to stick between the green area 100% of the time but rather to get a rough idea on how well your code has been written. If you genuinely write clean, simple code, I think you will be surprised at how often your code will hti the sweet spot of that green circle.

Here are the results of the code that the offshore company had written: offshore-company-code-complexity-metrics

As you can see the max code complexity is 80 and the average code complexity and comments is off as well.

 

Summary:

SourceMonitor is a great way to make sure your code is clean, simple and most importantly – understandable. It is NOT something to be followed as bible but rather a guide.

h1

TFS Build running out of space.

June 23, 2008

This morning all our builds started failing with the following in the error logs

the reason was because the drop location directory had accumilated too many builds and had run out of space. Rather than deleting the builds through explorer in the drop location you should remove them through TFS so that TFS knows about it.

Here is the command to do so: TfsBuild delete <TeamFoundationServer> <TeamProject> <BuildNumbers> [/noprompt]

h1

My Windows Mobile App Idea!

June 18, 2008

So I lost my phone yesterday. I’m going to get a smart phone for my next phone with GPS and this time i’ll create an app so that when it receives a message it scans the content of the message for ‘find me password=xxxx’ and it will then send its gps co-ordinates to a predefined email address and phone number. once I have these I will then be able to track the phone down using another GPS device.

I am looking at getting an IPhone so I may have to learn some non .net language for this…