Brendan Enrick

Daily Software Development

How Coding Katas Can Help You

Here at Nimble Software Professionals one of the activities that we have started doing is coding katas. We do these to help hone our skills as software developers. We do them because we value continual improvement among our team. The importance of an ever-growing, ever-improving team is very important, and through constant training and reemphasis of these techniques we expect to be able to achieve this important endeavor.

As developers we are presented with problems we must work through on a regular basis. Solving these problems is easier if we know all of the theory and mechanics to help us along the way. Knowing design patterns helps, since these are patterns which occur often enough that there is a repeatable solution. You can also just be a programming genius, and that will also help.

So how useful is it to know a bunch of design patterns? Not very if you haven’t had experience using them. You will not see the opportunity to use it if you haven’t seen it used or used it. Through training and practice you will learn what works when and why.

A kata is about solving a known problem. The standard way to do a kata is to follow along with someone who knows how to solve the problem. Following along with someone will let you see how to solve the problem the correct way. This is designed to help you think and solve problems the same way as that known smart person solves problems.

That is a great approach, but I prefer doing that after trying to solve the problem my own way. This lets me get my own perspective on solving the problem first. I can then compare my thought process with the one of the kata leader. Perhaps I prefer something I did over something they did.

The kata should be repeated again later. This time you’ve done it before, so your new solution should be better. Once you finish once again compare with how the leader did it. Make improvements like this every time until you have either the same thing as the leader or until you’re satisfied with your solution. Once you reach that state you will still do the same kata, but attempt to repeat the same solution, so that the process for solving the problem is well understood. You want to know how to solve problems. You do not want to think about how to solve problems.

One of my favorite katas is the Bowling Game Kata. One of the reasons I like it is because my first time solving the problem I created a solution nothing like the one that the kata teaches. From the kata I have improved how I do things. In my first solution for it I violated YAGNI.

My solution worked very well, and if there would have been more development of the problem my solution might have ended up being “better”. But it is true that I do not know what might come for the project in the future my solution was not as good, and since then I have been training myself to not make the same mistake again. By following along with the kata I’ve learned to improve the development process I use.

How to Add a ToolTip to a RadGridView

So I was using a RadGridView to display some data and I wanted to add a tooltip with more information. Shouldn’t be too difficult. I of course checked through intellisense to see if there were any obviously named properties for setting a tooltip.

I checked on the RadGridView tag for the properties and I also checked the GridViewDataColumn for it. Didn’t come up with anything so I Binged until I found a potential solution. It didn’t really make sense to me and the solution had me doing a lot of what seemed like extra stuff. It was adjusting the tooltip using the styles for the cell. So, then it hit me that I was thinking about this the wrong way. Since I just wanted text and a tooltip why don’t I just add that in?

So I took control of things and I just used a template for the column instead. Here is the quick and easy way to add a tooltip into a RadGridView.

<grid:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False">            
        <grid:GridViewColumn Header="Person">
                    <TextBlock Text="{Binding NickName}" 
                       ToolTipService.ToolTip="{Binding FullName}" 
                       VerticalAlignment="Center" />
        <grid:GridViewDataColumn Header="Place" 
          DataMemberBinding="{Binding Place}" />
        <grid:GridViewDataColumn Header="Thing" 
          DataMemberBinding="{Binding Thing}" />


And there you have a tooltip on the text of a cell in a RadGridView. You can obviously add different content items into the DataTemplate so that you can support more advanced templates. Just throw the tooltip on the root element inside the DataTemplate and you’ll be set.

Programming is Not Just Typing

One of my favorite quotes about programming languages comes from Ward Cunningham who said, “If you don't think carefully, you might think that programming is just typing statements in a programming language.” Not sure if he really said it, but it is attributed to him plenty of times on the Internet.

So back to Ward Cunningham for a minute. I really like that quote. It says one very powerful thing about programming that I think is known by a lot of people using programming languages, but I am not always sure they think about it in this manner. I know that non-programmers certainly don’t understand it. Plenty of people think that all we do all day is type, but there’s a heck of a lot more to it than that.

Nearly a year ago, when Jeff Atwood posted about our being Typists First and Programmers Second, I was quite appalled. Here is one of the most respected individuals in our industry, and he’s making a statement like this in a blog post. Sure I agree that one of the core skills that every programmer needs is the ability to type. I don’t disagree with the importance of typing. I think a programmers ability to quite quickly and accurately is extremely important. He says in the post that there are other things of importance, but I refuse to say that our primary skill is typing.

Although I find that programmers should spend some time thinking and some time typing. If you’re typing non-stop as fast as you can then you’re probably not thinking enough about what you’re typing.

Like broken clocks, even pointy-haired managers are right once a day. Coding is just typing.

This is a bit crazy to me since I work on code every day. I can certainly say that coding is not just typing. This is one of the reasons why I am an advocate of pair programming. I think that a fair amount of time needs to be spent thinking. All programmers need to be able to type quickly, but the core of what we do is the thought and design that goes into making an application that we can be proud.

Don’t get me wrong I have the highest respect for Jeff Atwood. I think he is one of the greats. I just disagree with the priorities here. I believe that a developer can certainly benefit from typing faster. In fact I wish I did type faster. I certainly don’t hunt and peck. I’ve typed without looking at the keys since I was a kid. I can touch-type the “correct” way, but I have my own style that has worked for me since i was a kid.

Most of the development I do these days is pair programming. An Extreme Programming technique I am sure most of you have at least heard of. This technique is an excellent one that I believe produces better software. Why? Well for one because it lets developers spend more time thinking and less time typing. Both guys are thinking, but about different things. One developer has the keyboard at any given time and keeps in his head the path he is on. (This guy is concerned with typing speed.) He types along the path thinking about the code he is currently writing not the structure of the app, but the code he is typing right now. For a short time his typing speed matters.

The programmer in the pair who is not actively typing is spending all of his time thinking. He keeps in his head the path that the typist is taking, not concerned with the syntax of the programming language. That is the other guy thinking about the language syntax. The one sitting back without the keyboard is the guide. He must make sure that the pair stays on the right path using the most efficient route to success.

By spending time thinking the pair is able to take the smarter path to their goal. Rather than brute-force typing speed we use intelligence of our development team to ensure successful work. This isn’t to say that we shouldn’t type very very fast, because typing fast sure does help us be better developers. However, more important than our typing speed is our thinking speed.

If you’re considering your typing speed to be more important than your thinking speed then I am concerned to see how you’ve structured your code in such a way that you need to type very fast. I find that well structured code requires a lot less typing and a lot more thinking.

If you pause and consider for a minute who are the most revered of developers in the world. Do they type fast? I bet most of them do. Is that why we revere them? No probably not. The greatest of people who code are some of the greatest minds in our industry. They are not the greatest typists in our industry. If you could type 200 WPM do you really think your code would be that much better? I doubt a developer could get more than a 10 or 15 percent increase in efficiency even typing that fast. But if you could think twice as fast I am sure you would see a much larger increase in how efficiently you wrote code.

Good luck with either endeavor, but don’t tell me I’m a typist. I am a thinker first and a typist second, and I refuse to let anyone tell me otherwise. Just because someone can type and knows a programming language does not mean that they can create software of any value.

ASP.NET Dynamic Data, MVC, and AJAX

I’ve been having an interesting conversation with Peter Blum about the different directions in which ASP.NET is currently developing. He has some very interesting points that he is making about this topic. So he asked me if I use dynamic data, which is of course how all of this conversation started. I informed him that most of my exposure to ASP.NET Dynamic Data has just been playing around with it. I really haven’t done any applications using it. (I of course don’t consider little test applications and demos to be real applications.)

I also admitted that I’ve been heavily involved with MVC since the early beta versions of it. I didn’t mention at the time that I also started using AJAX very early on as well. I did a lot with “Atlas” as it was called at the time. His responding comment was quite interesting.

the Insiders are so heavily into MVC that we don’t have enough people who push Microsoft to improve the webforms technology

I really think that he makes a great point here since MVC got here we really don’t hear too many of the prominent voices talking about improvements that can be made to ASP.NET Web Forms. Yes, I know there are those who do not like MVC. I read some of their blogs. Some of their reasons are well thought out and very relevant. What I am seeing less often is people commenting on the things that can make web forms better.

Something I’ve said many times since MVC came around is that it is great for certain circumstances. If you’re in one of them, use MVC. If your task requires Web Forms, then use them. Heck, if you need classic ASP, go for it. Using the right tool for the job is extremely important. Just because you’ve mastered the hammer and the screwdriver doesn’t mean you should use them to dig a hole.

A trend that Peter also noted in our conversation is that Dynamic Data came around and there was a little bit of hype for it, but the hype largely died out. MVC, however, has had continual hype, growth, and attention since its mention. AJAX also had a large amount of support and a great following from MVPs, insiders, and influential people.

The thing with Dynamic Data though is that in concept it is a very cool idea and has the potential to be great. It, like all technology, needs to have feedback from the community. It is up to the developers to push Microsoft into developing the technology in the correct direction. I think this is one of the reasons that Peter has been working so hard on Dynamic Data.

With the early beta versions of ASP.NET MVC some of the “testability” was really not there. People trying to use it had to use workarounds to get things to work. For example controllers used to call a method to show the view. They didn’t return ActionResults as they do now. The problem is that it was hard to see what was called so you couldn’t really test it. So I created “fake” controllers to do my testing since the controllers were inadequate at the time. Developers using and giving feedback about what needed to change is what made that project a success.

Not sure if we can revitalize the interest in Dynamic Data and get the ball rolling in the right direction for it, but I can say that I’ve heard very little about it lately. So how about it? Willing to try out Dynamic Data and see how it can be made better?

Peter made DES Dynamic Data, which is supposed to enhance a lot of the aspects of ASP.NET Dynamic Data perhaps I’ll try it out and see if it makes Dynamic Data spectacular.

String Formatting BoundFields in Silverlight

Hi my name is Brendan E. While working with a Bindable Silverlight control I ran into a little bit of trouble because I have a dependence commonly found among Visual Studio developers. I am addicted to intellisense. When a property isn’t in intellisense I make the failing assumption that it does not exist.

So even though I have posted specifically about how we developers should be smart enough to know that we can’t always trust intellisense, I still make the mistake of trusting it.

I am binding to a control and it slipped my mind to use the DataFormatString property, because it didn’t show up in intellisense for me. So of course I look around for what else I might use. I bing a few times about what I am trying to do. When I find the answer I feel like an idiot once again. This must be how all addicts feel. I just need my intellisense.

So I was trying to format my bound field as a percentage. To do that I just needed to add the following code.



Hooray! I’ve got working code now. So I repeat again. Don’t trust intellisense. Just because it says it isn’t there doesn't mean it isn’t there.

Transactional Data Persistence with OpenAccess

OpenAccess is an Object Relational Mapper (ORM) from Telerik, and as you might have noticed from my earlier post about building an OpenAccess enabled project on a build server, I am currently working with OpenAccess on one of my projects. I figure that since I am using this Object Relational Mapper that I should post regularly about using it so that others starting to use OpenAccess have a shorter learning curve.

Making modifications to persisted data needs to be done transactionally so that any issues which arise during the persistence can be responded to and handled correctly. For example if you are going to be updating a customer and that customer’s address then you will want to make sure that the save is an all or nothing situation since it could be bad if the address was saved but not the customer. With a transaction you have the ability to rollback so that you can be at the initial state once again. By doing this we can then handle the error and not have the transaction halfway committed.

OpenAccess has support for transactions using its ObjectScope. To begin a transaction you simply need to access the Transaction peroperty of the IObjectScope and call its Begin method. To complete the transaction you call the Transaction’s Commit method.

using (IObjectScope objectScope = MyScopeProvider.GetNewObjectScope())
    // Perform the persistence logic here

So this is pretty easy, right? Well what about rolling back the transaction if we have a problem. So the simple thing to do is to wrap a try-catch block around the transaction. Then in the catch portion we will need to make sure that if the transaction is still active that we roll everything back to the previous state. (We also handle the exception, but that’s your job not mine.)

using (IObjectScope objectScope = MyScopeProvider.GetNewObjectScope())
        // Perform the persistence logic here
        // UPDATE: This explicit rollback is only
        // required if you're crazy and don't trust
        // that things will wrap up nicely on their own.
        if (objectScope.Transaction.IsActive) 
        // Make sure you handle the exception here
        // failing silently is often a problem

So all we did is check to see if the Transaction is Active and if it is still active rollback the transaction. Wasn’t that easy?

Building an MVC Gaming Statistics Site &ndash; Setting Up the Project

Now that ASP.NET MVC has been around for a while there have been plenty of articles written about how leverage the technology to create powerful, lightweight web applications which are highly customizable and testable. I’ve discussed the advantages of using ASP.NET Forms and ASP.NET MVC plenty of times in the past, but just so no one thinks I am a forms hater I will say that I still create forms applications. Both MVC and Forms can coexist and they both have their advantages.

I will say that there is of course a learning curve for MVC. You don’t instantly know it just because you’ve used web forms. So yes, it will be like learning any new technology. However, I am writing this so that a transition can be easier. Rather than doing some demo application that doesn’t take into consideration real-life situations and circumstances I’ll be posting about an application I’ve been working on.

Background Information and Reason for Creating the Site

I am a member of the Boardgamers Of Greater Akron (BOGA), which if you hadn’t guessed from the name is a group of people who gather together the second Friday of every month to play board games. As games are completed the stats from the games are recorded onto sheets of paper and these stats will later be entered into a database.

Initially the founder of the group had been entering these game logs into the system using a local web forms application using the standard data entry controls. The entire site took about half an hour to an hour to create, so as you can guess it was kind of clunky and hard to use. From the data, I was able to write a bunch of SQL queries that were then used to calculate the stats from these games.

Creating the Solution, MVC Project, and Web Tests Project

I like to start by creating a solution first. I don’t want Visual Studio to create the solution for me because it will do a lot of stuff for me. I want to have control of the structure of my application, so I am going to create that first. This will let me organize my software project. To create a solution just create a new project of type Blank Solution. You can find that in the Other Project Types –> Visual Studio Solutions category.


I named the solution based on the domain of the application. This is important to do since I don’t plan on referencing the domain in any of the projects in this solution. Since names get long and difficult to work with sometimes I am going to stick with shorter ones. I’ll alter their default namespaces so it is a little bit easier to deal with.

Before we can write any code we have to have a project in which to write this code, so how about if we create a new MVC project. I’ll name it based on the domain of our application, so I’ll go with Web. Since the


Since we created this as an MVC site we will be prompted with the option to create a test project. Your Test Framework options will be populated with the test frameworks that you have installed that Visual Studio knows about. In this case I am just going to go with the Visual Studio Unit Test Framework since it defaulted to that. The differences between this and NUnit are negligible anyway.


After you wait for Visual Studio to create the projects for you the following will appear in the Solution Explorer. The first step is deleting the AuthoringTests.txt file. Not sure why that needed to be included every single time a project is created. Maybe there is some way to turn it off just so I don’t have to delete it. Well it doesn’t matter anyway.


I might also delete the App.config file, but there really isn’t much there to worry about. The use of the App.config in testing should be discouraged. If you’re having to put something in there then you have too much dependency on that. Keep in mind that the App.config in a test project should only include test configuration information. If it is using anything that is normally in the production configuration then you’ve got something you need to fix.

Creating the Core and Infrastructure Projects

Our next step is to create a project where we will keep the core logic of our application. This is business layer, but I don’t like that name because business logic often ends up getting mingled with infrastructure concerns. I am naming the next project Core to mean that this is central to the application. Only the things that are core parts of the application go here.




So as usual I need to make a couple of modifications. First I delete the silly Class1.cs file and then move the Models from the web project and move it here. I would say that the domain objects that we are going to be dealing with deserve to be in our core application.



The Infrastructure is the next step. If you expect to have multiple infrastructure concerns that you want to separate into separate libraries go with a more specific name for this project. Since I expect to only deal with database concerns I will stick with a generic name> If I ever need to change things I am not too concerned since renaming things is actually really easy if I structure my application nicely and use refactoring tools to help.


Once I create this I will of course delete the Class1.cs file and I will end up with a pretty full Solution Explorer now. I’ve got most of the projects in place now. I could have started small here, but I know I am going to need these projects.


Creating the Unit and Integration Test Projects

Since I like to keep the unit and integration tests separated from the production code it is nice to keep them in a separate library. This means that the tests need not be included with the rest of the application in deployed scenarios. The only problem I can think of is keeping the tests in their own library could make them just another navigation headache. However, since I use ReSharper I have a navigation tool which allows me to quickly get to anything based on its name, so I am not concerned with that issue.

Since I am using MSTest for my testing framework I can use the Visual Studio Test template. If you’re using something else like NUnit you will just create a normal class library and include a reference to the NUnit dll.


Since we created this from the UnitTest project template it added in the reference to the dll required to use MSTest. However, we will also need to eliminate these files which were created for us.


The next step is an integration test library. These tests are very important in the project as they help us ensure that everything is working well together. We want all the individual pieces working, but knowing that they interact is just as important. We keep them separate because the integration tests can often be long-running and we want to be able to execute the unit tests first. They will run faster and if there are any issues we will know sooner. Creating the integration test project will be done the same way we created the unit test one.


And as usual we have a few files that we do not need. Time to delete them.




I will soon discuss setting up the build process using NAnt and the continuous integration process using As you may have noticed I think the structure of software projects and the initial setup are very important. Without build systems in place I think the development process can be very limiting.


Fun With Web Forms Controls and LINQ

Since LINQ has come out I’ve been very fascinated with it. LINQ to SQL is kind of cool, but working with in-memory collections is my favorite. Sure anything we can do with LINQ we could have done before, but now it’s easy. While not exactly the most practical and certainly not the most efficient method of handling things, working with a page’s Controls collection can be a lot of fun.

So perhaps I want to change the text of all of the TextBoxes on a page. I can easily grab that collection like this.

IEnumerable<TextBox> textBoxes = Page.Controls.
    Where(c => c.GetType() == typeof(TextBox)).Select(t => (TextBox)t);

Well sort of except that some controls will not be in that collection because this is a tree structure so I’ll make a recursive method which will get me all of the controls on the page.

public IEnumerable<Control> AllControls(Control root)
    if (root != null)
        if (root.Controls.Count < 1)
            yield return root;
        foreach (Control c in root.Controls)
            if (c.Controls.Count < 1)
                yield return c;
                foreach (var control in AllControls(c))
                    yield return control;

Now we can work with a page having nested controls. Fun eh? Here is how you can get all of those controls and set the Text property of TextBox ones to their own IDs.

IEnumerable<TextBox> boxes = AllControls(Page).
    Where(c => c.GetType() == typeof(TextBox)).Select(t => ((TextBox)t));
foreach (var textBox in boxes)
    textBox.Text = textBox.ID;

Try it out with a page with textboxes in a login view. It works. Enjoy. Have fun!

Your IoC Container is Showing

Learning to keep things about your application hidden is important. Your code should be exposed to as few things as possible. Using tools like Ninject, Structuremap, etc. is great, but you should try to keep them at arm’s length.

If you want to keep your Inversion of Control (IoC) container hidden you can put a nice wrapper around it. In an application I am currently working with I started by using an IoC container that was very simple. Just enough so that I didn’t have to use the poor man’s dependency injection.

I start with these ten minute home-grown IoC containers for a few reasons. One reason is that they’re quick and easy. Another is that I wanted the developer I was working with to understand how IoC containers work, so having him deal with the inner-workings on an IoC container will give him that knowledge. Also I really don’t always make a decision on which IoC container to use until I see what features will be needed for an application. If one of them will give me an issue I don’t want to be using it. To say it in a nice way, I don’t like trying to force the square peg into the round hole.

Your own container

To start you’ll really want to have a class you can use to give you access to the container you’re using. This is the face of IoC in your application. It isn’t necessarily an IoC container since we’re really just going to have it pass the calls through.

We need to create a simple class. We will call it IoC for this example. I like that name since it is extremely short, so when we use it we aren’t making our lines excessively long.

public class IoC


Resolving Dependencies

The main task we use an IoC container for is to resolve our dependencies. We want to get objects of certain types from it. So we need some kind of Resolve or Get method on the class. In this case I am going to use a static method. Calm down! Static methods can be used sparingly. We just have to be careful with them and keep them very simple.

public class IoC
    public static T Resolve<T>()
        throw new NotImplementedException();

So I need to have something to resolve these dependencies for me. We want to depend on Interfaces and abstractions only, so I will create an interface for a dependency resolver. Then this static method can call through to that interface. This IoC class is really just here for convenience so I don’t have to pass around an instance of my interface everywhere.

public interface IResolver
    T Resolve<T>();


So now I can add this interface into my IoC class. I want to have a static instance of this interface and I want to have a method that will allow me to set the IResolver.


public class IoC
    private static IResolver _resolver;
    public static T Resolve<T>()
        return _resolver.Resolve<T>();
    public static void Initialize(IResolver resolver)
        _resolver = resolver;

Now we’ve got our IoC class finished up. Sure it doesn’t do anything yet, but we can test with this thing by initializing it with a mock, fake, stub, cake, etc.

Using Your Favorite IoC Container

Now that we have this nice interface in place we are set to wire things up. We can use anything we want to actually do the registering and resolving of our dependencies. If you’re ambitious go write your own. If not go grab something else. I’ll use Ninject in this example.

So I will create a concrete implementation of the IResolver interface and I will call it the NinjectResolver. This class will act as my go between for working with Ninject. I make this class inherit from the StandardModule from Ninject and implement my IResolver interface.

public class NinjectResolver : StandardModule, IResolver
    private readonly StandardKernel _kernel;
    public NinjectResolver()
        _kernel = new StandardKernel(this);
    public T Resolve<T>()
        return _kernel.Get<T>();
    public override void Load()


I am using the StandardKernel from Ninject, and am overriding the Load method from the StandardModule class. In the Load method I am registering the dependencies with the IoC container. Then when I want to get instances of the dependencies from the container I will be calling the IResolver.Resolve<>() method and it will just pass through to the StandardKernel.Get<>() method. Pretty simple actually.

Putting Everything Together

Now when my application initializes I just create an instance of the NinjectResolver and call its Load method. After that I pass this in to the IoC class using the Initialize method. Now we go celebrate because we can use this simple code to get an instance of IAmAnInterface in the form of ConcreteClass.

IAmAnInterface impl = IoC.Resolve<IAmAnInterface>()


I hope you’ve enjoyed today’s IoC fun. Please pass forward yesterday’s homework. Tonight your assignment is to figure out how to register your own dependencies without using Ninject. I recommend taking a look at the Dictionary class or something similar.

Viewing Disassembled IL with ILDASM

For those of you who are simply computer geeks I present to you an easy way to view the generated intermediate language code that is generated when you’re using the .NET Framework. So if you’ve ever wanted to see what is generated from your compiler, so you can see what code gets executed at run-time you just need to take a few simple steps.

Open up the Visual Studio Command Prompt. You can find this command prompt in the Start Menu inside of the tools folder for Visual Studio.


From here you will be able to open up ILDASM’s graphical user interface. Open it by typing “ILDASM”. It’s a very simple program.


From here you will want to open up the assembled file you want to view. This could be a class library or an executable. In this example I will use a “Hello World” console application.


The console application really only has one class. ILDASM_World.Program, which can be seen in the image. You can see the ILDASM_World namespace is where the class is located. Inside of the class we have a constructor (this is the default one I did not write the code for it). See this is neat, because we can see that a default constructor was created for us and we can see exactly what it does.

The Main method listed there is a standard one with a Console.Writeline(“Hello World!”); line written in it.

When we open up the method to view it we see the following IL is generated when we compile.


Now what is really cool here is that I bet pretty much every person reading this can figure out exactly what that code is doing. I think that people could have figured it out without my having to explain it. It is really cool to see. There are a lot of awesome tricks you can see here. Also if you’re ever wondering what is going to happen when you compile something I recommend looking here. You’ll be able to see exactly what actually happens.

This will assist you when you’re writing your code since you’ll be able to make a more educated decision on which approach to take with your code if you see what will be generated behind the scenes.

Your homework is to try this with loops and with a goto.