Monday, May 9, 2011

The Report of ALT.NET’s Death Was an Exaggeration

I spent last weekend in Redmond at ALT.NET Seattle 2011 and it was an amazing experience.  This is the 3rd ALT.NET conference that I’ve attended and they’ve all been unique experiences.

A New Breed

There were very few of the original ALT.NET leaders at the conference, but it was awesome to see so many new people picking up the torch.  There was a significant change in the atmosphere from previous ALT.NET conferences too.  The theme of the conference was “practice don’t preach” and it was reflected in the attendees and conversations.  I had so many great conversations with people based on their experiences and practices that they actually use.

James Shore gave an excellent keynote speech about cargo cults and how it’s important to understand the substance of an idea.  This concept was solidified for me in a session about CQRS, which many believe is a cargo cult, but it was the most pragmatic conversation about CQRS that I’ve ever had.  There was as much talk about when not to use it as there was about its benefits.  All of the proponents of CQRS warned about the pitfalls and downside to it and provided a lot of experience based expertise.  I didn’t hear a lot of talks with this kind of tone at previous ALT.NET conferences and it really struck me how the community has evolved.

Not Satisfied

One of the most thought provoking sessions happened near the end of the second day where a great discussion about learning occurred.  If this conversation would have occurred at the first ALT.NET conference that I attended, it would have focused on TDD, Agile and pair programming.  This time around those topics are accepted and we talked about pushing those techniques even further and incorporating organization learning techniques.  It’s great to see how those early topics have been accepted and new ideas can be discussed to raise the bar even higher.

I had so many conversations with people who didn’t care about buzzwords and rhetoric and just wanted to find better ways to develop software.  It wasn’t about who the big names were, just about sharing ideas.

ALT.NET Lives On

ALT.NET isn’t dead, not by a long shot.  Just because most of the original ALT.NET leaders have moved on, a new generation of ALT.NETers have picked up the torch and are running with it.  It may not be as in-your-face as it used to be, but those involved in the community are still pushing the .NET community as a whole forward.  The ALT.NET community has evolved and it continues to provide a huge amount of value to the .NET community as a whole.  It was a fantastic experience and I can’t wait to apply all of the new things that I learned.

Tuesday, March 1, 2011

Software Developer Résumé Tips

I’m currently in a situation where I’m part of a hiring team for two different companies.  I’ve been up to my eyeballs in developers’ résumés and I have to say that I’ve been less than impressed.  The problem is that very few developers put anything in their résumé that distinguishes themselves from others.  For the most part I’ve seen long lists of tools and technologies used, lists of places the applicant has worked along with more lists of tools and technologies they’ve used, and a short list of their education.  None of this makes the applicant stand out as a developer.

Here are some tips that will help your résumé stand out and will get you to the next stage in the hiring process.

Passion

Tell me that you actually like doing what you do.  Tell me about the books that you’ve read, the user groups you attend, the blogs that you read and the podcasts you listen to.  It’s even better is you can link to your own blog and the open source projects you work on.  Tell me why these things are important to you and how they help make you a better developer.  I need to know that you’re not just coasting through your career and that you’re constantly trying to improve your skill set.  I guarantee you that the job you’re applying for is not exactly the same as the one you have and I need to know that you will be able to adapt and thrive in a new environment.  I want to know that you bring fresh ideas to the team and will help the team take advantage of changing technologies.

Champion Change

Tell me about how you’ve driven change in your development team to make it more productive, raised the quality of the code or reduced the bug count.  Tell me about a pain that your team had and what you did to fix it.  I want to know that you care about your team and that you care about the products your team produces.  I need to know that you will be an asset to the team and will take action when you see a need.

Stand Out

Remember that you’re certainly not the only qualified candidate applying for the position and you must make your résumé stand out.  Think about what’s on your résumé and how unique it makes you look.  Ask yourself if it highlights what makes you the best candidate for the position.

Work Experience

Yes, work experience is important.  The problem is that I’m learning way more about the companies you’ve worked for than I’m learning about you!  Don’t just give me your company’s elevator pitch, your job description and a list of tools.  Tell me about a valuable skill that you learned.  Tell me something outstanding that you did to make the project succeed.  Tell me how this experience has made you a better developer and how you will be able to apply those skills at your new job.

Think about what makes you stand out as a developer and ask yourself if that is reflected in your résumé.  Make sure that your strongest assets are highlighted and will stand out to the person reading it.  If you follow this advice you will have a much greater chance of moving to the next stage in the hiring process.

Thursday, February 24, 2011

ADO.NET Query Causes SQL Server to Ignore Primary Key Index

*Disclaimer* I am not a DBA. I'm just a poor, humble developer. I just happened to be the guy standing closest to the server when the DBA quit.1

The Story

I came across a performance bottleneck today that had me stumped for a while.  A query to the database, for a single record, by the primary key, was taking 3 seconds.  Let me say that again, by the primary key, for a single record, taking 3 seconds.  How could this possibly be?  I pulled the query out into Management Studio and ran the query again after turning on the option to display the actual query plan. (Query –> Include Actual Execution Plan)  I was quite surprised when the query plan was not using the primary key index at all.  To make a long story short, SQL Server didn’t use the primary key index because the generated query supplied the parameters as NVarChar while the actual columns were VarChars.

The Cause

The query was generated by an open source tool, so I was able to dig in to find out how it crafted the query.  Basically it came down to this code:

IDbDataParameter parameter = command.CreateParameter();
parameter.ParameterName = paramPrefix + name;
parameter.Value = val ?? DBNull.Value;
command.Parameters.Add(parameter);

This is pretty standard code for ADO.NET but the key isn’t in what’s there, it’s in what is not there.  The parameter’s type is not specific which causes the .NET framework to use it’s own mapping of .NET type to SQL Server type.  The value that was being passed into this piece of code was a string and automatically got mapped as an NVarChar, or System.Data.DbType.String.


The Solution


To get around this default I needed to use my own mapping to use the non-unicode string type.


parameter.DbType = DbType.AnsiString;

With this additional line of code, this query executed infinitely faster; I’m not kidding.  It went from taking around 3 seconds and now consistently measures at 0 milliseconds.  How often can you claim an infinite performance optimization in your system?


1 This story is not true. It's a lie, made up.  There’s has never been a DBA here, and if there had been, I would not have set foot anywhere near the server just to avoid such a situation.  However, in many cases I am the Accidental DBA and I find myself struggling through problems just like this one.

Thursday, January 27, 2011

Messing around with C# dynamic

At last night’s ALT.NET Vancouver meet up we were talking about the dynamic keyword in C# 4.0 and how it could be used for dispatching a message to the appropriate message handler.  The conversation with a look at Chris Nicola’s blog post on the topic.

The first test that he shows in the post fails. 

[Test]
public void cant_pass_base_class_to_function_dynamically()
{
dynamic handler = new FooMessageHandler();
IMessage message = new FooMessage();
handler.Handle(message);
}

To me, this was expected.  Despite using the dynamic keyword for the message handler, the C# compiler is still going to use the same algorithm for method matching as it does on a static object.  To make this method pass we need to add our own method matching, and in C# dynamic, that means overriding the TryInvokeMember method.


public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
result = null;

if (binder.Name == "Handle" && args.Length == 1 && args[0].GetType() == typeof(FooMessage))
{
Handle((FooMessage) args[0]);
return true;
}

return false;
}

This code looks to see if the Handle method was being called and then checks if the argument passed in will satisfy the real method then calls then method. It's not the cleanest code, but the test does pass with this override. We can take it a little further and move the method to the base class so that we don't have to repeat the override for each message handler.


public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
result = null;

if (binder.Name == "Handle" && args.Length == 1 && args[0].GetType() == typeof(T))
{
Handle((T)args[0]);
return true;
}

return false;
}

One of the conclusions that we reached at the meet up was that dynamic is well suited to where reflection would have been used.  I have done message dispatching with reflection in the past and I think I like this approach better once I clean up the code a little more.


P.S. Also check out Cliff Hammerschmidt’s post on Graft-on Visitor in C#.

Friday, January 7, 2011

Inversion of Control: It’s All About Decoupling

I've been using Dependency Injection and Inversion of Control for a few years now and have always wondered why there is such resistance to the concept. I've heard the argument that it seems too complex and on a not-so-recent Dot Net Rocks episode, Richard Campbell was concerned that it would make debugging more difficult. To me, Dependency Injection and Inversion of Control are just fancy words for a technique designed to reduce the coupling in your system.

Coupling is one of those terms that everyone knows, but few pay much attention to on a daily basis. I can remember an exam I wrote for a second year Computer Science course that had the following multiple choice question on it:

Object-oriented code should exhibit these characteristics:

a) High coupling, high cohesion
b) Low coupling, high cohesion
c) High coupling, low cohesion
d) Low coupling, low cohesion

I knew the answer right away, but thinking back on it, I couldn't have gone into much more detail about what those terms actually meant, or more importantly, how to apply the principles to code. I’ve found that coupling and cohesion are concepts that most people take a long time to apply at anything more than an elementary level.

At one place where I used to work, the development team completed 360 degree evaluations of the each other. One of the characteristics that we evaluated each other on was that we wrote “quality object-oriented code that displayed a low level of coupling and a high level of cohesion.” Vague I know, but what was most interesting about it was that the developers who wrote the poorest code in this regard scored themselves the highest, and the developers who wrote the best code, scored themselves the lowest. I interpreted this to mean that the developers who fully understood what it meant to write loosely coupled code were able to remove much of the coupling from their code, but were also keenly aware of the coupling that they left behind.

The argument that IoC makes debugging more difficult doesn’t hold any weight to me.  The argument is that you don’t know exactly which implementation is being called when a method is called because the call is to an interface or an abstract class and not a concrete dependency.  Now listen up people, cause I’m going to let you in on a little secret, THAT’S CALLED LOW COUPLING!  You’re only coupled to the interface, not the implementation, that’s what object orientation is all about!

So the next time someone tries to argue against IoC because it’s too complicated, just remind them about the foundations of object-oriented programming.

Saturday, November 6, 2010

Agile Vancouver 2010 Tutorial Materials

As promised, here are the materials from the Domain Patterns Big & Small tutorial.  Chris has posted his material on his blog.

Domain Patterns Big and Small.pptx

Samples (Before).zip

Samples (After).zip

Friday, March 26, 2010

Technical Debt, Non-Technical Managers and Tony Soprano

Yesterday’s Ignite Your Coding webcast featured Dave Laribee speaking about technical debt.  It was very insightful and Dave made several great points that make the technical debt metaphor more powerful.  One point that struck a cord with me was that of “high-interest debt”.  I’ve always found the technical debt to be a very powerful when talking with other developers, however, it seems to lose it’s effectiveness when talking with non-technical managers.

A Short Story

A few years ago I worked on a project that had a lot of technical debt, like mountains of debt.  New development was painfully slow because of all the crappy code that we had to wade through just to make a simple change.  The dev team had all sorts of inside jokes about it and any estimates that were given were always padded with a hefty “tax”.  We all knew that we had loads of technical debt and had to do something about it, but the message always seemed to get lost when communicating this to management.  Looking back now I can’t blame them at all because in their eyes, debt was how you grew the company.  The company had been built with loans from angel investors and venture capitalists and this was considered a good thing, this is how the company was able to grow to the size it had in the short period of time that it had.

High-Interest Debt

What we as a development team failed to communicate was that the technical debt we had incurred was not the technical equivalent of loans from angel investors and venture capitalists.  No, we had borrowed from Tony Soprano and every other loan shark in town, we’d maxed our the credit cards and had 3 mortgages on our homes.  The fact is that in software, the interest rate on technical debt can run much higher than what business people are used to in the financial world.

Metaphors

This is the inherent danger of all metaphors, they only take the concept so far and end up implying meaning that was never intended.  As business person already has preconceived notions about borrowing and debt that they will carry with them when speaking about this metaphor.  From now on, I will make an effort to clarify the “interest rate” when speaking about technical debt to non-technical managers.

Paying Down Technical Debt

I would be remiss if I didn’t touch on strategies for paying down technical debt and the best resource I’ve seen is Dave’s article in MSDN magazine titled “Using Agile Techniques to Pay Back Technical Debt”.  Go check it out so that you can start to pay down your debt and get Tony off your back so you won’t end up swimming with the fishes!