I came across an interesting article a day or two ago on Coding Horror. It seems that many interviewers seeking programmers are discovering that applicants for the jobs cannot write even the simplest of programs.
The article referred to another article in which the author said
After a fair bit of trial and error I’ve come to discover that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.
As as a result he asks programming applicants to write some simple code, one example being to code the children’s game FizzBuzz.
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
The interesting thing was that, while both articles were about the state of the education or lack of it of programmers, especially in computer science courses, the comments to both blogs were, in the main, demonstrations of how to write the program in various languages. Not that that should be surprising, after all both blogs are aimed at programmers.
But two interesting things emerged.
First, a number of solutions, mainly on the Coding Horror site, were wrong. For example, most of the wrong answers showed every integer from 1 to 100, but the ones which should have been replaced by Fizz or Buzz showed the number as well. So that the list went something like 1, 2, 3 Fizz, 4, 5 Buzz etc.
This is an example of not reading the requirements. But a few solutions would not even compile. I didn’t check this out myself, other comments mentioned it.
Of course, as soon as I read the article I had to come up with a solution myself. So I wrote one. And it is a very simple exercise. Actually I wrote two, one in VB and one in C#. But the point is that I actually wrote them, compiled them and ran them. I am surprised that programmers would post a solution that they hadn’t tried out and tested.
The second interesting thing was the number of programs which attempted to produce the solution in the least number of lines of code. You don’t get any brownie points for less lines of code. You only get unreadable and unmaintainable code. I assume that these programmers know this and in the real world they don’t write like that.
But I have seen countless examples of code over the years which are impossible to read because the programmer tried to look clever.
Programmers should always remember that code is read many more times than it is written. And even if it is only read by you, come tomorrow you won’t understand it if it isn’t clear in the first place.