My Least Favourite Error Messages
Exception in thread "main" java.lang.NullPointerExceptionwhere Java refuses to tell me which variable holds the empty pointer or faulty array index. This is no small irritation when one is calling a method that takes seventeen pointer arguments, any of which could be null.
My least favourite error messages are Java's array-index-out-of-bounds and null-pointer ones, as in:
Exception in thread "main" java.lang.NullPointerException<br /> at mystuff.prog.main(prog.java:11) <br />where Java refuses to tell me which variable holds the empty pointer or faulty array index. This is no small irritation when one is calling a method that takes seventeen pointer arguments, any of which could be null.
Granted, it does at least deign to tell me the line number, and given its ineptitude with variable names, I am amazed it can do so. One imagines Java standing at a rain barrel full of tombola slips, as at a village fête. Scribbled on each slip is a statement and its line number; scrabbling through them all is Java, trying to find the slip whose statement text matches mine so it can report the corresponding line number.
Perhaps I'm being unfair to Java, but then again, perhaps I'm not. For its compiler messages are no better. You've written your program — it might be, let us say, an eigenvector finder for medical data reduction — and you have just completed the method for printing the results. A very nice method it is too, with ever so many options:
private static void printEigenvectors( int indentation<br /> , short line_spacing <br /> , boolean whether_pdf<br /> , float page_magnification<br /> , char vector_component_separator<br /> , double eigenvectors<br /> , String page_title <br /> , java.io.PrintStream output_to <br /> )<br />
But it's half past five already, and you really really want to see the results before you meet your mates at the pub. So you fling the program at the compiler as you grab your wellies and umbrella and get ready to set off. But what does Java come back with? This, and this only:
prog.java:13: printEigenvectors(int,short,boolean,float,char,<br />double,java.lang.String,java.io.PrintStream) in <br />mystuff.prog cannot be applied to (int,short,boolean,float,<br />char,java.lang.String,java.io.PrintStream)<br /> printEigenvectors( 4, 1,<br /> ^<br />1 error<br />
Is that easy to read, or does some compiler writer need to learn the word "ergonomic"? Surely, you mutter as you text a friend your food order because now you're going to be late, Java could apply a bit of nous, say a minimum-edit-distance between the formals and the actuals to tell you the type and position of the missing argument?
Even better would be a smidgen of context-dependence:
prog.java:13: <br />Dear Jocelyn,<br />you have an argument missing from your call to printEigenvectors <br />on line 13. I suspect it to be the double, local parameter <br />"eigenvectors".<br /><br />I have examined the method that calls printEigenvectors,<br />and I see that it has an unused variable named <br />"principal_component_eivects". Because "eivects" is <br />likely to be an abbreviation for "eigenvectors", and<br />because Principal Component Analysis uses eigenvectors<br />for its principal components, I suspect this variable to be <br />your missing argument.<br /><br />I have therefore recoded the method call so that it binds <br />"principal_component_eivects" to "eigenvectors". I then ran <br />the program, and sent the output to the best-quality printer in the<br />office, the upstairs one with the magnolia 125-gsm paper in it. <br />If I have recoded the method wrongly, thereby wasting the<br />paper, please contact Sun's Java team, who will refund<br />its cost.<br />
Sun, I hope you're reading this. But I shan't be truly satisfied until Java knows enough to stand me a pint at the pub. With such intelligence, though, it will probably insist on me standing it one.