Insights and outlooks on software development

S'true

On ClrStrings in IronRuby

Wednesday, March 25, 2009 by Thomas L

A string is a string is a ... well, at least not string.

C:\ironruby\bin>ir
IronRuby 1.0.0.2 on .NET 2.0.50727.3053
>>> require 'Guestbook'
=> true
>>> @repo = Guestbook::MessageRepository.new "connstring"
=> #<Guestbook::MessageRepository:0x000005c>
>>> @str = @repo.ConnectionString
=> "connstring"
>>> @anotherstr = "connstring"
=> "connstring"
>>> @str == @anotherstr
=> false

Huh? "connstring" != "connstring"? This bit me quite hard, but the following helped me resolve the problem:

>>> @str.class 
=> ClrString 
>>> @anotherstr.class 
=> String

So, when you instantiate a string from a CLR object (Guestbook above is a .NET dll), you don't get a ruby String, but a ClrString. When you use the ClrString, e.g. when printing it out to the console, the to_s method is automatically invoked, and it looks to the ir user as if it is the same as the ruby String created when invoking to_s. Sneaky.

If I had been using IronRuby 0.3.0 instead, I wouldn't have been bitten by this:

C:\ironruby-0.3.0\bin>ir 
IronRuby 0.3.0.0 on .NET 2.0.50727.3053 
Copyright (c) Microsoft Corporation. All rights reserved. 
>>> require 'Guestbook' 
=> true 
>>> @repo = Guestbook::MessageRepository.new "connstr" 
=> #<Guestbook::MessageRepository:0x000005c> 
>>> @str = @repo.ConnectionString 
=> 'connstr' 
>>> @str.class 
=> ClrString 
>>> @anotherstr = "connstr" 
=> "connstr" 
>>> @str 
=> 'connstr' 
>>> @anotherstr 
=> "connstr" 
>>> @str == @anotherstr 
=> false

When printing out the ClrString @str to the console, it's quoted with single quotes. Smart.

How does this work with JRuby-Java Interop?

IronRuby 0.3

Sunday, March 22, 2009 by Thomas L

I missed this one completely, but luckily stumbled upon it when I was troubleshooting assembly loading from cucumber: IronRuby 0.3 was released yesterday!

In the release notes, they say that there will be shorter time between the releases, which obviously is good.

Technorati Tags: ,,

On quick launching in Vista

by Thomas L

This is a feature I didn't know of until today: in Vista, you can launch a program on the quick launch bar by pressing the Windows + (number) key, and it starts the (number)th program in your launch bar. This means that by invoking Win+2, I'm launching Internet Explorer when the quick launch bar looks like this:

VistaDev 

Technorati Tags: ,,

On XP == Pair Programming

Sunday, March 15, 2009 by Thomas L

It seems as if the XP practice of pair programming is the number one reason for development teams not considering XP seriously. I've lost count of the number of times I've gotten a blocking No, we won't use XP from a stakeholder, with the inevitable I don't beliveve in programming in pairs all the time as the reason.

In the scenario above, the stakeholder concentrates on the pair programming practice to the extent that (s)he loses track of the big picture and thus dismisses the eleven other XP practices.

On playing around with css

by Thomas L

I haven't done that much of blog posting regarding web tech, but I thought I should change that, at least for once. I've become more and more intrigued by the things that can be done with css, and I thought I should share this tip on creating a comma separated list in css.

The scenario is that we have a list of things which we want to display as a comma separated list on the web. This could be in whatever language or web framework, be it Ruby on Rails, Castle MonoRail or ASP.NET MVC.

The solution is to output the list in a ul list, with all the items that should be comma separated in li elements inside the ul list, like so:

<ul class="commaseparated">
  <li>first item</li>
  <li>second item</li>
  <li>third item</li>
  <li>fourth item</li>
</ul>

Then we add css rules for the commaseparated css class:

ul.commaseparated { list-style: none; margin: 0; padding: 0; }
ul.commaseparated li { display: inline; }
ul.commaseparated li:after { content: ","; } 
ul.commaseparated li:last-child:after { content: ""; }

The output is then a comma separated list. The trick here is the li:after and li:last-child:after css pseudo-classes. Read more about them at e.g. the sitepoint css reference.

One drawback is that IE 7 doesn't support css properly, so the solution with the pseudo-classes doesn't work in that browser. However, people using that browser should really look for something a bit more in the 21st century. What you could do for IE7 is using jQuery to append the commas instead of using css.

Technorati Tags: ,,

On getting started using Cucumber for .NET

Wednesday, March 11, 2009 by Thomas L

NOTE: This post is obsolete, please check my new write-up on Cucumber running under IronRuby 0.9.

I'm gearing up for an ALT.NET Oresund meeting in Copenhagen, (March 24 @ IT Universitetet, near the Metro station Islands Brygge). As I've promised to demonstrate running Cucumber stories against .NET code, I needed to get everything running on my lab computer running Vista. Since I heard there had been problems setting up Cucumber, I thought I should document my progress. These are my notes.

The text below is largely based on the IronRuby and .NET page on the cucumber wiki, but I had to jump though some hoops to get things working.

Installing MRI

Since IronRuby isn't exactly 1.0 yet, we need the Matz's Ruby Interpreter (often referred to as MRI) to get stuff working. Since we're running on Windows, we can install the Ruby One-click installer from RubyForge.

When installing, make sure that you check the checkbox for RubyGems. I checked all of the checkboxes, just to be sure. Place MRI in C:\External\languages\ruby\ruby-1.8.6.

When MRI is installed, you can invoke ruby --version and gem --version. Both should work, giving the versions of the two tools.

Installing IronRuby

IronRuby is, if you didn't know, a Microsoft-backed open-source interpreter on the CLI, using the .NET dynamic runtime to execute Ruby code in the .NET world, making it possible to interop with regular .NET assemblies. The interop feature is the thing we are looking for, since we want to get Cucumber running stories against .NET code written in e.g. c#.

To install, download IronRuby. At the time of writing, the latest version was IronRuby 0.2 Alpha, packaged in a zip file. The zip file contents should be placed in C:\ironruby, and then the path to IronRuby's bin folder (C:\ironruby\bin) should be added to the PATH. If everything is fine, it's possible to invoke ir.exe which launches the IronRuby console.

Getting Cucumber and RSpec

Now we have both MRI and IronRuby working, it's time to direct the attention to Cucumber and RSpec. To install this, we use RubyGems to automatically download and install the plugins (called 'Gems') by invoking gem install cucumber rspec.

Now the cucumber and rspec gems should be installed. The Cucumber gem should have placed a file called cucumber.bat underneath the MRI installation directory. To make sure everything works as it should using the MRI, start a cmd prompt and run cucumber. If everything is set up correctly, there should be an error about a missing cucumber.yml. We have now gotten cucumber running under the MRI.

Now for the next step; getting cucumber running under IronRuby.

Cucumber wrapper script

Create a bat file called icucumber.bat in the MRI bin directory that should wrap the cucumber.bat. On my system, having Ruby and IronRuby where I placed them, this is the contents for me:

@ECHO OFF
REM This is to tell IronRuby where to find gems.
SET GEM_PATH="C:\External\languages\ruby\ruby-1.8.6\lib\ruby\gems\1.8"
@"C:\ironruby\bin\ir.exe" "C:\External\languages\ruby\ruby-1.8.6\bin\cucumber" %*

To test if this works, run icucumber, and you should get the same error as previously, the one about a missing cucumber.yml file.

This was where things didn't work as it should for me. icucumber quit, shouting about not being able to load the cucumber gem, and somehow it was looking underneath {MRI}\lib\ironruby\gems\1.8, even though my GEM_PATH was set to the above. My solution to that problem was to copy everything from the ruby gem folder to the IronRuby gem folder. I thus have to remember to copy things from the ruby to the ironruby folder when anything is updated, but it at least kind of works.

Testing if icucumber works as it should

Earlier we only tested if we could start icucumber. The really interesting thing is to check if icucumber can run stories for code written in c#.

cd to the cucumber gem directory; in our case this would be c:\External\languages\ruby\ruby-1.8.6\lib\ironruby\gems\1.8\gems\cucumber-0.1.16\examples

To test if we can run icucumber stories testing plain ruby code, do the following.
cd c:\External\languages\ruby\ruby-1.8.6\lib\ironruby\gems\1.8\gems\cucumber-0.1.16\examples\i18n\en
icucumber features

To test to run icucumber stories for c# code: If you haven't already, run a Visual Studio 2008 command prompt (to get the paths to the .NET Framework). Then do the following.
cd C:\External\languages\ruby\ruby-1.8.6\lib\ruby\gems\1.8\gems\cucumber-0.1.16\examples\cs
compile.bat
icucumber features

The command above should crank out "20 steps passed", which means we have gotten our Ruby-to-.NET interop running!

But why?

This is the most interesting question of all. I believe that the BDD way of writing executable specs is something that we as software developing teams should start doing right away. It helps on many levels; not only will our test code be more readable, it actually helps when fleshing out how the features will work. Us as teams will gather and write the specs in free-text and the developers will then fill in the gaps (i.e. write the steps), instead of having specs on one place and unit/integration/acceptance tests on the other.

If you come to the ALT.NET Oresund gathering March 24, I am more than interested in discussing this topic. I'll hopefully be able to show a demonstration of how BDD with Cucumber works tech-wise and then we can take the theory and the why afterwards.

On Agile creating Yes Men

by Thomas L

No one wants to be a No Man. The same goes in software. It's no more frustrating than having to tell the person with the business need for the software that's being built that

I'm sorry, but we didn't plan for that!

Yet we do this; time and time again. After the first plan in a waterfall-ish project, the project members are turned into No Men, having to say no to all new ideas, no matter how good they are, or at least raising the barrier of entry so high that few features take the route into the product. CCB's anyone?

What if we could turn everything around? Imagine saying

That seems like a superb feature! Let's include it as soon as possible!

This is actually one of the best selling points of Agile to project members, architects and project managers. We no longer have to be the boring No Man, instead we give our product owners/customers the power to wield tools that makes the product we are building adaptable to changes in the world around us.

On the second ALT.NET Oresund meeting

Sunday, March 1, 2009 by Thomas L

March 24 at 18.00 we'll have the second ALT.NET Oresund meeting. Since we try to alternate between having the meetings in Denmark and Sweden, we'll be meeting up in Copenhagen this time. We have managed to get a room in the IT University quite close to the Islands Brygge metro station. For us Swedes, the easiest way to get there is to switch to the metro at the Orestad train station.

I have planned to do a lightning talk about Cucumber and BDD in the .NET world.