Input error detection

I have been on CodeChef for a few months now, where I have been enjoying keeping my mind active with the practice problems and long challenges. I have noticed a certain style about the problems, where the emphasis is not only on finding a solution but finding one which is efficient. There is a particular emphasis on fast input, fast sorting and the avoidance of nested loops.

In my long career developing software I have always found it necessary to concentrate on error handling, either faulty input or algorithm failure. In particular I believe that a well-written program should never crash. In CodeChef submissions a crash is not considered any worse than a wrong answer or time-limit-exceeded.

I suggest that some challenges should handle faulty input. For example the following C# code is fast for reading an integer, but will produce nonsense if it encounters some characters other than a digit. For example, you might consider a variation of INTEST2 which must produce a controlled error message if it encounters any input which does not meet the prescribed definition.

    static int StringToPositiveInt(String s)
    // Convert string from index up to next space or end to zero or positive integer.
    {
        const char zero = '0';
        int index = 0;
        int n = s[index] - zero;
        int len = s.Length;
        while (++index < len) {
            if (s[index] < zero)
                break;
            n = n * 10 + ( s[index] - zero );
        }
        return n;
    }

Another possibility to encourage good programming practice is to deduct points in a challenge if any submission crashes, as opposed to failing with TLE or WA.

Hi David,

Your suggestion is good, however I feel it will be hard to implements as the listed languages have a very wide range of error handling capabilities.

Few things like invalid type casting, or faulty references may be caught by languages like Java during compilation, while they may only come into light for C programmers after submission. So it can be implemented in contests if it restricted only to a particular set of high level languages.

Let’s see what others have to say.