Homepage | About Me | Testing ASP.net Book | Best Blog Posts | Personal Projects | Follow me on Twitter | GitHub | SlideShare | RSS
Blog.BenHall.me.uk

Why consistency is overrated

Monday, February 15, 2010

I've recently had a number of discussions with various different people around consistency.

There a few really good reasons why you should be consistent in your development approach. Being able to pick-up a code-base and understand where the tests are, where external libs are stored\reference and how to build and run are fundamental when you work on more than one project. In a similar way, being consistent with setting, both application and keyboard (ReSharper) can increase productivity when working with a team as it makes it easier to share the code and pair at different machines. Having a standard and a foundation gives you the base to improve and learn from. Toyota have said “standardized tasks are the foundation for continuous improvement and employee empowerment” Wikipedia.

However, this brings about another problem. If you are continuously improving, what happens to consistency?

Many moons ago, we were all writing our data access logic using Ado.net and code-generated ORMs. Thankfully today we have NHIbernate. We have taken a standard, improved and progressed beyond it to create a new standard. This is why consistency is overrated. If we were consistent, we would had kept making the same mistakes for the sake of being consistent. The same can be said for unit testing frameworks, languages and even project structures\coding style.

However, in software many people forget the improve and progress part once a standard has been set.  We sacrifice improved productivity and adding value to the business to maintain the status quo. How many developers would push the use of frameworks like OpenRasta instead of just going with ASP.Net MVC because they did ASP.net webforms before - even when OpenRasta provides a much better solution to their problem. Or use WCF because “we are a Microsoft shop”, hence must be consistent and use the Microsoft stack.

Get a grip.

Forget consistency. Instead, focus on what makes you productive, what provides value and what makes doing your job easier. If there is a better way, do it and break free from the status quo.

Labels:

Why GPS systems are a metaphor for software development

Sunday, February 14, 2010

A while ago I was on my way to see family members. Due to working all the time, I was unfamiliar with the route so I used my GPS. During the journey I had a brainwave, a good GPS system is like a good software development team.

Imagine the roles involved in a car journey. We have the nice GPS lady, the one who knows the final result and the most effective way to get there. We have the passengers who do the work together with the backseat drivers who think they know better than everyone else involved and will take you in a different direction.

This is very similar to the structure of most project teams. Everyone knows the final destination, and some might even know how to get most\part of the way there however we have project managers guiding us along the way, step by step, even if sometimes they are just background noise telling you what you already know. We have developers\testers taking the information from the project manager and applying it using their own skills. The GPS doesn’t drive the car in the same way project managers don’t write code. Finally, we have the members of the team who always seem to know better - these are either visionaries or bad apples.

As you are driving, when you are coming up to a change in direction the GPS will tell you just enough information to put you in the best position to act when the additional information is relevant instead of overloading you with unnecessary and confusing the problem right at the beginning. As the steps are broken down and told as required, if you go wrong then the GPS can adjust itself and guide you back. These could be consideration iterations.

What if the journey wasn’t broken down into steps? You would know the end route, however you wouldn't know the quickest, or even how, to get there. Instead you would be flooded with information as soon as you enter in the car. You will be told every turn taken, every lane change. During the journey, you will attempt to remember everything, as a result relying on other indicators such as traditional sign posts. The problem is that you can easily miss a critical step and take a wrong turn. Without someone guiding you, you could be going in the wrong direction for a long period of time. This is the equivalent of a waterfall project and we all know how they end. GPS systems take an agile approach to car journeys.

But I only have a cheap GPS systems. The good (ie expensive) GPS systems respond to the environment around them.  They can sense (be alerted) to traffic ahead and as a result take a different route to ensure you get to your end goal in the most effective way. This is why you pay twice as much, as when problems occur, they can help instead of just sending you down the same old path.

I think this is the same as a good project manager. If they can see the problems coming, then they can guide the team without the team ever knowing or being distributed. This allows the team to stay focused and motivated while the project manager does the hard work of ensuring any problems don't affect the project. This is a powerful and extremely useful position and person to have. This is when both GPS systems and project managers justify their cost.

But what if you crash? Well your project just got canned and no matter how good your GPS\pm is they can't help.

Interesting what comes into your mind during a car journey.

Labels:

Changing Resharper 5 to support Bdd_style_test_naming

When creating test names, I use a BDD style naming convention to describe the behaviour being tested. As such, I like the naming to be in a particular, consistent style. For example:

image

However, as you can see Resharper is saying there is a problem because of the way the method has been named. Ideally, Resharper should allow this naming convention. With Resharper 5 (maybe in 4.5 too), you can change the setting to match how you want your naming to be.

image

Simply by hitting alt+enter you have some options related to Inconsistent naming.

In the settings dialog, you can set the name style. In my name, First_upper is how I like my tests to be named.

image

Resharper will now accept the naming. As a bonus, if the name happened to be Something_Like_This() then it would detect and provide an option to convert the naming to Something_like_this() keeping your test naming consistent which improves readability. Very cool!

However, the problem now is that ReSharper complaints on production code. For example:

image

Luckily, you can define two possible naming conventions as I’ve done below.

image

Labels:

Not much of an invitation - Thanks Google

Saturday, February 06, 2010

This week Google was kind enough to invite me to "Google Apps Premier Edition". This is the email:

2010-02-06_1621.png

I would love to use the premier edition as the free version is amazing! Sadly, the invitation was only for the 30 day free trail. After gaining my interest, Google then went and lost my interest while also making me disappointed. Not the ideal way to make your users feel.

When sending over promotional emails, take into account how the user will feel and their thought process when reading your email.

DDD8: Albacore and Testing ASP.net Web Applications using Ruby

Monday, February 01, 2010

Yesterday was the excellent DDD8. Thank you to all who attended. I gave a grok talk and a full presentation. The grok talk was on Albacore,  while the full presentation on Testing ASP.net Web Applications using Ruby. The slides are below. If you have any questions\feedback then do please let me know.

Don’t forget, if you are interested in learning more about Testing ASP.net then my book has recently been released.

cover[1]

Download demo from http://github.com/BenHall/Kona/zipball/DDD8

Labels: , ,

Quick screencast: Installing Git

Wednesday, January 20, 2010

I have spoken to a number of people who have been put-off by installing Git as it seems difficult. To prove that it’s not, I decided to put together a very quick screencast to highlight the main points. As I wanted it to be quick and to the point I decided not to add voice-over and instead use call-outs where required.

If you want to know more, then I really recommend you check out TekPub as they have done a great series on how to take full advantage of Git.

Labels:

Time for a new stubbing and mocking syntax?

Monday, January 18, 2010

When using IronRuby to test C# applications we are still faced with similar issues as with C# – the different is how we can handle them. For example, to stub the HttpRequestBase in C#, we could use Rhino Mocks as follows.

var stubbedHttpRequest = MockRepository.GenerateStub<HttpRequestBase>().Stub(x=>x.ApplicationPath).Return(“~/test”);

I do really like this syntax and think it works for C#.  However, if we are looking to use Ruby and a dynamic language we have the potential to be more inventive.

IronRuby has an excellent framework called Caricature which allows you to fake CLR objects. For example, here we are stubbing the HttpRequestBase from MVC.

require 'caricature'
include Caricature
stubHttpRequest = isolate System::Web::HttpRequestBase     
stubHttpRequest.when_receiving(:application_path).return("~/test")    
stubHttpRequest 

However, this got me thinking. With Ruby being dynamic, how could we take advantage when defining fakes? For example, what about the following syntax:

stubHttpRequest = stub 'System::Web::HttpRequestBase
                          .ApplicationPath.returns("~/test") &&
                          .FilePath.returns("")'

This would stub two properties, ApplicationPath and FilePath to return “~/test” and an empty string respectively. If we wanted to handle method calls and arguments, we could have the following:

stubHttpRequest = stub 'System::Web::HttpRequestBase
                          .SomeMethodCall("WithArgument").returns(SomeObject.new) && 
                          .SomeOtherMethod(*).returns(-1)'

Here we stub two methods, one stubs with a particular argument (must be the string “WithArgument”) while the other matches on any argument.

My aim is to reduce the ceremony associated with the act of stubbing and instead focus on the true intent of the defined behaviour.

Note: Imagine the ‘refactoring’ problem has been solved, and changing the method names would also update the tests.

If we look at other languages, for example Javascript’s jqMock and Ruby’s NotAMock are using a similar syntax to C#.

var alertMock = new jqMock.Mock(window, "alert");
alertMock.modify().args("hello world new!").returnValue();

I think it is time to start looking beyond the existing syntax and reveal our true intent. What do you think?

Labels: ,

Testing ASP.net using Ruby – CodeMash session

Sunday, January 17, 2010

This week I went over to CodeMash, an amazing community and cross-language conference in the US. I had some amazing conversations, meet some amazing people and gave a session on Testing ASP.net using Ruby.

I would like to say thank you to everyone who attended and the organisers for giving me the opportunity to speak. If you have any questions\comments, then please give me a shout, Twitter is the best way.

The code I used during the demo can be found on GitHub - http://github.com/BenHall/Kona 

I created a tag so you can download the zip of the code, now and in the future without being affected by other changes - http://github.com/BenHall/Kona/zipball/CodeMash_2010. In future I plan to keep working on this code as a sample so you might want to keep an eye on the repository. 

Also, if you would like to know more about Testing ASP.net web applications, then I recommend you take a look at the book I co-authored, check out http://www.testingaspnet.com

Labels: , , ,

RSpec, IronRuby and RubyMine

Saturday, January 09, 2010

RSpec, IronRuby and RubyMine is an amazing combination. Here is a screenshot of an example I’m currently working on…

Rubymine_tests_passing

All I do is execute the Rake command below, which exists in my rakefile.rb. Rubymine does the rest! Very cool.

desc "Run all examples"
Spec::Rake::SpecTask.new('examples') do |t|
  t.spec_files = FileList['examples/**/*.rb']
end

Adding IronRuby and JRuby to your OSX path

Saturday, December 26, 2009

After downloading IronRuby and JRuby to do some hacking over the Christmas period, I wanted to add them to my PATH variable on OSX. In Windows, this is fairly easy to find but is hidden a few dialogs down.

In OSX, you need to edit the .bash_login file in your user directory. A simple nano ~/.bash_login will allow you to edit the file (replacing nano is your own favourite editor).

To add IronRuby to your path add:

export PATH=/Users/Ben/Library/ironruby-0.9.3/bin:$PATH

Import points:
1) The path to your IronRuby bin folder.
2) Ensure you add the existing $PATH to the end
3) Export the result to the current PATH variable. Note, this is case sensitive.

To add jRuby you do it in a very similar fashion. However, because of priorities and how jRuby works, unless you want jRuby to be the default, add it to the end of the path export

export PATH=/Users/Ben/Library/ironruby-0.9.3/bin:$PATH:/Users/Ben/Library/jruby-1.4.0/bin

You should now be able to see all your ruby interpreters.

Ruby_OSX.png

A sneak peek at Meerkatalyst.Lonestar

Sunday, December 20, 2009

As I had some free time on my hands today I decided to create a new project called Lonestar. For those of you who are interested, here is the first (working) screenshot. Can anyone guess what it is?

Meerkatalyst.Lonestar Hello World Screenshot

For those of you who are following me on twitter then you will know I’ve been mentioning Meerkatalyst for a while – all will become clear soon. For now, keep an eye on my blog, the Meerkatalyst website and twitter feeds (@ben_hall and @meerkatalyst) for more exciting news on Lonestar and other projects!

Labels: ,

More amazing region examples

Friday, December 11, 2009

Come on – really?

image 

With the code being

image

This is why I hate regions

I just loaded up a default from Microsoft built into the Visual Studio 2010 extensibility and was greeted with this:

image

If someone could tell me what this region is actually adding to the code-base then I would love to know! Personally, it’s just a pointless layer of abstraction.

If your interested in what is happening within the region, well it gets worse. This is the code:

image

Instantly, I notice the following problems:

1) The comment to code ratio is very high. This makes seeing the code harder.

2) The attribute to code ratio is very high. This makes seeing the code harder, however it does have some useful information.

3) The class name is not at all related to the file name. This can cause real confusion when attempting to navigate and understand a code-base. Please, don’t do it.

What would happen if we wrote code like this:

image

The true intent of the code is now very clear without having to read anything! Stop hiding code and just show us the true aim.

Ideally I would also want to remove editorAdornmentLayer however MEF uses this, as such I need to leave it.

Labels:

Excellent error message from Amazon

Thursday, December 10, 2009

Yesterday I tried to purchase a book from Amazon UK on my iPhone and was given this error message:

IMG_0196

It had all my information, everything looked correct but unbeknown to everyone, including Amazon, it was game over.

Labels:

Making Visual Studio more keyboard friendly – File.Close

Saturday, December 05, 2009

image

Any time my hands are not on my keyboard my productivity is being harmed. Visual Studio + ReSharper has some really nice keyboard shortcuts which means I don’t need to use my mouse. However, one shortcut which just feels to me plain forgotten is being able to close a file using the keyboard. I can open, switch between but cannot close! Thankfully you can bind your own shortcuts, as such I bound to Ctrl+Q. Having this simply makes everything a little bit easier. But please, Visual Studio or ReSharper – auto-bind this command.

Note: Visual Studio 2010 Beta 2 is a bit buggy when it comes to keyboard shortcut. I had to un-assign anything bound to the key and restart the app before it took effect.

Labels: ,

Migrating from CodePlex to GitHub

While I have a lot of respect for the work Microsoft have done with CodePlex, personally I think GitHub is fundamentally a much better platform for open source projects. The main reason being is that it is just so easy to get access to the code, make changes and do whatever you want while utilising the power of Git. I have a couple of projects on CodePlex, so I wondered how easy it would be to port them over to GitHub.

After creating a new repository on GitHub, you are given the option to import from a Subversion Repository. All you need to do is enter the public Subversion URL for your repository.

image

Thankfully, CodePlex allows you to access your source code via TFS and Subversion. To find the URL, simply go to the Source Code tab and click Connection Instructions. This will give you the project’s SVN URL to enter into Github.

image

After clicking next the experience isn’t great – there is no real feedback about what is going on which is unfortunate.  However, after a while I received an email saying the Import had been completed successfully. If it fails, it also will send you an email to let you know.

image

My GitHub repository now has all the source code from my CodePlex project.

image

Along with the code, it also has all the commits and history associated with the project which is pretty awesome!

image

In just a few clicks I was able to migrate from CodePlex and SVN to GitHub and Git.

If you didn’t want to use the UI, or it failed for some reason, GitHub have a great guide about how you can do this import manually.

Labels: , ,

RubyMine – The Meta keyboard shourtcut on Windows

Saturday, November 21, 2009

Today I installed RubyMine 2.0 which is a great IDE from JetBrains. However, I was confused as all the keystrokes referred to ‘Meta’, for example ‘Meta+C’ for copying. Being on Windows 7, this wasn’t a valid keystroke.

After a bit of search around, it turns out RubyMine has keystrokes targeted for different environments, in my case it was targeted to be the same as TextMate. Awesome when I’m on my Mac, not so good on Windows.

To change the keymapping, select File > Settings. Pick the keymap option, and in the dropdown change it to Visual Studio.

image

Everything will then feel right at home.

Labels: ,