Tuesday 8 December 2009

Call to arms: Ban Case / Switch statements

Of late I've been keeping up with the Hashrocket bookclub which is streamed on Tuesday evenings at 5.12pm GMT. Each week the folks discuss a chapter or two of the current book Refactoring: Ruby Edition

I noticed there was a running theme through a number of the 'Organising Data' refactorings which was removing case statements.

I've been at this coding game for about a decade now and I've only seen what I would call one valid use of a case statement. Every other use benefitted from being replaced by polymorphism.

With that in mind I'd like to see the case and switch keywords removed from all OO languages as it actively encourages poor design and less flexible code.

Any language designers out there reading?
The one case I mentioned above where a switch was useful could easily be replaced by an if, else if condition. Save yourself the hassle of implementing case or switch.

Wednesday 15 April 2009

Mac Gem Jip

I'm a bit of a newbie to Macs and finally took the plunge a few months back. The day job is still on a windows box to keep inline with the rest of the team so there hasn't been much Mac playtime.

The last few days I started to put together a presentation for Agile Scotland with coded examples and that is where I hit the wall - running the code. 

Background to the problem:
About six months back I was poking at rspec and cucumber to get a feel for them. For my presentation I wanted to have the latest and greatest version of rails, rspec and cucumber available on my Mac.

When trying to run features for cucumber 0.3.0 it was expecting rspec 1.2.2 to be in place, which it was, however the rails environment had already picked up rspec 1.2.4. For the life of me I couldn't find out what where rspec 1.2.4 was being fetched. I decided to uninstall the rspec 1.2.4 leaving only one version in place and hopefully solving the problem. All looked good until you run 

gem list

and there it is, still sitting there refusing to budge no matter how many gem uninstalls are run: rspec 1.2.4

What was wrong:
After much running around the short story is there are three places gems are stored. Depending on how you install the gems affects where the gems are stored and I managed to muddle them. Thanks to Jason Tennier post which helps explains where I went astray.