This is my personal blog. The views expressed on these pages are mine alone and not those of my employer.

Saturday, 22 January 2011

The often underrated value of Googling skills

I recently stumbled upon this question over at Stack Overflow:
can anyone help me find out url from given paragraph using regex c#
From reading this you can learn a few of things about the asker:
  • They have *some* software knowledge as they know they want to use regular expressions (regex)
  • They didn't use punctuation
  • They don't know how to use Google
Programming is is such a large area that is constantly undergoing change that it simply isn't possible to know it all, and anyone who tells you that is likely already light-years behind.

The internet however does know all of the answers, and any programmer at any level should know about and exploit this excellent resource. Of course you know this - because you're doing it right now.  In fact it has been said that software developers are simply Googling machines.

Whats at the centre of the internet?  Its Google of course! Google is a tool - period, and any one whos been tasked with writing even a single line of code should know how to use it and use it to its full potential. And since you're reading this that likely means you.

So why arn't educational establishments teaching Googling skills to computer science students?  I graduated in 2008 and certainly didn't get any formal guidance.

Which brings me back to the question above.  The asker would have got an answer instantly if they simply knew (and had the motivation) to do a search.  Perhaps if all software related education taught the use Google that above question would have never been asked.  Of course the asker could have simply been lazy - in which case shouldn't be developing software at all...

Monday, 17 January 2011

Assumptions in software

Its no secret that I prefer beautiful code.  I prefer code that reads like a set of comments - which provide a running commentary of the execution path with zero ambiguity and certain clarity that makes its intent crystal clear.

This makes good sense when you realise code is the only medium which allows us to communicate with machines - it allows us to speak the same language.  And just as in English, if you do not directly specify each and every possible fact - assumptions get made.

Now if an assumption is not was as intended strange results may occur - some may even say exceptional results. Bill Gates famously assumed in 1981 "640K ought to be enough for anybody" and we all know how wrong that was.

Exceptional circumstances are dealt with by most modern programming languages (in particular .NET) with - you guessed it - Exceptions. These set of classes are the equivalent of the software going crazy and refusing to carry on doing anything until the assumption is resolved - this is good, as we know that assumptions at best cause ambiguity and at worst are a show-stopper.

My beef is with a certain construct  that goes by the name "Else".  The problem is it encourages assumptions to be made but the main problem with this is computers don't have intuition.  Imagine the following scenario:

A school want to carry out a survey of the average age of students and would like to use some software to take input and perform the calculation.  I know if this was paper-based and an age came back as 135 my intuition would tell me this cannot be true - so I would write the software to also discard such a condition.

Once done the code looks like this:

private void addAge(int userInputtedAge)
        {
            if (userInputtedAge < 100)
            {
                //They've entered a valid range of ages
                calculateMean();
            }
            else
            {
                //The age wasn't less than 100
                MessageBox.Show("Please enter a valid age");
            }
        }

As you can see here using the else construct you have potentially introduced a bug if the user entered a perfectly valid int value of -10.

If I had re-written this software without using the else construct I would be forced to manually check for each expected condition:

private void addAge(int userInputtedAge)
        {
            if (userInputtedAge > 100)
            {
                //Bigger than 100
                throw new ArgumentOutOfRangeException();
            }
            if (userInputtedAge < 0)
            {
                //Less than zero
                throw new ArgumentOutOfRangeException();
            }

            calculateMean();
        }

Writing without the else has forced me to stop being lazy - and in the process I removed a potentially serious bug.

"So what?" you might be thinking.  The fact of the matter is any assumptions included in your code have the scope of being manipulated and abused.  Here is a real life example I found.

My conclusion is simple - if I'm expecting a particular range of inputs I should specifically test for each one.  If an input is not what is expected it is therefore exceptional and hence the software should throw a tantrum rather than carry on regardless.  Software should be designed in a way that causes bugs to show themselves - not hide away quietly.

So please - next time you think of writing Else stop and think "Do I really mean anything else?"

Monday, 3 January 2011

Are programmers any good without Google?

Having recently read that apparently 199 out of 200 of applicants for programming jobs can't write code at all I thought I'd put myself to the test.

The crux of the post being the FizzBuzz problem.

My results were rather surprising, although I managed to code a solution within 10 minutes - I had to perform the following google searches:
  • c# if whole number
  • c# multiples
and finally ending up with asking a rather dumb question over at stackoverflow.

This strikes fear through me, as it has become apparent that I am one of those who have a degree but can fail when asked to carry out a basic programming task during interview.

I've often wondered about this very fundamental understanding of programming - are programmers reduced to being simple googling machines?  Are our jobs simply comprised of looking up others code - and making it work for you?

I'm not so sure about the value of coding during interviews, as they tend to want you to code solo - without help.  But when in the real world are you working on a computer without internet access? Now obviously I disagree with someone using the internet for hours whilst trying to solve a trivial problem, but looking up syntax or framework quirks - surely thats excusable?

There are thousands of aspects to the .NET Framework and I challenge anyone who says they "know" it all. A programmer not needing the internet I believe is the equivalent of saying a Christian doesn't need a Bible because they "know" it all.

So what are the general thoughts on this?