Aarrgghh!! Accidentally pressing the Caps Lock key

I keep pressing the Caps Lock key accidentally. I don’t know why, but I do. I think it is the most despicable key on the keyboard, but I am not willing to go to the measures that a former colleague did. He hacked the key off his keyboard.

There are ways to get notified that the button has been pressed accidentally. In the control panel there is a setting that means that each time a “lock” key (Caps Lock, Num Lock and Scroll Lock) is pressed you get notified with a beep. The setting (known as “Toggle Keys”) is part of the keyboard accessibility options.

There are two routes to the setting. The Classic route and the modern route (it depends on how you’ve got your Control Panel configured).

Modern Route

If you are taking the modern route (the default) you need to open the control panel and select “Ease of Access”

Vista Control Panel (Modern)

Then click the link that says “Change how your keyboard works”

Vista Control Panel (Modern)

Classic Route

If you are taking the classic route you need to select the “Ease of Access Center”

Vista Control Panel (Classic)

Then click the link “Make the keyboard easier to use”

Vista Control Panel (Classic)

Finally

Both routes will eventually lead to the same screen. You need to ensure that “Turn on Toggle Keys” is checked (ticked). Once the setting is turned on you can “Apply” or “Save” the settings.

Make the Keyboard Easier to Use

Follow up on hiring a software developer

A while ago I wrote about finding it difficult to hire good software developers. We have now hired someone and it took us 3 months from the first interview to the last. We changed our strategy a couple of times throughout the process.

First we were told we had to go through the internal HR system which puts adverts out in job centres* across the UK. I don’t know why as we don’t do relocation so why not just stick to the local job centres. We also went to a recruitment agent after persuading HR that we really needed their services. For all the flak that recruitment agents get all I can say is that at the very least they gave us CVs that were of high enough quality to warrant an interview. All the CVs from the job centre were useless. Half of them didn’t even have any IT experience on them at all, let alone any evidence of software development work.

As we started to interview it seems obvious to us that the vast majority of senior software developers have stagnated. I did that once and it cost me 3 months unemployment – I am never doing that again.

We would ask these “senior” guys basic questions about OO (such as “What is encapsulation?”) and we’d get back blank stares from most of them. Okay, they’ve done work with SQL Server so some basic questions about indexes and joins (and I mean very basic like “What is the advantage of having an index?” or “Can you name any of the types of join SQL Server supports?”).

After a while we realised that the people we interviewed always perked up a bit and became more enthusiastic when we started talking about SQL Server. We got more right answers, more confidence and more enthusiasm in that area. So we changed the order of the questions around putting the SQL Server questions up front to give people a bit more confidence in themselves rather that just ask questions on skills in the order in which they were listed on their CV.

We also gave them a little programming problem. It was based on the Fizz-Buzz (or Buzz-Fizz) game that Scott Hanselman mentioned in one of his Hanselminutes on Hiring and Interviewing Engineers. I wrote the program, then I introduced a bug. We would give the candidate the paper with the program on it and the output that the program made with the error in the output highlighted. We would then ask the candidate to first of all tell us where the bug was and secondly to suggest a solution. I was shocked at the number of people that could not even point out the bug.

What was interesting was the the guy we eventually hired only looked at the code for about 5 seconds and pointed out the exact line and why it wasn’t working. When we asked for a possible solution we got an answer straight away. Given the speed of the answer we asked a third question (never before asked).

Before I get to that third question here’s a little background. When I developed the question I put it round the development team for comments and just to see how fast our existing developers could solve the problem to get some kind of bench mark on the time needed for the question. I got a number of different correct responses for the way to solve the problem (even from our DBA who hadn’t programmed in C# before).

So, the third question asked was “Can you think of any other ways in which to fix the bug?” and very quickly our candidate came up with two further solutions.

I’ve skipped ahead slightly in the story, so I’ll go back a bit. We were still having problems with senior developers not being able to answer basic questions. And when they did get as far as the practical test, they failed that shockingly badly too. Although, most of them failed because they did not read the specification and therefore did not do what was asked of them.

So, we changed out tactics slightly. We decided that as we had a fixed budget in which to hire someone, we would look for a graduate and use the extra money for training. We started getting in CVs for recent graduates. These were more difficult because a graduate doesn’t have so much experience. So we looked for things that showed commitment and an interest in technology. It didn’t matter to us that the only language they might have used was Java as we could train them.

But when it came to the interviews these guys really shone out more that the supposedly senior guys. They could answer all the basic questions. They were willing to admit when we’d reached the limit of their knowledge. (Either that, or they hadn’t learned to BS their way through answers)

When it came to the practical test, they showed some real promise, even if they did get the occasional thing wrong. Compare that with our earlier experiences where one “senior” guy had spent two hours in front of the PC and had written two lines of code in that time.

In the end we interviewed about 4 guys who had recently graduated and this was going to be their first or second software development job. And we hired one of them. If we’d gone for that strategy to start with I think we would have taken a lot less time and we wouldn’t have been so frustrated with the whole process.

The one thing we did not consider during the whole process was dropping our standards. I think we would have regretted it if we had. What we discovered was shocking. That is something I’ll cover in another post.

Some advice

As I mentioned, a lot of the senior developers we interviewed had somehow stagnated. They weren’t interested in software development other than as a 9-5 job. One even said in answer to a question “I’ve not been on a training course about that yet”! We only ask questions about stuff they’ve put on their CV. If they don’t have ASP.NET, for instance, but they’ve spent time doing windows applications we’ll ask them about Windows applications and we’ll skip ASP.NET. If we then need them to do an ASP.NET application we are confident that any developer worth their salt can pick it up in a short time. But, if they don’t have the fundamentals then I can’t see how they would cope.

So, if you are happy to go with the flow and just learn what your company needs you to learn rather than keep your marketable skill set up then feel free. Just don’t expect me to consider paying you the big bucks only to send you on lots of training courses for basic things like OO, C# and SQL Server.

 

But, if you do want to get out of that rut then here is some advice to you:

  • Find a local user group and attend their meetings. You get to meet experts. You can talk to them and increase your understanding. If you are in Scotland there are a number of user groups already:
  • Read stuff – And not just when you discover that you need it. Subscribe to a relevant software development magazine. Many companies will pay for that for you as they see it as an inexpensive form of training. Just read articles about software development to broaden your horizons. If you take a train or a bus to and from work this is an excellent time to do this.
  • Listen to stuff – There are some excellent podcasts out there that you can listen to while driving. DotNetRocks and Hanselminutes are two of my favourites. Scott Hanselman even has a show on how to be a better developer in 6 months.

You don’t have to spend a lot of time or money picking new stuff up. A user group meeting or two per month. That really doesn’t cost a lot. Some user groups charge, some don’t. If they do it is a modest amount to cover the cost of the venue and maybe some food and drink. In terms of time it is about 5 hours per month. It might be a wee bit more if you socialise after but that brings additional benefits. If you socialise people get to know you and if there is a job going it is great to have some contacts already.

Listening to podcasts in the car is practically free. You can get MP3 players hooked up to in-car stereos now and if not many will have CD players that can play MP3 or WMA files (The Toyota Yaris certainly does) so that only costs you the price of a blank CD for every 15 hours (roughly) of podcasts. In terms of time it only takes a few minutes to download and burn the files to a disk or transfer them to your MP3 player. In terms of time listening to them it is also free because it was dead time anyway. So that’s an additional bonus – you’ve turned some dead time into something useful.

 

Other posts on a similar theme:

 

* If you are from outside the UK, the job centre is part of the government’s department for work and pensions (DWP) and it is tasked with dealing with out of work people and helping them back into work.

 

My Favourite Patterns by Gary Short

Glasgow Caledonian University
Glasgow Caledonian University

Top speaker Gary Short presents his favourite patterns. If you missed this highly acclaimed presentation at DDD then this is your chance to see it. Gary has consistently received high scores on our event feedback and has the highest average score of any speaker.

Description: Well I kind of like Argyle myself… ah sorry, wrong group, you guys are not interested in those sorts of patterns then? In that case, I’d better talk about my favourite design and enterprise patterns. I’ll show you what the are, what they are used for and then I’ll rustle up a coded example – just for the hell of it! If you’ve heard of design and enterprise patterns and want to find out a bit more, or if you know about them already but just want to see how someone else does it, then this talk just might float your boat.

Bio: Gary Short was employed as a canoeist, but was presumed dead after disappearing under mysterious circumstances, only to reappear 5 years later. Gary had used this time to secretly re-train as a software Jedi and now plies his trade throughout the known galaxies, where he sells his skills to the highest bidder. Outside of his dog, his laptop is his best friend; inside of his dog, it’s too dark to use it.

The event is FREE.

It is held in the Continuing Professional Development Centre at Glasgow Caledonian University on the 16th of January 2008 at 19:00.

For more information visit My Favourite Patterns on the Scottish Developers Website.

 

Developer! Developer! Developer! is coming to Scotland

Spatial Operations in SQL Server 2008 (Katmai) – Union and Convex Hull

CODE EXAMPLES IN THIS POST WORK WITH THE NOVEMBER 2007 CTP (CTP 5) OF SQL SERVER 2008.

Say you would like to create a polygon out of a group of points. One way of doing this is to union the points together then create a convex hull from those points. A convex hull is a polygon that contains all the points of the geometries that it is made from. “The convex hull may be easily visualized by imagining an elastic band stretched open to encompass the given object; when released, it will assume the shape of the required convex hull.” [Wikipedia:Convex Hull]

It is possible to create a convex hull from just two points, however in this case you will end up with a linestring rather than a polygon because a polygon requires a minimum of 3 points.

DECLARE @a geometry
DECLARE @b geometry

SELECT @a = geometry::STGeomFromText('POINT(0 0)',0),
       @b = geometry::STGeomFromText('POINT(10 10)', 0);

SELECT @a.STUnion(@b).STConvexHull().ToString();

Results in: LINESTRING (10 10, 0 0)

With an additional point a polygon can be created.

DECLARE @a geometry
DECLARE @b geometry
DECLARE @c geometry

SELECT @a = geometry::STGeomFromText('POINT(0 0)',0),
       @b = geometry::STGeomFromText('POINT(10 10)', 0),
       @c = geometry::STGeomFromText('POINT(20 0)', 0);

SELECT @a.STUnion(@b).STUnion(@c).STConvexHull().ToString();

Results in: POLYGON ((20 0, 10 10, 0 0, 20 0))

What you’ll notice is that the polygon has 4 points, but we only gave 3 to start with. That is because the first and last point in the polygon are the same.

If you were to look at the geometry that had been created with just the union operations before the convex hull was made then you’ll see it is a MultiPoint: MULTIPOINT ((10 10), (20 0), (0 0))

graph1Unioning different types of geometry together, such as a point, linestring and polygon (see figure on the right) will, if the geometries don’t overlap, result in a GeometryCollection. For instance the code:

DECLARE @a geometry
DECLARE @b geometry
DECLARE @c geometry

SELECT @a = geometry::STGeomFromText(
            'POLYGON ((25 5, 15 15, 5 5, 25 5))',0),
       @b = geometry::STGeomFromText(
            'POINT(5 10)', 0),
       @c = geometry::STGeomFromText(
            'LINESTRING(20 20, 30 5)', 0);

SELECT  @a.STUnion(@b).STUnion(@c).ToString();

 

Will result in the following: GEOMETRYCOLLECTION (POINT (5 10), LINESTRING (20 20, 30 5), POLYGON ((5 5, 25 5, 15 15, 5 5)))

Moving the point to a position within the polygon, such as POINT(15 10) will result in a geometry collection that does not contain a separate point. As the point is within the boundary of the polygon it does not need to be separately listed in the geometry collection. The actual geometry looks like this: GEOMETRYCOLLECTION (LINESTRING (20 20, 30 5), POLYGON ((5 5, 25 5, 15 15, 5 5)))

graph2Moving the linestring to travel from 5,10 to 30,10 (through the polygon) results in a geometry collection with two linestrings (see figure on the left). One that runs from 5,10 to the boundary of the polygon at 10,10 and the second that runs from the  boundary of the polygon at 20,10 to the original end point at 30,10. The resulting MultiGeometry looks like this: GEOMETRYCOLLECTION (LINESTRING (30 10, 20 10), LINESTRING (10 10, 5 10), POLYGON ((5 5, 25 5, 20 10, 15 15, 10 10, 5 5)))

DECLARE @a geometry
DECLARE @b geometry
DECLARE @c geometry

SELECT @a = geometry::STGeomFromText(
            'POLYGON ((25 5, 15 15, 5 5, 25 5))',0),
       @b = geometry::STGeomFromText(
            'POINT(15 10)', 0),
       @c = geometry::STGeomFromText(
            'LINESTRING(5 10, 30 10)', 0);

SELECT @a.STUnion(@b).STUnion(@c).ToString();

Other posts in this series:

Always show the solution, Dammit!!!

This has got to be the most pointless setting in Visual Studio. I can’t imagine why any reasonable person would want to hide the solution. Maybe it is for those “Morts” I keep hearing about who bundle everything into one giant ball of mud project so have no need to know about mundane things such as solutions.

Always Show Solution

I suppose what gets me most is that I like my right-click. I like to right-click on things and get context sensitive menus. I also normally create a new blank solution then add projects to it. The solution disappear when the number of projects equals one. When there are zero projects the solution shows, but as soon as I add one it disappears so I can’t right-click and add another until I sort this setting out. It was the same in Visual Studio 2005, I was hopping they might have changed the default for VS2008, but no – the mob rule of the Morts wins.

Yes, I realise that I can go to the file menu to add a new project from there, but if I’m already focused in the solution explorer, I want to stay there. I don’t want to make giant leaps across the screen to do these things. I want everything I need within easy reach.

Contradictory messages

While attempting to create a database project in Visual Studio 2008 against a SQL Server 2008 database I got a rather odd error message. The dialog used to create the project requests information about the SQL Server database. It clearly states “The server version must be 2005 or later”. No problem, I thought. So I put in the information about my SQL Server and database in the dialog and tested the connection. So far so good. But as soon as I hit the “Okay” button I got a new message. Apparently, “Only servers up to Microsoft SQL Server 2005 are supported.”

Contradictions

Inserting geometry through a .NET Application

THIS POST REFERS TO THE NOVEMBER 2007 CTP (CTP 5) OF SQL SERVER 2008

Following from my previous posts (Getting started with Spatial Data in SQL Server 2008, Spatial Data in a .NET application) on the new spatial features of SQL Server 2008 I’ve been looking at how to get spatial data into SQL Server from a .NET application. This has not been as easy as expected.

I suspect I just have not found the right piece of documentation because my eventual solution isn’t one I’m entirely happy with.

I was unable to add a SqlGeometry as a parameter to the collection of parameters on the SqlCommand object in my .NET application. The SqlGeometry does not appear in the enumeration for SQL Server data types. My first thought was to put the data through as binary as I vaguely remember reading something about using binary in something I read recently, but I couldn’t quite remember where. However, when I created the geometry object in .NET then used .STAsBinary() on it so the parameter object would accept it the INSERT failed. The exception message was:

A .NET Framework error occurred during execution of user defined routine or aggregate 'geometry':
System.FormatException: One of the identified items was in an invalid format.
System.FormatException:
   at Microsoft.SqlServer.Types.GeometryData.Read(BinaryReader r)
   at Microsoft.SqlServer.Types.SqlGeometry.Read(BinaryReader r)
   at SqlGeometry::.DeserializeValidate(IntPtr , Int32 )
.
The statement has been terminated.

 

Yes, that was the MESSAGE from the exception. The stack trace above comes from within SQL Server itself. There is a separate stack track for my application. (I’m guessing if you are familiar with CLR stored procedures you may have seen this sort of thing before. I’ve not used the CLR code in SQL Server before, so it is a new experience)

The solution I found was to mark the parameter as an NVarChar, skip the creation of an SqlGeometry object and use a string containing the WKT (Well Known Text) representation. For example:

cmd.Parameters.Add("@Point", SqlDbType.NVarChar) = "POINT (312500 791500)";

I mentioned earlier that I’m not all that happy with this solution. That is because if I already have an SqlGeometry object I don’t want to have to convert it to a human readable format and have SQL Server parse it back again. Human Readable formats tend not to be the most efficient way of representing data and the geometry type already has a more efficient (as I understand it) format. Although in this case I bypassed the creation of an SqlGeometry object in my code, I can foresee cases where I might have created an SqlGeometry object through various operations and would have produced a fairly complex object. In those cases I wouldn’t want the additional overhead formatting it into WKT, passing it over the network and parsing it on the other side.

If I find a better solution I will post it.

Improving performance with parallel code

While waiting for my car to get serviced today I finally managed to catch up on reading some articles in MSDN Magazine. One of them, on optimising managed code for multi-core machines, really caught my attention.

The article was about a new technology from Microsoft called Parallel Extensions to .NET Framework 3.5 (download) which is currently released as a Community Technology Preview (CTP) at the moment. The blurb on the Microsoft site says “Parallel Extensions to the .NET Framework is a managed programming model for data parallelism, task parallelism, and coordination on parallel hardware unified by a common work scheduler.”

What I was most excited about was the ease with which it becomes possible to make an algorithm take advantage of multiple cores without all that tedious mucking about with threadpools. From what I gather the extensions are able to optimise the parallelism across the available cores. A looping construct can be set up across many cores and each thread is internally given a queue of work to do. If a thread finishes before others it can take up the slack by taking some work from another thread’s work queue.

Obviously, if an algorithm never lent itself well to parallelism in the first place these extensions won’t help much. Also the developer is still going to have to deal with concurrent access to shared resources so it is not a panacea. Those caveats aside these extensions to the .NET will make the job of using multi-core machines to their best much easier.

Parsing OS Grid References

If you have ever been to an agile coding session you may have come across the concept of the coding kata. It is an exercise designed to improve coding skill by making you more aware of the different ways of building the same solution. It also tends to lend itself extremely well to TDD.

I was just looking at ways of converting OS National Grid References from their alphanumeric form to a purely numeric form and it occurred to me that it might make an excellent project for a coding kata.

So, what’s the deal with OS National Grid References. Well, they consist of two letters followed by a number of digits. For example NT2474. NT relates to a square 100km along each side. The first two digits represent eastings within that square, and the second two represent northings within the square. The complete reference gives you a square that is one kilometre along each side. Of course, you can modify this to produce larger or smaller squares. NT, NT27, NT245746. As The actual coordinate the grid reference resolves to is the south west corner of the square. Also, there are optional spaces between parts, so NT245746 could be written as NT 245 746.

There is a more detailed guide to the national grid on the Ordnance Survey website.