October 2010 - Posts

I love R#. It’s a great Add-on that makes Visual Studio .NET a usable tool. What I don’t like about R# is it’s test runner – so slow… I switched to use TestDriven.NET almost two years ago. In the last few weeks had to go back to R# test runner. What a difference. I tried to capture the difference on a video, so that you’d see the difference between R# test runner, TD.NET, and command line build script that does everything (compile and test). By the looks of it, R# takes about the same time as command line script. A tool that does literally miracles with VS.NET should be a bit snappier IMO.

PS: I used free version of Jing to capture the video since this is something I was using for a while. But to get it into AVI I used free Microsoft Expression Encoder 4, which I will be using as a capturing tool. Changing tools as you go, another blog post subject.

2010-11-03 Update: QAs at JetBrains are looking into the issue.

So now it’s official. After 2 year with Cortex I am leaving. It was an extremely interesting period in my professional life. I was given an opportunity to work with so many great people and an outstanding group of developers, build a great team, exercise TDD/BDD development, experiment with agile processes, design and build systems that evolved the company business in electronic procurement and supply chain management. Among many other things that I could list here, I learned a big deal of human-related skills. In the business of software and computers, human skills are still one of the most important commodities that striving to acquire is necessary for any software developer that wants to be successful.

Every end is a beginning. I am excited to start another chapter in 2 weeks.

This a very good introduction into RESTfull services on .NET platform.

image

The author goes into implementation on bare metal (browsers),

ASP.NET MVC, WebForms, WCF, Silverlight, etc. A good read to get into RESTfull services. 

 

Today Jonathan and myself worked on a RESTful service that is responsible to create a new invoice. The design decision was to return HTTP status code 409 (Conflict) in case client tries to add more than once the same invoice. The code looked like this:

public Invoice AddNewInvoice(Invoice newInvoice)
{
var existingInvoice = invoices.Find(x => x.Id == newInvoice.Id);
var ctx = WebOperationContext.Current;
ctx.OutgoingResponse.Headers["Cache-Control"] = "no-cache";

if (existingInvoice != null)
{
ctx.OutgoingResponse.StatusCode = HttpStatusCode.Conflict;
return null;
}

invoices.Add(newInvoice);

ctx.OutgoingResponse.StatusCode = HttpStatusCode.Created;
ctx.OutgoingResponse.Location = PluginFactory.INSTANCE.InvoiceServiceUri() + "/" + newInvoice.Id;

return new Invoice(newInvoice.Id, newInvoice.Receiver);
}

Everything was fine, except that in our client (Silverlight 4.0) application it was impossible to get the HTTP status code you’d normally get on a normal .NET stack. By the looks of it, definitely something Microsoft team should look into.

But no worries, we decided to look into WebException to see if it really that clueless or it actually has what we need and hides it. After all, Response is a WebResponse object.image

Unfortunately, no luck there. The implementation was exactly what Intellisense showed us.

  public abstract class WebResponse : IDisposable
{
public abstract long ContentLength { get; }
public abstract string ContentType { get; }
public abstract Uri ResponseUri { get; }
public virtual WebHeaderCollection Headers { get; }
public virtual bool SupportsHeaders { get; }
void IDisposable.Dispose();
public abstract Stream GetResponseStream();
public abstract void Close();
}

Then we tried the last resort – review object in debugger. And there we could find an interesting thing. Silverlight has two HTTP stack implementations, Browser and Client. We used the Client one. The type of e.Response was System.Net.Browser.ClientHttpWebResponse as a result of that. Now ClientHttpWebResponse had everything we needed. The only problem was that casting was impossible due to Microsoft decision to make ClientHttpWebResponse internal. 

 

 

image 

Normally, we’d go with reflection to access the StatusCode property. But reflection is ugly and painful. This is where dynamic becomes really handy. Definition of dynamic says:

Type dynamic behaves like type object in most circumstances. However, operations that contain expressions of type dynamic are not resolved or type checked by the compiler. The compiler packages together information about the operation, and that information is later used to evaluate the operation at run time. As part of the process, variables of type dynamic are compiled into variables of type object. Therefore, type dynamic exists only at compile time, not at run time.

Final result that works:

	catch (WebException e)
{
dynamic exceptionResponse = e.Response;
if (exceptionResponse.StatusCode == HttpStatusCode.Conflict)
//...
else
//...
}

Update: JR has actually posted the code were this technique is applied. Check it out.

Today, a work of two years has manifested itself as an ordinary fact.

An old project (2 years old) had to be re-opened for new features required by client. This is a project we started when I joined the company, back when team didn’t have any TDD skills. It was group’s first attempt to use BDD, combined with Mocking using Rhino.Mocks, NHibernate, WatiN, and some other tools and libraries that previously were never used. We executed tests using ReSharper 4.1 test runner and didn’t have build script to execute them automatically (build server was the next step after the project was done). So we tagged the project as a legacy project, and placed in the legacy projects repository (the one that had all the “fragile” code).

So as I was going through the project details with the development team, I automatically called it Legacy Code. And after we were done with a quick pair-review, a developer told me “Sean, you are wrong, this is not a legacy code. I have tests to verify changes. I have confidence in what I will be doing. Therefore it is not Legacy Code.”

Call me sensitive, but it did warm my heart.

The other day I was listening to This Developer’s Life podcast, episode 1 – Getting Fired. Please don’t confused, I am not getting fired (yet), but I find it very interesting how Rob formulated his experience. I also completely in agreement with Oren Eini. Being honest (not rude) is a key to successful work relationship. Dealing with people is not always logical, therefore the importance of way things are communicated sometimes exceed the message itself.

I am so grateful to Graham O’Neale for blogging his experience with installing Management Studio Express for  MS SQL Server 2008. This has definitely saved me time (and others based on comments).

In my case, I have installed Visual Studio .NET 2010 first, and then tried to install Management Studio Express.

It is a great honour to work with the person who wrote the book Iimage just recently finished reading. The Agile Samurai is a mix of project management and software development. It’s a reality check helper if you are trying to run agile process in your company/team/project. The intention of this post is not to review the book, this is what I will do later at Amazon. Jonathan has managed to make me think of certain things in a different manner, maybe a little bit more realistic. There are a few new tools I can put under my belt (Inception Deck) to move forward with. The most important message from the book IMHO was not taking Agile literally as written - fluctuate, experiment, and question.

This is not a technical post.

A while ago I was told that you always have time, you just don’t know how to manage it. I tried to resist to that person, knowing nothing about life of family with little kids. Yes, you can make “borrow” some time from family and kids, but that is not an option I would take.

The article below is a very accurate description of what it’s like, and highly recommended to those “that know better” :)

parenting

More Posts