Resharper Updater for 5.0 EAP

October 20th, 2009

I’ve updated the Resharper Updater to support the 5.0 EAP that has just started.

There are some new features such as seeing the last 10 builds on the EAP from the taskbar. This way if you’d like to install a highly rated build from a couple days earlier that can be done quickly.

RUpdater001 

Enjoy,

Resharper Updater 1.3

Uncategorized 2 comments

Company culture affects your code

April 8th, 2009

If you produce bad code now you can blame your boss. Well at least there’s some research you can use to justify that reasoning.

According to Conway’s Law

Any organization that designs a system will inevitably produce a design whose structure is a copy of the organization’s communication structure.

Have you ever thought about how much your company culture affects how you code? I do make a bit of a leap between a communication structure and the company culture but I’d argue that they’re the same.

Not long ago I was under the reigns of an evil manager. It was a waterfall project so it was doomed from the start but I was naive. I would work long hours and the manager would ask me to work late everyday.

quality

The software we produced was

  1. rushed
  2. full of bugs
  3. had poor solutions that weren’t thought out
    That was my last poorly made piece of software but I bring it up so we can be realistic about the culture in which we build software. Can you think of examples where different cultures have been reflected in the software you make?

At sportinginsider.com we’re a splintered group of developers spread from London to Seoul. We communicate over skype and IM and meet in person every few months. Without collocation its a lot of work to keep communication happening. The communication we have is generally high latency since we’re overlapping at different times during the day. What we produce reflects this broken nature of our communication by separating concerns with SOA and plug-in support.

the quest for quality is a good thing. the quest for perfection gets you no where

Uncategorized No comments

Building plugins with NAnt

April 8th, 2009

I’m a big fan of using convention to simplify your build process and its really easy to do. I’ll show that with a snippet from our NAnt build file which is a target that builds each of our plugins.

the convention I’m using is that

  • each plugin is in folder named Something.Addin
    In order to compile each plugin into a seperate dll we use the foreach Task.

the property addin.name will contain just the folder name “Something.AddIn” instead of the absolute path that we get from the foreach Task.

I’m using Mono-Addins to provide plugin support to the application which I’ll cover soon.

<target name="-addin-compile">
  <foreach item="Folder" property="folder">
    <in>
      <items>
        <include name="${sources.dir}/*.addin"/>
      </items>
    </in>
    <do>
      <property name="index" value="${string::last-index-of(folder, '\')}"/>
      <property name="addin.name" value="${string::substring(folder,int::parse(index)+1,string::get-length(folder)-int::parse(index)-1)}"/>
      <echo message="Compiling ${addin.name}"/>
      <csc target="library" output="${deploy.dir}/${addin.name}.dll" debug="false">
        <sources>
          <include name="${sources.dir}/${addin.name}/**/*.cs"/>
        </sources>
        <references>
          <include name="System.Configuration.dll"/>
          <include name="${deploy.dir}/mlb.aggregator.common.dll"/>
          <include name="${lib.dir}/mono-addins/*.dll"/>
          <include name="${lib.dir}/log4net/mono-3.5/log4net.dll"/>
          <include name="${lib.dir}/xstream/*.dll"/>
          <include name="${lib.dir}/nhibernate/*.dll"/>
        </references>
      </csc>
    </do>
  </foreach>
</target>

every project has conventions, not every project uses them

Uncategorized No comments

Twitter notifications with TeamCity

March 27th, 2009

I was surfing Stackoverflow when I saw a request for a Twitter Notifier for TeamCity from Lance Fisher. I decided to implement it because I’ve always been a big fan of how last.fm use IRC to do notifications and queries. Last.fm puts everything up on IRC there from Jira issues, builds, hosting alerts and more.

twitter is the new IRC

If you use to spend time on IRC you know it feels very similar using twitter. Using private accounts we can keep our companies notifications both restrictive and accessible. At our company I’m starting to get interested in more notifications so I can keep track of how what’s happening company wide.

What you’ll need

  1. Twitter TeamCity Notifier
  2. TeamCity
  3. Java 1.6

google code project

The default install of TeamCity installs with Java 1.5 so you’ll want to update to 1.6 if you haven’t already. You can do this by installing the JRE and then copying it into the c:\TeamCity\jre dir.

to check what version of java TeamCity is using try this command

c:\TeamCity\jre\bin\java.exe –version

After you install Java 1.6 you’ll want erase the contents of c:\TeamCity\jre and replace them with the jre folder that you can find under C:\Program Files\Java\. In my case the folder was C:\Program Files\Java\jdk1.6.0_10\jre

Installing Twitter Notifier

  1. extract the zip into C:\TeamCity\webapps\ROOT\WEB-INF\lib
  2. restart the teamcity service

Configuring your notifications

login to teamcity and goto My Tools and Settings

ttn-01

here you’ll see some boxes to enter your twitter account.

ttn-02

If you click edit you can specify the rules for the notifications

ttn-03

make sure you select all projects and tick off conditions you want to send tweets for

ttn-04

Notifications in action

Now when I trigger a build it notifies twitter.

ttn-05

Don’t worry I’m going to add fields that let you customize messages in the future.

Communication is harder when your distributed

Uncategorized 5 comments

Downloader for Resharper Nightly Builds

February 13th, 2009

If you use Resharper your probably a fan of getting the new features early with the Nightly builds. Now with 4.5 stable enough to develop with full time I thought I’d cut down on my daily ritual of downloading the latest nightly build with a little app to do most of the work for me.

Resharper Updater checks the website behind the scenes for you and changes the icon to one with a star when there’s a new version, so all you have to do when you come in in the morning is close studio and update to the latest version.

You can download it here resharper-updater-1.0.zip

Using Resharper Updater

There’s two ways to access the install

right click for the menu

13-02-2009-14-28-27

If you have resharper installed it will tell you there’s no new version

13-02-2009-14-28-51

If you Check for update it will tell you what build is available and the icon will change

13-02-2009-14-33-48

Otherwise if you choose Check and Install or you double click on the icon it will check,download and run the installer.

13-02-2009-14-34-51

There’s definitely room for improvement but this is the bare minimum before I could release it.

Automating your day

Uncategorized No comments

Reusable Build Scripts

February 10th, 2009

246357466_cba52d3fc5

I started last week at Open Space Coding Day 1 and I had builds on my mind. I proposed a lot of different topics to code one but reusable build scripts picked up a bit of traction. I ran a quick tutorial on how to get an application compiling and tests running. We used NAnt because that’s what people wanted to learn but there’s plenty of alternatives including Powershell, Rake and MSBuild.

Here’s the repository from our session:

reusable build scripts subversion

When I first started off with build scripts it didn’t take long before they got ugly. Your build script goes from a simple compilation to a monstrous 1000 line file if your not careful. I remember adding all kinds of email notifications and deployment steps that I ended up cutting out during the hand over. I recommend if your new to build scripts and NAnt to read through with JP Boodhoo’s NAnt Starter Series which is a really good starting point.

The main tips for simplifying your build scripts are

  1. remove application specific information to a common properties file
  2. separate out common targets into separate files which you can include (ie: tests, compile, deploy)
  3. keep it simple

I maintain a number of projects for a data mining job and it started to bug me how across different projects on a few scattered lines of the build changed. Even after the tips I mentioned you can still find that you have application specific configurations in your build.

The problem I had was I was repeating myself in the build script and that defeats DRY. The steps I was taking were:

  1. compile all the .cs files in my source dir
  2. manually set the references for my project
  3. copy the referenced DLLs into the output directory

It doesn’t seem like much but anytime you add a reference you need to edit the build file. It ends up looking like this.

    <csc target="library" output="${dir.deploy}/sample.core.tests.dll" debug="true">
      <sources>
        <include name="${dir.src}/*.tests/**/*.cs" />
      </sources>
      <references>
        <include name="${dir.deploy}/sample.core.dll" />
        <include name="../thirdparty/tools/mbunit/MbUnit.Framework.dll" />
      </references>
    </csc>
    <copy todir="${dir.deploy}">
      <fileset>
        <include name="../thirdparty/tools/mbunit/MbUnit.Framework.dll" />
        <include name="../thirdparty/tools/mbunit/QuickGraph.Algorithms.dll" />
        <include name="../thirdparty/tools/mbunit/QuickGraph.dll" />
      </fileset>
    </copy>

The benefit of using csc over msbuild is that it lets you use the Mono Framework just by setting the target framework at command line.

The other problem with this approach is that mono needs reference DLL’s compiled for Mono like MySql Connector and Log4Net.

Cowan.Commons.Nant.ProjectsTask

My solution was to take all the logic I was repeating and put it into a custom task called ProjectsTask. It allows you to use wildcards to specify your projects to compile, which is not supported by SolutionsTask. This task uses XPath on each project file to retrieve references,resources and the project name.

<projects outputdir="${target.dir}">
      <fileset basedir="${sources.dir}">
        <include name="**/*.csproj" />
        <exclude name="*.tests/*.csproj" />
      </fileset>
</projects>

To fix the mono reference problem I’ve included references for both mono and .net in my lib folder but only referenced the .net dll.

\lib\log4net\net-3.5\log4net.dll
\lib\log4net\mono-3.5\log4net.dll

when you compile with mono it notices the net-3.5 directory and tries and finds a mono directory beside it. A new addition to NAnt is that it’s no longer sensitive to OS specific path seperators like / or \.

I still need to specify the build configuration (ie:debug or release) but it’s really simplified things for me.

you can see the code here

Work Smarter not Harder

Uncategorized 2 comments

Using Fluent Interfaces

February 6th, 2009

A couple weeks ago I was mentioning a training I did at Concentra. Well here’s the codebase that came out of the three days of training.

You’ll need a subversion client to checkout the code (like tortoiseSVN)

http://sleepoverrated.googlecode.com/svn/2009-01-14-Training_Codebase

Fluent Interfaces

Fluent Interfaces are are a way of writing code in which its more readable. Wikipedia uses the example of having a method return its class so you can add up a series of method calls like this.

new ConfigurationFluent().SetColor("blue")
                                           .SetHeight(1)
                                           .SetLength(2)
                                           .SetDepth(3);

The preparation exercise was to create a Movie Library that allowed us to search and sort in an number of different ways. We used the specification pattern to search thru an in memory collection. For searching moved towards a way of having a Linq like query syntax that let us select all the movies of different criteria. You can see some examples of this used in MovieLibrary.cs

Here is an example of how we used Movie.is_of_genre to search for all the action movies in our library. The Search Criteria is built up as a Specification and then checked for each movie in all_movies() by satisfied_by()

        public IEnumerable<movie> all_action_movies()
        {
            return all_movies().satisfied_by(Movie.is_of_genre(Genre.action));
        }

Looking at Move.is_of_genre() in Movie.cs we can see the Fluent Interface we created for created a Specification to check if a Movie has a genre that we specify.

        public static ISpecification<movie> is_of_genre(Genre genre)
        {
            return Where<movie>.has(x => x.genre).equal_to(genre);
        }

this is our fluent interface that we developed for querying. I recommend you look thru the code for this.

How would you write this?

When writing Fluent Interfaces you want to just write some code to do the thing you want to do in the way you want it to look. Then you have to figure out some way to make it compile. You may have to change your code around to get it to work.

Implement classes in reverse

You may naturally feel like implementing the Where class first but the one thing you know is what has to be returned and that is the responsibility of the last method.

  1. equal_to needs to return an ISpecification<movie>
  2. Where.has() needs to return a class with an equal_to method

We named the class returned by Where.has() as SpecificationBuilder<T,TOutput>. The x=> x.genre is passed into the new SpecificationBuilder in the constructor as a Func<T,TOutput> property_accessor. This Func is a function we call that takes in a Movie and returns a Genre if it was a delegate it would look like

        public Genre property_accessor(Movie movie)
        {
            return movie.genre;
        }

The great thing with C# generics is that it actually infers the TOutput type of genre in from the lambda x => x.genre. I barely noticed this ability until I started using Generics in Java. It is easier to just do this in Linq and there are some examples of that in MovieLibrary.cs but it’s a challenging exercise to try.

Doing things differently teaches you different things.

Uncategorized 2 comments

Getting started with Boodhoo BDD

January 28th, 2009

Boodhoo BDD is a set of libraries that abstracts Rhino Mocks and MBUnit to give you an easy way to write BDD Specifications (a readable form of unit tests).

I’ve been using JP Boodhoo’s BDD helper libraries on a few projects and I’ve seen my tests become documentation because they’re more readable. I’ve been using it to set up our development team with application modules in a design by contract methodology. Which means that tests are in place first to provide a high level contract of the inputs and outputs of the class.

I’ll be covering this again in a grok talk tonight at the LDNUG but consider this a thorough transcript.

Definitions

  1. BDD – Behaviour Driven Development
  2. AAA – Arrange-Act-Assert syntax testing
    Here’s all the components you need to start developing using Boodhoo BDD.

jpboodhoo.bdd

helper libraries which give you a fluent interface to rhino mocks and mbunit so your interaction with these frameworks are abstracted away and readable.

you’ll need the following references to take full advantage of all the extension methods and reporting functionality of bdd doc.

jpboodhoo.bdd.dll
jpboodhoo.commons.core.infrastructure.dll
bdddoc.core.dll

checkout the latest version from http://subversion.assembla.com/svn/jpboodhoo_bdd with a subversion client like tortoisesvn

or you can download a build from here

here’s all the using statements you’ll need

using bdddoc.core;
using jpboodhoo.bdd;
using jpboodhoo.bdd.concerns;
using jpboodhoo.bdd.contexts;
using jpboodhoo.bdd.core;

first we need to setup all the concerns for our movie repository, this is where we would setup and dependancies and override the MovieRepository constructor if is need to inject anything.

public abstract class concern_for_movie_repository : observations_for_a_sut_with_a_contract
    {
    }

and the specification looks like this

    [Concern(typeof (MovieRepository))]
    public class when_all_movies_are_asked_for : concern_for_movie_repository
    {
        static IEnumerable results;

        static concern c = () => {};	

        static because b = () => results = sut.All();                                

        [Observation]
        public void should_find_a_movie()
        {
            results.Count().should_not_be_equal_to(0);
        }
    }

the main points are

  1. Concern is a MBUnit TestFixture
  2. Observation is a MBUnit Test
  3. sut is a MovieRepository which is created in observations_for_a_sut_with_a_contract based on the Generic type.
  4. concern,because and any fields need to be static
  5. a concern in concern_for_movie_repository will run before the concern in when_all_movies_are_asked_for

Here’s some more thorough examples to get you started

  • Test examples with MBUnit and jpboodhoo.bdd
  • How I’m Currently Writing My BDD Style Tests – Part 1
  • How I’m Currently Writing My BDD Style Tests – Part 2

    AutoHotKey BDD naming

    A script for AutoHotKey which replaces the spaces you type with underscores so you can quickly describe your behaviours in a underscore naming convention. You use Ctrl-Shift U to turn this off and on and there’s a tray icon to tell you if its on or off.

    After you download the

    BDD Doc

    BDD Doc is the report generator of this package. It uses the Concern and Observation attributes that we used above and generates an html report to show you which Concerns are behaviours of which Objects.

    If you have an MBunit test report you can include the results in the BDD Doc report too.

    you can checkout bdd doc here with a subversion client

    http://svn2.assembla.com/svn/bdddoc

    or download a build here

    Here’s how you call BDD Doc at command line.

    bdddoc.console.exe tests.dll TestAttribute SpecReport.html test.report.xml

    and here’s what the SpecReport.html report will look like

    bdddoc_report

    Resharper Templates

    File Templates are Live Templates allow you to insert new files and do code insertion with aliases. Its not needed but its definitely useful for developing faster.

    download live templates

    you can import the live templates by going to Resharper > Live Templates and clicking on the import button below.

    bdd-livetemplates01

    Welcome to a world with readable code.

  • Uncategorized 4 comments

    First training course of the year

    January 16th, 2009

    borough market

    Last week I taught my first course of the year for Concentra. I have heard some horror stories about running internal training courses but I really enjoyed it. It’s definetly a cool place to work, there’s some smart people there.

    I used an evolutionary teaching style where we started writing raw C# code without LINQ and moved towards third party libraries like log4net, NHibernate and ASP.Net MVC. There was just too much to cover and really It should’ve been the original 5 day course I had planned.

    I find that teaching really makes you need to know what your talking about. Most of the time you are not writing infrastructure code and to be able to start an app from scratch lets you reassess how you do things.  I have a big crush on Iteration 0 efficiency there’s so much to setup and if you start into app code prematurely you end up working with a handicap.

    Here’s the outline of what we managed to cover, I will be posting code shortly.

    Day 1

    • Refactoring
    • TDD
    • BDD
    • Team System
    • IComparer<T>
    • Paired Programming
    • Delegates
    • Predicate<T>
    • Specification Pattern
    • Strategy Pattern
    • Lambdas
    • Searching and Sorting on Collections
    • Fluent APIs
    • Rich Domain Model
    • Barebones Data Access

    Day 2

    • Refactoring Data Access
    • Factory Pattern
    • DBProviderFactory
    • log4net
    • Service Layer Pattern
    • Mapper Pattern
    • Repository Pattern
    • NHibernate
    • Detached Criteria

    Day 3

    • ASP.Net MVC
    • JQuery
    • AJAX calls with JQuery
    • Scrum
    • User Stories
    • Kanban
    • Dependency Injection
    • Rhino Mocks

    Uncategorized No comments

    How Did I Get Started In Software Development?

    July 15th, 2008

    JP asked me to to post how I got start in software, so if you want to know my favourite colour or whatever that’ll have to be another post.

    How old were you when you first started in programming?

    I’m not too sure but I must have been about 8 or 9 years old. I probably would have done it earlier if I had a computer with basic on it. The one thing that was worse than having a computer that took cassette tapes was having a broken play button on the cassette deck.

    What was your first programming language?

    Our Neighbour had a Apple II and I would be over there playing games all the time. One day we found a book for Apple Basic and it had a cool looking game in it so I proceeded to type out all the sample code they had for it so I could play it. It never worked but I soon followed that up with an application just as complex.

    10 PRINT "Something Funny in the 80s"
    20 GOTO 10
    RUN

    For some reason the next language I learned was Motorola 86000 Assembly.

    What was the first real program you wrote?

    The first real program I wrote in school was a hockey pool program. It was a team project and I was doing the UI. Everyone else was doing text only apps on the mac but I managed to add menus and normal GUI stuff and the best part was if you tried adding a menuitem outside of the menu array it completely destroyed the computer. Who would have known that you’d need to reinstall your OS from a bad line of code you wrote.

    What languages have you used since you started programming?

    In order of apperance
    Basic,Turbo Pascal,C++,Perl,Modula-2,Visual Basic,PHP,Java,ColdFusion,C#,VB.Net,Ada,Python

    I also did assemble for a bunch of different platforms
    Assembly for 86000,PIC 16F84,Z80,Allen Bradely PLC5, Motorola 68HC11, C/ASM on TI C67x DSP

    What was your first professional programming gig?

    At a company called IQLinux.com, we were making the Ebay of Services. It sounded great but we ended up suffering from Feature Creep so much that the site got way too complex. We were working out how to do dispute arbitration before we even had users. I ended up sticking around to the point where we had moved into the basement of the founders mothers house. I still work with one of my colleuges on another project.

    If you knew then what you know now, would you have started programming?

    Of course, if I didn’t enjoy what I was doing I’d do something else. I started out in Electrical Engineering but realized that product development was way too complex and software allowed you to do new things really quickly. I guess I just want to be able to make an impact on the world around me and I didn’t see that happening in hardware.

    If there is one thing you learned along the way that you would tell new developers, what would it be?

    People skills are equally as important as technical skills. Just because someone has been in the industry for 10 years doesn’t mean he’s got any experience. He may just had 1 years experience 10 times. Your education doesn’t stop when you graduate, thats when it begins. If your lucky your university actually taught you about software engineering, my university did not and I was in a software engineering program.

    What’s the most fun you’ve ever had programming?

    Working for a startup, It’s very cool to start out without the years of management overhead that you get at a large company. Too much freedom can kill you but It’s nice to be able to see what isn’t working and be able to change it. I love being given broad requirements and coming up with the solution to achieve them. It defers a lot from consulting gigs where you show up and everything is mostly planned out and you just have to implement.

    Who am I calling out?

    Micheal Foord
    Ben Hall
    Zi Makki
    Andrew Myhre

    Uncategorized No comments