Tijmen 03:10, 8 August 2009

At my current project we needed a quick sort of throw away app that was going to be used by a small group of people. Without going into much details the app basically is a planning and analysis module for the allocation of employees to divisions.

Since development speed is crucial we decided to work with Linq2sql and winforms. No need for all sorts of layers; just get it done.

 

We needed to fill a combobox with values. This should be trivial, but was a bit more trouble than expected. I ended up using the excellent description found here. Basically all you need to do is:

var comboBox = new ComboBox();
var choices = new Dictionary<string, string>();
choices["A"] = "Arthur";
choices["F"] = "Ford";
choices["T"] = "Trillian";
choices["Z"] = "Zaphod";
comboBox.DataSource = new BindingSource(choices, null);
comboBox.DisplayMember = "Value";
comboBox.ValueMember = "Key"; 

 

Notice the clever use of new BindingSource(choices, null);

 

Nothing complex here, but this is static and I wanted to get the values from the db. Next to that it would be nice if we could have some sort of generic function that could take a type of TEntity (table) and some hints to which properties in TEntity it needed as Key and Value.

I ended up with this:

public interface IComboBoxHelper
{
    void SetComboBoxContent<TEntity, TKey, TValue>(
            Func<TEntity, TKey> key,
            Func<TEntity, TValue> value, 
            ComboBox comboBox)
        where TEntity : class;
}

Usage becomes pretty straightforward: register the IComboBoxHelper and it's implementation to the Dependency injection container. Add a constructor dependency and use the helper variable:

comboBoxHelper.SetComboBoxContent<Divisie, int, string>(s=> s.Divisie_PK, s=> s.Divisienaam, comboBox);

The implementation of the IComboBoxHelper takes a datacontext and is responsible for looking up the required entity.

Let's have a look at the actual implementation:

public class ComboBoxHelper : IComboBoxHelper
{
    readonly HRDataContext dataContext;

    public ComboBoxHelper(HRDataContext dataContext)
    {
        this.dataContext = dataContext;
    }
   
    public void SetComboBoxContent<TEntity, TKey, TValue>(
            Func<TEntity, TKey> key,
            Func<TEntity, TValue> value, 
            ComboBox comboBox)
        where TEntity : class
    {
        Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>();

        IQueryable<TEntity> entities = dataContext.GetTable<TEntity>().Select(s => s);
        entities.ForEach(s => dictionary.Add(key(s), value(s)));
        var source = new BindingSource(dictionary, null);
        comboBox.DataSource = source;
        comboBox.DisplayMember = "Value";
        comboBox.ValueMember = "Key";
    }
}

Nothing too complicated, but the use of Func's to get to the properties in the required Entity is pretty nice.

Technorati Tags: ,,
Tijmen 12:53, 4 July 2009

When I joined Avanade half a year ago they provided me with a very good laptop. It's a Dell 830 with a brilliant 1920x1200 resolution. At first I thought it was a bit small but nowadays I hardly ever use my Dell 24" monitor except for the occasional Hollywood download.

The processor is reasonable fast, it has 4GB of internal memory and they even put the decent IBM 7200rpm hdd in it.

 

For some reason however my machines always feel sluggish after a couple of months. Rather that going for a new install again I decided to take the plunge and get myself the Intel X25 SSD.

Intel x25

 

Ordering was easy and after two days it arrived at work in the afternoon. Obviously my teams productivity dropped to 0 as we had to install the drive first and test how fast it would be.

Initial speed experience was a bit of a disappointment. Copying Windows 7 from DVD took about 8 minutes. Now I know this is due to the limiting speed of the DVD but still.  :)

Installing Windows 7 took about 15 minutes, booting as promised only 25 seconds. Installing Visual Studio 2008 was kind of a surprise. I first copied everything on the hdd, then ran the installer. Took about 4 minutes to complete! SP1 which used to take over 40 minutes now only took about 6. Quite an improvement I must say.


Most important however is day to day speed. Firing up VS2008 is fast, it's still not instantly however. Loading projects is 2-3 times faster, but there still are loading times (also because of Resharper I guess).

 

One of the best improvements however is that the irritation on the noise of the hdd has completely disappeared. The only thing that's audible is the soft spinning of the fan. This means more focus to what I'm doing as opposed to what my machine should be doing. You don't care about the hdd anymore as you can't hear it's activity and the little hdd icon is hardly noticeable.

Building solutions, adding references, working with the file system in general; I never get distracted by a waiting time for some stupid IO anymore and development feels just that much snappier.

 

All in all, bit disappointed in the fact that loading still takes a bit time but very satisfied in the overall user experience my laptop now provides.

 

Technorati Tags: ,,
Tijmen 11:58, 4 July 2009

Jeremy Miller is the author of StructureMap. The first DI container I was exposed to. Nowadays I have to use Unity but that's all fine as a DI container is just a vehicle not the purpose.

Anyways, in this presentation Jeremy talks about setting up your solution in a modularized way and how he did it with his Storyteller project (a fitnesse replacement for .Net). He speaks a bit about injecting view, using Presenters and of course the Event Aggregator.All this is very similar to the PRISM or Caliburn framework.

All was fairly interesting, but I think that without some context on these frameworks you'd be lost soon.

 

Now, I have been working on these concepts for a while now and I fully believe this is the way forward. If you are new to this I would recommend first to have a look at PRISM. There are some very good screencasts available on channel 9.

Next to that you probably also want to have a look at the MVVM geekspeak talk hosted a while ago (june 2009) at MSDN, and read a bit at MSDN.

 

Watch the screencast here

Tijmen 11:41, 4 July 2009

I never heard of Astoria before. I did hear about ADO.NET DataService, but as there's ADO in the name it had to be evil. Luckily Astoria is not about ADO.NET, it's about exposing data using JSON & REST.

 

Basically the idea is very simple. You create a website project, add a class that will act as your data source. This can be anything, be it Linq to Sql, Entity or NHibernate. You can even use a stub to temporarily make some data available. The only important thing to keep in mind is that it needs to implement IQueryable for select operations.

Then add a new item - ADO.NET Data Services item.

 

Data services

 

Go to the newly created cs file and implement the DataServices generic base class.

 

Implement interface


That's all there is to it. You can now reference the WCF Data Service and query it like you would query any IEnumerable<T>.

 

Very cool stuff.

 

Some links for Astoria:

Team blog Astoria
Learning Astoria
MSDN Reference
API Documentation
Help forum and info
Whitepaper on using Astoria

 

Watch the screencast here.

Tijmen 11:25, 4 July 2009

Robert Martin is the author of CleanCode. Great stuff in this presentation. I have read most of his books and this talk felt a bit like a reread.

Some of the notes I took while watching the video:

Write small methods, then write them smaller
In an if statement, call a function
In the predicate, call a function
Extract your logic into small methods and objects. Not only to separate concerns but also to document and name your code.
If you feel troubled coming up with a name for a method; it's probably doing too much (and it's probably also too big)
If there's much data sharing between methods in a class; you're probably better off extracting that logic into another class
Etc etc.

On our current project we have done something similar. First we started by naming our methods in a more expressive manner. We then applied cutting off large chunks of code into smaller methods. One obvious downside to this is that you end up with quite steeps objects graphs and lot's of small methods.

We found that as long as you name them properly and stop caring about the inner details some method deep down you'll be fine. But letting go the habit to examine every bit of code to understand what something is doing is quite a steep learning curve.

 

Watch the screencast here.

Tijmen 11:09, 4 July 2009

Rather than giving a presentation from PowerPoint, Ayende asks the audience what they would like to discuss and then starts rambling off.

He talk is 100% around NHibernate. I increased the playback speed in windows media player (available when you go to full screen). Even though there really wasn't that much coherent info it's still fun to observe someone speaking passionate about something they care for.

Watch the screencast here.

Tijmen 11:02, 4 July 2009

This week the NDC conference made available many of it's talks. In contrast to the typical .Net focussed conventions this one is more or less targeted at the alt.net population.  Uncle Bob is there, Micheal Feathers, Jeremy Miller, Scott Hanselman etc etc.

I have been watching some of the video's available and they are generally speaking very good. I'll post short reviews on them shortly. For an overview of the agenda and screencasts see here.

 

Tijmen 09:18, 16 June 2009

I intend to dedicate several (short) posts on the various tools I use to increase my productivity. At some point I will post a complete list of my must-have tools, but for now I want to focus on a new find (for me): the Everything search engine, by voidtools. Everything is a very silly name for a tool and its functionality is not ground-breaking: it searches for files on your local machine, based on their filename. This is obviously not rocket science, but it has a few distinctive characteristics. The first is performance: it indexes an average system in seconds. Literally. Searching is very snappy as well. Another big advantage is its low footprint. it uses up very little memory and disk space, and since its indexing process is very fast, there is no noticeable background disk churning like you get with default Windows search or other third party tools.

So, after this intro there are a few things worth mentioning: using Everything together with Launchy, and setting up Everything on a fileserver.

 

Everything on a (personal) fileserver

Everything can only index local disks. It does not index network shares or other remote locations (so NAS users are out of luck I suppose). However, you can run Everything as a service on a file server and have your local Everything client connect to this server. As an alternative, you could just run Everything on the desktop at the server, but that requires staying logged in all the time. In any case, you need to install Everything on the server and make it start an ETP server.

To install everything as a service, you need to follow these steps:

  1. Install Everything on the server
  2. Disable "run on system start". Go to the tools menu, click options. On the general tab, uncheck "Start everything on system start up", and click OK
  3. Open up a command prompt, CD into the folder where Everything was installed, and enter everything.exe -install_service
  4. This installs the server, but it does not set the command line option correctly: it only runs Everything as a service for the local computer (i.e., the server), but we want Everything to run as an ETP server. To do this, type the following at the command prompt: sc config everything binPath= "c:\program files (x86)\everything\everything.exe -svc -host" (replacing the path with your install path of choice, obviously).
  5. Stop and start the service (either through control panel or the geeky way, by issuing net stop everything (sounds kind of cool), followed by net start everything).

After this, configuration is done. Fire up Everything on another computer connected to the file server and use the option "Connect to ETP server" on the tools menu. I've had to use the IP number of my server since it did not do a name lookup, but I am not running any local DNS or hosts file, so YMMV.

Side note: Everything defaults to opening networked files on shares named after the local drive letters, so it opens the folder documents on the E-disk of the server as \\server\E\documents\. Not a huge problem, but something to be aware of. I have not found a setting in the INI file (old skool!) to change this.

 

Using Everything from Launchy

This next bit is directly from Lifehacker. Simply add a shortcut in a location that is indexed by Launchy, and use "C:\Program Files (x86)\Everything\Everything.exe" -search as the target. Name it appropriately (for example, "find") and re-index Launchy. Now you can type "find", TAB, and enter your search text. In order to do a search on your fileserver, make another shortcut, but add -connect 192.168.1.1 before the -search  option. I've named this shortcut "dfind", since my servername starts with a D.

 

I first read about Everything on the top 10 tiny & awesome Windows utilities at Lifehacker.

Tijmen 05:23, 1 June 2009

I've finally finished reading the excellent Working effectively with legacy code by Michael Feathers. It has been quite a struggle but that's merely because of the amount of useful information in it.

 

The author declares all code that is not under test to be legacy code. Ayende (author of Rhino mocks) basically based his mocking framework on the concepts in the book. Not surprisingly, he recommends the book as well.

 

I recently worked on an application written by another team that had zero unit tests. It did have a winforms test app included but that was merely for integration testing and required quite a bit of tweaking before anything useful could come out.

I started with isolating large chunks of functionality using Dependency injection with Unity. I then used StructureMap's automocker to bring most of the codebase under test (+80%).

Adding the required features was made much easier when most code was under test. This inspired me to throw a talk on TDD at meet the Masters in Microsoft at Avanade.

 

I´ll be hosting another talk about PEX next week and in preparing I will be diving into the book´s concepts. As most of these are written for either Java or C++, my focus will be around utilizing the same concepts in the beautiful world of .Net.

Tijmen 12:11, 26 May 2009

After Toms intro, I can't stay behind. I've been working in IT for about 10 years now, mainly working as a consultant for various shops, both large and small. Other random facts: I have a degree in Astronomy, a Norwegian forest cat, 2 daughters, I live somewhere between National Park "Utrechtse Heuvelrug" and de Veluwe and sometimes strike people as hyperactive (which I'm not).

My professional background started with developing line-of-business apps with MS Access. In that first year of my career I learned a lot about what problems businesses and business users run into, and the great part of using MS Access was that most projects had limited scope but surprising functional coverage: data modelling and entry, reporting, ETL, etc.

It also planted a seed for the urge to constantly improve as many things as possible about the "developer experience", for lack of a better term. By this I mean everything that influences the quality of code written and the efficiency of writing it: tools, guidelines, frameworks, even the keyboards in use

After this flirting with arguably one of the best RAD tools out there (yes, still talking about MS Access), I got involved on the Microsoft web stack, meaning classic ASP, VB 5/6, COM+, Windows DNA, that whole can of worms. Again, working with these tools, I always tried to come up with ways to reduce the pain and strain of developing software (and we had a lot of that in those days). This was also the time I realized that no, I wasn't that elusive consultant that can do everything perfectly: sure, I can design a user interface, but I'm no user experience expert. Fine, I know something about firewalls, protocols and tunneling, but I'm by no means an infrastructure guy. To cut a long story short: I learned to focus, to concentrate on specific skills to get ahead. I dabbled a bit in DBA roles, but at the heart I am a software developer with a slight tendency for web technologies.

Luckily for all of us, the world moved on since Windows DNA, and .NET has been upon us for quite some time. To accompany this framework, Microsoft has rolled out an impressive stack of server products to support all sorts of scenario's: stuff like BizTalk, SharePoint and SQL Server with all its BI bells and whistles to name a few. These days I often work as a solution  architect, which means I have to know a bit about most of these products, but again, they are mostly outside my focus zone. I continue to focus on the developer experience, trying to share both knowledge and enthusiasm along the way. Design patterns, principles like SOLID and DRY are high on my list of intended topics, but I also expect some less-focused (but equally interesting) ramblings on things I run across.