Monday, June 18, 2007

Virtual Journys #1

For some time I have been a great fan of virtual hardware and the now opportunities it brings.

For most of this year I have been working on a large enterprise scale Java application targeting IBM WebSphere. Currently this configuration is only available on Windows and Linux so my Mac OS-X is out in the cold. During the day I work using windows and in the evening OS X for my own projects.

With the availability of Parallels and VMWare's virtualisation systems for the Mac new options are available. The most obvious is to create a Windows development envrionment for work running entirely in the guest Windows operating system. I thought I would try a different options. I would keep the source on the host OS X filesystem and perform builds using the virtual machine. Both Parammels and VMWare allow the host filesystem to be accessed as a network server. For windows this means that you can map the host files as a network mapped drive.

My first experiment used Parallels. The source was located on the host drive and I mapped a drive from the guest Windows system to the host source folder. I use helper batch files to move around the source and do tageted builds (e.g. bvt for ant -f custom-build.xml bvt) which seemed to be a problem for some reason. To run the CMD files I found I had to type bvt.cmd rather than bvt. It appears that the bvt is not sufficient to find and run bvt.cmd - very odd.

Otherwise things appear to work fine.

I exported the guest image using the VMWare importer tool to the host filesystem and booted the new VM in VMWare and set up the mapped drive in the same way. This time bvt was sufficient to find the bvt.cmd so there must be a difference in the way the shared filesystems work.

All the VMS are running on an external USB drive. Having the VMs there is convenient if I want to boot them on another computer and I find that the performance is faster with a second drive. I have used two types of drive. The first is a simple 160GByte laptop style drive which is convenient for travel. The other is a 150GByte 10,000 RPM raptor drive which is really sweet and I think faster indicating to me at least that USB is not the limiting factor for the slower drives.

Saturday, June 16, 2007

Terminate SQL Server processes for a database

I have come accross the same problem several times now and have had to google for the answer. This one is the best one I have found so far. I take no credit for the script but I have lost the original link so my appologies to the original author. If you read this please let me know so I can supply credit.

declare @spidstr varchar(8000)

select @spidstr=coalesce(@spidstr,'')+'kill '+convert(varchar, spid)+ '; ' from master..sysprocesses WHERE dbid=db_id('database name')

if @spidstr != '' exec (@spidstr)

The script can actually be put on a single line which makes running it from Ant (etc) very easy.

Quite often as a developer I need to rebuild my test database. However it is often the case that there are processes still running. It would be nice to track them all down but this is time consuming and it is often easier just to kill the processes in the database server and rebuild then retest.

Sunday, June 3, 2007

Why I bought Mac

Why I bought a Mac
==================

Just over a year ago I was working in the US on a Java project. My day to day work was was done on a PC and I was looking for something different. An addicted laptop buyer I had been through a number of dells and had a very nice Veio but still I was not satisfied. I had tried customisations of the UI and alternate technologies for software development. In a recent article Martin Fowler talked about boredom when it came to Microsoft and its development tools. Maybe that was it but for whatever reason with the advent of the Intel based macs and virtualization I could run windows if I needed to in a VM but I would use the native OS for my day to day requirements.

So it is just over a year later was the decision I made a wise one? Hell yes. The day I turned on my mac and saw it boot from cold in 25 seconds was a changing point. A year later it still boots from cold in just over 25 seconds. I have installed and uninstalled lots of software and still it continues to perform. Applications start reliably in the same time that they did when they were first installed. (I had always found that I needed to reimage my windows system once a year to get it back up to speed).

So I sit as my desk typing this message

Macs Rock

Maintaining principles, values and culture

Maintaining principles, values and culture
==========================================

I am currently working out of my home country on assignment in Sweden. Anyway, working away tends to means that I quite often get to spend time with my colleagues over dinner and talk about work, technology, people and generally put the world to rights.

The other evening was just such an event and after talking about work and life in general we started talking about company values and I recounted some things that I had seen during my life as a professional software engineer.

In the early life of a company the company is a direct reflection of its employers or more typically the mind of the person heading up the company. In this early period especially for software companies it is likely that the company has a very casual attitude to dress and personal expression. The people joining the company at this time are often attracted to the company because of this relaxed approach. Encouraged that hard work and thinking are valued over conforming to corporate stereotypes.

As companies grow they attract employees with a different view and customers who may expect a different set of values. This difference quite often sets up conflicts or 'growing pains'.

I believe that these changes in company culture and expectations in most companies go unnoticed or are simply accepted as part of growing up. But should this be the case? If I were to visit the offices of a design company I would expect to be surprised. I would expect a 'different' approach to office layout, dress and a more 'creative' environment. Why? Because I am looking for that type of organisation.

So why is it that when looking for someone to help with a software development problem I expect to see people in suites? Surly I am looking for creative solutions to my software development issues not someone who will try and apply a formula to my problems. My personal view is that a company should decide what type of company it wants to be rather than just become what everyone else expects it to be.

Keeping Unit Tests Small

Unit testing has become one of the mainstays of modern software development. Techniques such as Test Driven Development have delivered significant benefits in ensuring that the developed software is testable.



Designing good tests however seems to be a skill in its own right. I have seem many people struggle to hit the right level. I am not surprised by this - it took me some time to become happy with with my unit tests.



So I thought I would put some time to documenting what I have learnt about writing good unit tests.




  • One test - one feature

  • Keep the environment out of the tests.



One test - one feature



It is very tempting to shore up test code with many assertions. I have found that this makes the tests overly brittle. On failure more diagnosis is required to find
the cause of the problem. With more than one assertion you need more than the test name to find the code causing a problem.



Testing a single feature also makes it easier to name the test - name it after the feature! Not after the method name or class. Grouping the tests together for tests referring to a single class is useful for organisational purposes but beware of reflecting the method names into the tests.

A language for test

Writing tests is hard
=====================


Writing unit tests is hard. Often harder than writing the application. Our current choice of languages does not help much. General purpose programming languages were designed to solve application development problems not necessarily help us test the application under development. Virtual machines such as Sun's JVM and Microsoft's .NET runtime provide basic support by exposing the code meta-model so that test frameworks can be developed. To my knowledge 'test frameworks' have not been made high priority aspects of current language design.

Initiatives like [Behaviour-Driven Development](http://behaviour-driven.org) (BDD) add new dimensions to verifying the behaviour of an application. BDD uses a constrained analysis language to define the intended behaviour for the domain model. This behaviour statement is then used to generate executable code that it then run against the application.

BDD is an important step but is by its nature a confined to particular types of application (those with a domain model).

So what could a test language look like?
----------------------------------------

test-case: test case name
given ::=
BankAccount (Balance => 12.50, OverDraftLimit => 100)
when

verify that ::=
BankAccount