Wednesday, October 13, 2010

A Codefession

"Forgive me Father for I have sinned, It has been 3 iterations since my last confession."

I was brought up a Catholic and one part of being a Catholic is Confession. It's great! You do a load of bad stuff (sin), tell a priest,  he gives you a penance and then he absolves you.
Now that the slate is clean, you can do loads of bad stuff again until your next confession. (I think that's how it works).

When coding, I'm a good boy. I've read the various gospels. I even try and write my code so I don't give in to temptation. And, oh boy, there is temptation. The devil manifests himself in many ways.

There's the temptation to hack it together because you're going to fix it later. The devil knows this will never happen. The devil can be in the form of a looming deadline. You're under pressure and so your good intentions go straight out the window. The devil can be that you are working in an area or language that you are unfamiliar with.

Well I let the devil into my life the other day, I'm ashamed to tell you Father, I sinned. I wrote a real bit of untested, hacky code the other day. Just thinking about it makes me feel guilty. I fixed a defect but at the same time made that bit of code a little bit less maintainable. I broke the boy scout rule.

Ok...lets drop the metaphor. Programmer writes crap code under duress. Is this acceptable? Well, it depends. In an ideal world all my code would be written like an angry Agile Alliance was stood behind me with baseball bat but we all deviate from time to time, even Saint Corey! I think the most important lesson is to understand the reasons why you have strayed.

Be honest with yourself, why did this happen? What can you do to prevent this happening again? I've done my own retrospective, I guess this blog post is part of it. I know what went wrong and I hope I'll recognise the signs that it will happen again. And when I see those signs I hope I can do what I can to mitigate the circumstances that force me to right it.

I've pulled this into the sprint reviews too. When I've not achieved what I set out too, I want find the root cause. We've not being doing this and I've no idea why. After all, Scrum is not going to solve your problems, it’s just going to make them in-your-face obvious, every day. I've been thinking about XP values recently too. Without courage and communication and to a certain extent feedback we are setting ourselves up for a failure.

In the talk by Software Craftsmanship, Beyond The Hype, Corey Haines talks about when you have to get stuff done quickly you drop back to the skills you find instinctive. It takes time to learn techniques (such as TDD). Its a natural process. That's why practice and honing your technique are important and that's why just coding in work time doesn't give you the time and space to perfect your skills.

Ok metaphor back on.

Father: My child before I absolve you this is your penance. Say 20 Hail Ruby's and do 10 Our Katas.
Me: Thank you Father, see you next week!

Friday, July 16, 2010

Be more assertive when unit testing (and not when challenging me)

I tweeted this today.
A test without an assert is not a test. It leaves the intended behaviour as completely ambiguous.
Apparently I'm wrong. Some people disagreed. They were mistaken.
Let's examine their arguments.

Argument #1: Name the test method clearly enough and you don't need an assert?

public void Should_not_throw_when_doing_that_thing()
        var obj = new MyObj();
        var result= obj.doThatThing();       

To me this this has a huge gap missing in it. I'm a fan of the AAA pattern when constructing tests. Above we are only doing the Arrange and Act part.  This is why I'm not a fan of the [ExpectedException] attribute. There is no assert within the body of the message. It just doesn't read as I expect to be.

Argument #2: A test can contain no assertions, if you are mocking interactions.

public void WhenDoingSomeThingWithAnotherThingThatWillOccur()
    var someThing = MockRepository.GenerateStub();
    var anotherThing = MockRepository.GenerateStub();

    someThing.Stub(x => x.Do(1)).Return(2);

    new myObj(someThing, anotherThing).Do(1);


Ok this is a good point but when you are interaction testing you are still asserting that a behaviour is true. Its even there in the code.

As you can tell I'm not convinced. Can anyone provide a compelling reason to leave asserts out of tests?

Monday, July 05, 2010

Its more than your job's worth!

Recently I've been tasked with recruiting my replacement for my current employer. My worry is that the team will end up with someone who is just there to pick up a pay-cheque or a bumbling incompetent (yes another one, v funny).  As the position is to lead and support an ASP.Net WebForms app I wanted to test the candidate's ability in ASP.Net WebForms. I presumed that the candidate would jump at the chance of proving their worth prior to an interview.

Here's the test
A dating agency, CandyDate, is running a promotion for its members. 
It will provide some romantic food for one date that is set up for its members.

A date comprises of two people, the organiser and the guest, and a location. 

The Romantic food that the member can choose from is

Belgian Choccies

A member can only set up one date but can be an guest on any number of dates and the food must be chosen.

When an organiser submits his date there is a 1 in 4 chance he will also win one of 2 bottles of champagne.
After the 2 bottles have been won there should be no more chance to win the champagne (as there's none left)

The website is very simple (and trusting) so no authentication is needed. Each of the members have unique firstnames (for simplicity) allegiance 

Please construct a simple website to model this scenario in ASP.Net WebForms (vb or c#). If you do not have VS2008 handy you can use VS2010 express but please target .net 2.0 or 3.5   ( . If you need to use a db please use SQL2005 express or SQLlite. All other dependencies should be shipped with the website.

The "Date Form" will be a link off the main website so please start off with a dummy landing page.

All that is required is that you give the members the ability to enter the details of a date and a message (or page) to say the date has been submitted confirming the arrangements. A special message will be shown if the member has won the champagne.

Please do not leave the pages unstyled but don't spend hours on your colour schemes/fonts either. Simple is fine.

You shouldn't spend more than 2 hours on this test. 
I thought that the test was

  • very simple
  • open-ended to allow some creativity
  • show a rudimentary knowledge of , data access and simple logic.
Of the 12 candidates sent the test I had < 50% completion. I couldn't understand why I was getting so few back. These were keen, pre-screened (yes i used recruiters) prospects apparently. So tonight I made the test public and asked for the feedback on Twitter. Some of the comments were along the lines of:
  • Too vague
  • Too long description
  • Two hours is too long.
This surprised me. I kept things deliberately vague so people could create and yet I gave what I thought was enough information to keep them on the right track. I timed the test and did mine well within the allotted timeframe and in any case is 2 hours a lot of time to invest in your career? For over 50% people it was. I think the time issue is the one that gets me.

So I'm interested, after you've done your cv and after you've seen a job you wanted where do you draw the line at making the effort for your new role? I've never had a problem at launching myself at a tech test. I don't mind spending time on a panel interview. Even in failure I've learnt more about myself by going through the motions of applying for a role.

What is more than a job's worth?

Saturday, May 29, 2010

The case of the missing Tilde ~

The case of the missing Tilde ~

I've been looking at Ruby on Rails recently following the book Rails for .Net developers. This has meant I've been working in a Windows 7 VM in my Mac Book Pro. (I use the excellent Parallels). At some point in the book I had to use the tilde (~) symbol but the life of me couldn't find it as the tilde (~) key produces a pipe |. My Web Search skills failed me and there seemed to be nothing on the Parallels site but eventually I discovered it. So for the benefit of the next person to search I'm going to document it here. 

To type a tilde (~) in a windows 7 vm on parallels with a macbook pro you press:

SHIFT and §  

That's shift and the section sign symbol (§) which is the ±.

EDIT: This works for VMWare too.

Tuesday, April 20, 2010

Thoughts on Testing

I drew a picture with Balsamiq. Which is great. These are my current thoughts on testing.
Consider this blog part II of my SEO unfriendly series.

Thursday, April 01, 2010

Community Rocks

Apparently Microsoft gave out there MVP awards today. MVPs (most valuable professionals are described as such:
These exceptional community leaders come from a wide range of backgrounds. They are teachers, artists, doctors, engineers, as well as technologists, who actively share their high-quality, real-world technical expertise with the community and with Microsoft.
Inevitably there are people who don't get these award who deserve them. Those people that give their time and effort unselfishly for the benefit of others. Or those who want to have their efforts recognised but they've not quite made it.

I seem to be meeting more and more people that "actively share their high-quality, real-world technical expertise with the community" either through Twitter or sites like StackOverflow, the blogosphere or the user groups I attend. And that's ignoring the tons of excellent free open-source software. So I just wanted to thank you all. I don't care about your motivations whether they be completely altruistic or for the fact you're trying to jump up a notch in some imaginary ladder. Your engagement with me validates this sometimes difficult job. Thank you.

Friday, March 05, 2010

The case of the missing assert

I was looking at a friend of mines code late last night and he was writing his tests in MSTest. The test he wrote was an expected exception test.

        public void CanDoSomething_WithSomeThingThatThrows_ReturnsTrue()
            var something = SomeFactory.GetSomething();
            something.DoSomething(x => { throw new NotImplementedException(); });

            var result = something.DoSomethingElse<ISomeThingElse>();

I was tired, it was late, I'm used to a using different test framework but I got in contact straight away.
....spotted something in your codez. You're Assert is true everytime.
Of course dear reader you will have spotted the ExpectedException attribute as you, unlike me are not an idiot but my eyes see:
        [TEST BLAH]
        [yes i didn't spot the attrib here]
            //THIS IS IMPORTANT
            var result = something.DoSomethingElse<ISomeThingElse>();
            //AND SO IS THIS
In my semi-comatosed state my eyes fix on Assert.IsTrue(true) and I can look away from it. I'm used to NUnit's (and xUnit and mbUnit) Assert.Throws
        [TEST BLAH]
            //THIS IS IMPORTANT
            Assert.Throws(()=> something.DoSomethingElse<ISomeThingElse>());

However some frameworks don't support this. So you've got 2 options.
Option 1 Attribute and fail.
        public void CanDoSomething_WithSomeThingThatThrows_ReturnsTrue()
            var something = SomeFactory.GetSomething();
            something.DoSomething(x => { throw new NotImplementedException(); });

            var result = something.DoSomethingElse<ISomeThingElse>();

As my eyes always look the assert and so if I see a fail. I'll look to see why.
Option 2 No Attribute try catch
        public void CanDoSomething_WithSomeThingThatThrows_ReturnsTrue()
            var something = SomeFactory.GetSomething();
            something.DoSomething(x => { throw new NotImplementedException(); });
                var result = something.DoSomethingElse<ISomeThingElse>();
            catch (SomeException)
            catch (Exception)
And what happens when we want to invoke an action that doesn't expect anything. That you just want to run to see if doesn't fail. Well you've got Assert.DoesNotThrow in most .Net unit testing frameworks.
You can call the Assert.IsTrue(True);
        public void CanDoSomething_WithSomeThingThatDoesnotThrow()
            var something = SomeFactory.GetSomething();
            something.DoSomething(x => { throw new NotImplementedException(); });
Or just drop the assert.
        public void CanDoSomething_WithSomeThingThatDoesnotThrow()
            var something = SomeFactory.GetSomething();
            something.DoSomething(x => { throw new NotImplementedException(); });
So with MStest you can't use Assert.Throws but you do have options. Mine is to use another framework ;)

Friday, February 19, 2010

Git gotchas: batch deletes and single reverts.

Git is great and most of the time easy to use but there are some scenarios that I'm finding counter-intuitive.

Staging a group of deletes

if you have a load of files in a repository you want to delete (with some you don't wish to). It can seem a pain in the backside to delete them individually with the
git rm
Fileglobs may not be suitable and the '. -r' flags may delete more than you want.

The easiest way to deal with this is to delete the files from your local copy and call:
git add -update
git add -u
This flag does the following:
Update only files that git already knows about, staging modified content for commit and marking deleted files for removal. This is similar to what "git commit -a" does in preparation for making a commit, except that the update is limited to paths specified on the command line. If no paths are specified, all tracked files in the current directory and its subdirectories are updated.

Reverting or resetting an individual file

If you come from the SVN world to restore a file to its original state you would revert it. git revert does not do that. Perhaps you want to reset it? git reset does not do that either.
The command you need to use is
git checkout --filename
This checks out the original file from the repository again.

So remember to delete you add and to revert you checkout.
Intuitive my arse...

Monday, February 15, 2010

Micro Retrospectives for interruptions.

Internal interruptions for me come thick and fast. There are a few ways I deal with them, that help me.
  • Turn off email client,
  • Shutdown web browser.
  • Close all unecessary windows on my desktop down.
But for me they are still inevitable. I'll feel hungry or my mind will wander. Or I'll hear a conversation I want to join in.

When I have have to abandon a pomodoro I conduct a mini-retrospective.
  • Why did I abandon the pomodoro?
  • What can I do to prevent this happening again?
So if you get distracted by email. Turn it off. If you are interested in a conversation put headphones on.
If you ended up surfing the web, shut down your browser.

Thursday, February 11, 2010

Developer recruitment is broken.

When looking for a new job in software there seems to be little choice other than to go through a recruitment agent these days. You may get lucky and someone may approach you or you may find a company you want to work for and they may have an opening but most of the time it seems you are stuck with using these agents.

The Status Quo

Currently the finding a new job lifecycle:
  1. Want new job
  2. Go to your favourite job web site
  3. Add in relevant keywords Click go.
  4. Find several jobs that you may be interested in
  5. Discount ones that you have applied for before.
  6. De-duplicate the ones from the same recruiter that are written slightly differently.
  7. De-duplicate the ones from different recruiters that are for the same role.
  8. Chose one for job with highest salary.
  9. Speak with recruiter who inevitably says that that position is filled. 
  10. Recruiter will try and fit you into any other job that he can possibly can. Enticing you with promises of working with 'SilverLight MVC' or that the company is 'recession proof'. Recruiter will more often than not refuse to give you name of company.
  11. You will pick the most awesome sounding role.
  12. Either your cv will get rejected and you won't hear anything from the recruiter. Start again. Or..
  13. Goto interview. Job is not what you want. They love you though (or are clutching at straws)
  14. Tell recruiter thanks but no thanks. Recruiter uses hard-sales techniques and threats of violence.
  15. Begin to run out of money/will to live.
  16. Accept role.
  17. Start job and work for n months.
  18. become unhappy at work. Start again

What is wrong with that?

There is a huge signal to noise ratio of phantom jobs. You waste time and effort applying so that recruiters can harvest your details. Recruitment agents have a vested interest in keep the name of the company you've applied to work for, from you. So how do you know what you are applying for? There seems to be one common factor.

The Recruitment Agent

I am confident I could have this role filled within 2 weeks for you (From sending the CV’s, interviews taking place to offer being made) -quote from recruitment consultant
Lets look at the purpose of a recruitment agent. A recruiter sits between candidate and employer and will sort the wheat from the chaff. He/She will use their resources to find the right people for the right job. Brilliant but with market forces/greed/targets coming into play something has gone wrong. Most recruiters are target driven they get paid to place developers in roles. Consequently when there are no right people for the job the recruiter goes unpaid. So what do they do? They select the almost right people for interview. When they run out, they select the wrong people. A recruiter must produce candidates to be seen to be effective. This means that the larger the candidate base the better. If a recruiter has N candidates and N is large how can they know all their candidates? They can't. So they rely on playing cv bingo.
  • Employer says he needs asp client has (Bingo!). 
  • Employer wants JavaScript candidate has Java (Bingo!).
  • Client wants experience, candidate has 5 years Silverlight (Bingo!)
The recruiter doesn't get paid more for knowing the industry better, they get paid more for placing more people in more roles. In fact they get paid more for placing the nearly right people in more jobs that aren't quite right more often. Their ideal candidate is a brilliant interviewer who likes to move on every couple years and has mastered the art of bullshitting in acronyms. This gives the impression to the company that they are doing a great job of finding people in a difficult market. A candidate who is placed 3 times in 5 years is more of an asset from a recruitment point of view than a great developer who stays in a role for 5 years. So even if a recruiter feels that the candidate is not going to stay in the job long there is no financial motivation in dissuading a candidate, the motivation is placing the client.

Changing the model

As a prospective candidate I want a way to find out where the 'good' dev teams are in my area. I want to be able to say 'Hi, I'm interested in working for you.'
As an employer I want to say 'Hi, we do some great stuff and you should come work for us.' The current system does not support that. What can be done? Here are some alternatives:

Remove the middle man

Why do we need these agents in the first place? They create a closed marketplace. Candidates should just apply on spec to companies and tech companies should do a much better job of promoting themselves.

Candidates pay the agent

If the candidate paid the agent to find a job say with a small amount upfront and a satisfaction payment 6 months later. Perhaps the recruiter would take more care that the candidate was a better fit.

Appraise recruiter performance on candidate performance

The model is obviously broken. Why are we paying recruiters just to place. We should be rewarding them to screen candidates too. I'm mean this is why they are here in the first place, isn't it? Employers should be employing these people with a service charge. So you want to recruit someone but don;t want to sift through 1000s of candidates? Pay someone for that, don't pay someone to place as quickly as possible.

Monday, February 01, 2010

DDD8 Round up

I've just arrived back from the DeveloperDeveloperDeveloper 2010 aka DDD8 Conference in Reading and had fantastic time there. The conference was situated on the Microsoft campus but was organised by the .net development community for the development community. There were no major vendors (including Microsoft) shoving their products down you throat and the events chosen were voted in by the public.


Registration was opened a couple of weeks before the event and the 300 and something places were snapped up in an amazing 12 minutes! This must be frustrating for the many developers who wanted to attend but were not quick enough to register. There seemed to be issues with the emailing system which left some confusion with delegates not knowing they were registered or not. Those people on the waiting list had to wait but many of those on the list eventually got in (I spoke to someone who told me he was over 150 places away). It seemed a little unfair that early birds got all the ticket and I hope the team will introduce some sort of ballot system next time.

The Venue

The sessions were held within 4 rooms Chicago 1 and 2 were separated by thin divider, Memphis upstairs and Everest in another building. All rooms were of a good size and even when sat at the back I was able to enjoy each of the sessions. The main issues I found were that Memphis was a sweltering and stuffy room and that sometimes the sessions in Chicago 1 were so loud they would distract the Chicago 2 talk.
As the venue was in the middle of bloody nowhere we had to set off at 4:30 in the morning! (Note: the centre of the earth is in Manchester and therefore all events should be within a 1 hour drive from there)

The Sessions

Unfortunately I couldn't see everything (I've not been able to master replication - yet) so I can't comment on all the talks but talking to other delegates I got the impression that most of them were pitched at an introductory level. I realise that the community voted the events in but there seemed to be nothing that covered a subject in depth. I mainly went down the testing route as I am looking at that side for my msc dissertation so missed a couple of others I really wanted to go to. I'll go through the ones I attended.

Mark Needham - Mixing functional and object oriented approaches to programming in C#

Mark Needham's talk was on his experiences using functional aspects of c# (LINQ) as his approaches to master it. He talked about the strength's of functional programming and the strengths of OO and how they should work together to create readable and maintainable code. He then went through the basic LINQ methods and drew parallels with the Functional Programming world. (Map = Select, Filter = Where, Reduce = Sum) and talked about taking things one step at a time. We got then into some code examples from the wild which were interesting to listen too.
  • DRY and LINQ
  • Extract method and LINQ
  • Functions into Maps
  • Patterns as functional language.
This was a great talk. Mark is obviously a great researcher and it was a fantastic run through. A promising start to the day. He has put his slides online.

Andrea Magnorsky - Lessons learned on Unit Testing

Andrea's talk was an all energy affair on unit testing, heavily influenced by Roy Osherove's book The Art of Unit Testing. Andrea's style was engaging as she took us through test naming, mocking, stubs, fakes, dependencies.  Tests should be trustworthy maintainable and readable and being careful is the key.
It was a good run through and one of the sessions I enjoyed the most. If there was any criticism to give I think Andrea got her timing a little wrong (she skipped a few slides) and that 'dupplication' has only one p. :) She has now blogged with links to her code and thoughts.

Andy Gibson - Web Application Testing With Selenium

Andy's talk was a walk around the UI Testing framework Selenium up in the stuffy Memphis room.
The aim was to introduce the novice into Selenium and Andy's talk tried to cover a lot. (perhaps too much). It seemed from his talk that the framework is huge and the he seemed to position himself as an expert in all. It may have been better if he had done the talk in the 'this is how I use Selenium' style rather than the 'this is you to use Selenium'. Still it was a great to see Selenium in action.

A special mention goes to Craig Murphy who read my tweet asking for water and delivered some to me mid-talk :).

Kris Athi -Microsoft Surface

By this stage I was well and truly frazzled so I decided to go and see something pretty to recharge the braincells. Surface looked the the perfect talk. I'd just sit there dribbling and look at all the pretty graphics. Sadly I was disappointed. Kris's talk was on the Surface SDK but he didn't even have a surface. C'mon guys there is a Surface room apparently on the MS Campus so I was sorely disappointed that we didn't see one in the flesh. Kris went through the SDK talked a little about the design issues and showed us some code. The surface looked good but I expected to be wowed by an awesome demo app.

Ben Hall - Testing C# and ASP.Net applications using Ruby

The last session block I could have seen any number of talks but after much deliberation I ended up in Ben's. Ben Hall's talk began unconventionally with Barry Dorran's hijacking the speaker system to wish Ben a happy birthday. After that Ben started to talk about the benefits of Ruby's expressiveness in tests and using BDD style specs to make intent clearer. He talked about all the different levels of testing and where things. This talk really complimented the other talks I went to that day and it was great to see a DSL like WebRat firing Selenium. A very enjoyable talk. Ben's slides are available on his blog.

The Rest

It was a brilliant day. I met a million people who I've spoken with on twitter and missed a million people who were there and I didn't meet. I just want to say a big THANK YOU to the organisers if everyone got as much out the day as I did then you should be proud of yourselves. Can't wait for the next one!

Friday, January 22, 2010

| or ||? (or Or or Or?)

This is part 1 of my new SEO unfriendly series. I will be writing posts with un-searchable headings

I've just finished a code review with a colleague who's 1st language is not c#. As part of his solution there were several lines like this:
if (conditionA | conditionB)

Without even thinking about it I have always used the || (unless I want to do a bitwise operation).

Lets just clarify what | does. It a bitwise comparison for integral types e.g. (byte, int, etc..) and for bool types it performs a logical OR but checks both operands.

Most languages I've used short circuit the second check if the first check is true. If your condition has side-effects you need to be very careful.

Consider the following program:
namespace OrProgram
    class Program
        static void Main(string[] args)
            if (ConditionTrue() | ConditionFalse() )
                Debug.WriteLine("Outcome was True");
                Debug.WriteLine("Outcome was False");

            if (ConditionTrue() || ConditionFalse())
                Debug.WriteLine("Outcome was True");
                Debug.WriteLine("Outcome was False");

        private static bool ConditionFalse()
            Debug.WriteLine("ConditionFalse has been called");
            return false;

        private static bool ConditionTrue()
            Debug.WriteLine("ConditionTrue has been called");
            return true;

With the | operator you will get the output:
ConditionTrue has been called
ConditionFalse has been called
Outcome was True

With the || operator you will get:
ConditionTrue has been called
Outcome was True

So if you need to make sure both sides of the operator are called you can use the | operator but it would be much clearer if you did:

var isTrue = ConditionTrue();
var isFalse = ConditionFalse();

if (isTrue || isFalse)
    Debug.WriteLine("Outcome was True");
   Debug.WriteLine("Outcome was False");

That is all.