Rant of the day: Learn to frickin' count!

I was in a shop recently and I bought 6 items at £5 each. A total price of £30, even I can manage that mental arithmetic without resorting to a calculator. However, the till decided that the total price was £30.01. For a penny I really can’t be bothered to argue, but it got me thinking about code quality and wondering about what awfulness must be sitting in that system to create such a simple basic mistake.

My colleagues are probably all aware of my views on code quality. I rant daily whenever I see examples on ineptitude by people that are paid money to write code. I read and respond on forums in order to help others learn their craft, or just get unstuck when they accidentally dig themselves in a hole. However, I see on an almost daily basis these days people posting their homework questions with no apparent attempt to at least try to work it out from themselves.

Take this example I found on Code Project a while ago:

I need to know how to do some simple things with arrays please help with any!
1.Find largest or smallest value
2.Count how many times a given value is in the array
3.Count the number of even or odd integers in the array
4.Add up the sum and compute the mean
5.Create another array of the same size containing the same values in reverse order

This is very obviously an exercise from an introductory course on the language they were studying. They just want someone to give them an answer that they can copy and paste. If this is what they are like now, imagine what they will be like years down the road writing commercial software.

I’ve seen lots of evidence over the years of people writing software by copy and pasting examples from the internet without thought of what is actually going on. This results in slow, bloated, inefficient code that is integrated very badly with the rest of the system, hard to read, hard to debug, and is just generally a complete mess.

If you are tempted to copy and paste some code snippet from the internet for your application then stop and think first. Do you actually understand the code? If not, then don’t copy and paste it. If you don’t understand it, how will you debug it?

I would say that if you are tempted to copy and paste from the internet that you create a very small test application first, paste it in to that and learn how it works. Once you understand how it all fits together and how it works you can then write a version that will integrate in to your application.

While you are at it, write some unit tests to go with it. Make sure you test for edge cases, make sure you test for some normal cases too. If you ever get a bug, then add a test that replicates the bug. So if someone suddenly discovers your software things that 5 times 6 equals 30.01 you can add a test for it, fix the bug and redeploy the system. Hopefully, this would have been caught before the public get a chance to see the glaring error and write blog posts about it.

It's that time of year again

It seems to be that time of year when lots of students are on forums trying to persuade people to do their homework for them. Since I’ve found difficulty in finding good quality software developers in the past there is no way I’m going to contribute to producing any more debased lazy Muppets claiming to be programmers. The rules of the forums I frequent most often are very simple, and I’d imagine that most forums will have the same set of rules. Basically the person requesting help has to show what they’ve done already then they can expect to get advice on how to fix the problem. If the question comes in and it is just a set of questions with a plea that their homework assignment is due the next day then they are likely to feel the wrath of several professional software developers that have most likely had to clean up the excrement left by previous generations of these inattentive indolent laggards.

I would like to make it perfectly clear for any student that is genuinely struggling with an assignment that forums are an excellent place to seek help. However, you must show that you’ve made an attempt yourself, that you’ve attempted to research the topic and that you are genuinely seeking help and not just a free ride. If you are willing to work through the problem yourself (with some assistance from folks on forums) then you will attain a greater understanding and you are more likely to reach that AHA! moment where everything clicks in to place in your mind. And what a joy that feeling is!

Training Developers

Software development is a very fast moving business and it is therefore vitally important to keep up with what is happening with technology. If you don’t you could be left behind pretty quickly. When the proverbial hits the fan you don’t want to be left behind.

If you remember back to your school days you might remember Æsop’s fable The Ant and the Grasshopper. The grasshopper did no work in the summer while the ant worked hard in preparation of the lean times. When the lean times came the ant was able to provide for himself, while the grasshopper starved. A lot of software developers are like the grasshopper, they are not planning for their future. You might think it unfair of me to tar all developers with that brush, but I don’t mean to. I did say “a lot” not “all”. So why do I think that?

Last year I spent three months trying to hire a developer. I was shocked at the number of developers that I saw had the attitude that they didn’t need to learn anything unless their employer put them on a training course. Some seemed surprised when I asked how they kept up to date with the industry they are in. Most just mumbled something about reading books and articles online. Given the answers to other questions I don’t think they spent all that much time reading.

Software development knowledge fades faster than ever these days. It seems like only yesterday that I was learning .NET 1.0, yet .NET 4.0 is just around the corner. In a couple of years I’ll be using it commercially. Technologies like LINQ to SQL which has only been released will be dead soon, if recent reports are to be believed. That’s a lot of new information to take in only for it to go stale. This week I’m immersing myself in ASP.NET MVC. I’ve been to a talk on the subject at it looks like that’s the way forward so I want to be at the head of the pack. I’ll also be taking a first look at Subversion this week also. On top of that I’ve got a stack of other things to get through.

When I left university I had the arrogance to think that I knew it all and for a few years I worked on that principle. But that attitude eventually caught up with me and I spent some time unemployed partly as a result of that attitude. I am determined not to let that happen again. These days I am acutely aware of what I don’t know. I think that now I am more aware of my limitations I am a better developer. Because I’m more aware of what I don’t know I strive to fill those gaps by ensuring my own education – I don’t let an employer dictate what I should be learning. I am pro-active and go out there and ensure I’m educated. Of course, if my employer wants to put me on a specific training course I’ll accept it.

I did a little calculation last weekend that surprised me. Actually it shocked the heck out of me. Last year my employer spend roughly £200 on training materials for me. However, I spent a lot more. Of the things that I can remember (so I suppose the things that were worth it) I spent £2500 on my own education.

So, who gets the benefit out of this? For the most part my employer gets the benefit. While I enjoy developing software, it is my employer that profits from it at the end of the day.

Most employer attitudes to training developers are that it isn’t worth it because the developer will just leave with the additional knowledge they’ve received for a higher salary else where. Well, I suppose they will if the employer has that kind of cynical attitude. Employers think that they have to find a replacement soon so why bother training a developer only for another company to take advantage of that. But the a lot of the knowledge that is walking out the door cannot be replaced easily. A lot of the knowledge walking out the door is about the employer’s business and that is unique. You can’t hire that in.

There are a number of “solutions” to this problem. Some employers go for the stick method. “If I train you up and you leave within X months then you have to pay part of the training costs back.” The disturbing thing is that I used to think that was an acceptable solution. But it really isn’t. It is a form of financial handcuffs, and the developer being trained is going to resent it. Quite possibly they’ll be off as soon as the handcuffs are removed or simply not accept the training.

The more reasonable attitude, I think, to take about training is to realise that the developer that’s just been trained has increased their market value. So, pay market value for the developer. You don’t necessarily have to do it straight away, give the training time to sink in if you want, but do increase the developers salary within a few months and don’t tie it to anything else. Don’t roll it in with inflation based increase, an annual increase, or other bonus schemes. Make it very clear that the increase is solely as a result of the greater ability or productivity as a result of the training previously received.

Solution: A simple challenge

For personal reasons I’ve not been very active in the last week or so. Therefore the solution I promised has been a bit late in coming.

Here is the “reference solution” for the simple challenge that I set last week. It is by no means the only solution, nor is it necessarily the best solution (depending on how you define “best”)

class Program
    private static void Main(string[] args)
        int width = Convert.ToInt32(Console.ReadLine());
        int height = Convert.ToInt32(Console.ReadLine());

        DrawBox(width, height);


    private static void DrawBox(int width, int height)
        // Work out the interior width and height (i.e. the width
        // and height of the space inside the box)
        int interiorWidth = width - 2;
        int interiorHeight = height - 2;

        // Work out what the top and bottom of the box should look like
        string topAndBottom = new string('*', width);

        // Work out what the interior rows should look like
        string interiorRow = string.Concat(
            "*", new string(' ', interiorWidth), "*", Environment.NewLine);

        // Work out the entire interior using the "trick" of defining
        // a string with a repeating character for as many rows as the
        // interior needs to be, then replacing each of those characters
        // with the pattern for a row of the interior.
        string interior = new string('-', interiorHeight);
        interior = interior.Replace("-", interiorRow);

        // Write the box to the console.
Technorati Tags: ,,,,

A simple challenge

A homework question was posted on a forum recently. As usual it was met with the cries of “We won’t do your homework for you” (We will, of course, help if you get stuck. But don’t expect any assistance without at least trying first)

The assignment was to write a console application that accepted a width and a height from the user and then created a rectangle using asterisks. e.g. This might be the result of the program

*      *
*      *
*      *

Now the query was asked how to complete this using loops (or conditional statements, we weren’t really sure – he said loops, but proceeded to talk about if/else statements)

One of the responses was along the lines of “I can do this without loops”, modified to add “Or conditional statements”, and modified again to add “Or recursion”

So, my challenge to you is to write a small program above without loops, conditional statements or recursion. It sounds difficult, but it isn’t really. I have a solution (from which the example output above has been taken) which I’ll post this evening.

Technorati Tags: ,,,,

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.

What are developer forums for?

An interesting question. One that seems to have an obvious answer. But there have been a couple of people in the last week that seem to have asked a forum full of random software developers a question they should be asking their client/customer.

I’m not exactly sure why that might be, however, I can possibly guess.

A few weeks ago I asked the question Why is it so hard to hire good software developers? and my colleague also commented on the types of developer that pass through our recruitment process. After that experience I can understand that some developers might have been hired on being able to talk smooth throughout the interview process. Then they get the job and realise that they can’t actually do it. For fear of being fired they jump onto internet forums and seek any type of help they can.

Their lack of ability means that they have some difficulty in working out questions that they should already know the answer to versus questions that they really ought to be asking their client.

Lets take an example. One person was writing a tourist reservation system. He asked what should happen if a person makes a booking without going through a travel agent. This question can’t be answered on a forum for SQL Server. It can only be answered by the client or the business analyst that is liaising with the client.

The question I have to ask these people is: How would a random developer know what your business requirements are?

Another person was a bit more wide ranging in their request. They wanted to know how to develop a “real estate site”. Since the basic principle isn’t any different to any other interactive website surely they should have been asking their client what they wanted in the website.

Maybe I’m wrong in all of this, it is only my idle speculation. If you have a better idea of why some people are asking questions on forums that they should be asking their client or customer I’d like to know.


Then and Now


Recently a post was put up on Code Project that was basically a direct copy of a homework assignment. I don’t answer questions for people’s homework. I have enough trouble trying to hire a good developer as it is without contributing to another generation of useless code monkeys.

Anyway, the question was in two parts. The first part, in summary, was to write some code that calculates powers. e.g. 23=8; 74=2401; etc. by just using simple multiplication. The second part was to solve the same problem but without using a multiplication operator.

This has got me thinking for most of the afternoon, even after watching an episode of Judge John Deed (I’m on holiday). What I was thinking about was the different ways in which I’d tackle the problem. They way I would have tackled the problem when I was a student, and the way I’d do it now.

Then (15 years ago as a student) I’d have created a console application, read in a couple of integers from the keyboard and performed the calculation all in one horrible Main function. Then I would have thrown a few random integers at the command line to satisfy myself that it would work. If it didn’t I’d hack away at it until it did. There wouldn’t be any consistency in the testing as I’d be throwing different integers at it.

Now, because I was curious what the answer was, I did the following: I created a test assembly and wrote some unit tests so that each time I ran the tests it would be the same tests. Then I created a method that performed the calculation. It took two integers, x and y, and calculates xy using the multiplication technique. Then I ran my tests to see if it worked. Once that was working, I re-wrote the method to use the addition only technique. Then I ran the tests again to ensure that I still got the same results.


Why is it so hard to hire good software developers?

Why is it so hard to hire good software developers? That is the question I’ve been asking myself recently. The company I work for is currently looking for two software developers and it is incredibly disheartening to see the quality of candidates.

First off the quality of the CVs. We’ve taken a two pronged approach to this. We used a recruitment agency and we advertised ourselves. What a difference between the two approaches! The CVs we got from the recruitment agency were at least sufficient quality to warrant an interview. The vast majority of the CVs we got from our advertising efforts were useless. Half didn’t even live within a commutable distance.

Of those that we did interview two thirds didn’t make it past the first interview. This is an informal meeting where we ask some questions based on what’s in their CV and try and assess their personality. If they mention that they’ve got SQL Server experience we’ll ask questions on that. If they say they’ve got Reporting Services experience we’ll delve a bit further.

We are looking for C# developers, but we don’t mind VB.NET guys because the main learning curve is the .NET Framework and that is the same for C# and VB.NET. The hundred or so differences come from the language syntax and that can be overcome in a short period of time.

The second interview is really a technical test. We give the candidate a specification and walk them through it. The application is sufficiently small that it is just possible to complete everything in the allotted two hours, but most don’t – and we don’t expect candidates to complete it, although we do expect that they will get a fair way through it. Part of what we are looking for is to see how their thought processes work, so the spec is sufficiently loose that they can make choices to show off their skills.

We’ve found that it really is the best way to discover if the candidate can actually do the work. The application is not difficult by any stretch of the imagination and we’d expect anyone with a few years experience or a computing or software engineering degree to be able to complete a fair portion of it. It is, admittedly, slightly larger the Scott Hanselman’s example of the Buzz-Fizz program. But, then, we also want to see how they would structure a more realistic application rather than just a single simple algorithm.

So, what would we recommend? Listening to DotNetRocks is a good start. Download it to your MP3 player or burn it to a CD and listen to it on your commute to and from work. Most people waste that entire time going to and from work, so start doing something useful with it. I vaguely remember a study that suggested that if you drive 12,000 miles per year (a 24 mile commute) you could learn as much as a 3 year degree course in 4 years.

Next, watching episodes of dnrTV will help. If you need to learn about some newer technologies then the Developer Platform Evangelists at Microsoft UK have produced an number of Nuggets – short 10-ish minute videos showing a single concept.

But, what is next for us? We are considering going back to basics. If we can’t find someone with the relevant skills then we’ll have to hire someone without those skills. But we can’t hire someone with a few years “experience” because they’ll want more money than they are worth, so fresh graduates or especially talented folk that are crossing from another field in IT will be what we are looking for.