My new short story is The End of All Meeting. It’s a bit preachy but it helped me sort some thngs out. Have a read if you want.
Null is not Null
If you select length(’’) from dual in Oracle what you get in return is a null. I was trying to prevent string buffer overflow using some code like:
if length(buffer)+length(message) < 32767
buffer := buffer || message ;
end if ;
Ah yes but buffer was initialised to ‘’, with me thinking that its length would be 0. Nope, its length is null. Then remember the golden rule any operation involving null returns a null, any boolean operation is always false. Yes, you guessed it, the buffer remained empty. This took a bit of finding because I thought I’d dealt with it by setting the buffer to ‘’. Interestingly this means that you can’t have a varchar2 string that has a length of 0, you have to nvl the length to 0. Of course, if they fixed this a mountain of code would break, I have used it myself occasionally.
This gives us the interesting paradox
null is false
not null is false
null <> not null is false
My head hurts.
Fun with inheritance
I got to the bottom of the bug with my old code. I had refactored a class that I was doing a lot of inheriting from into an abstract class so we had something like:
public abstract class XMLActions
String currentTable = “” ;
static String sourceFile = “public_html\data-model.xml” ;
boolean firstColumn = false ;
boolean firstViewColumn = false ;
boolean firstTable = false ;
boolean doWhere = false ;
PrintStream os = System.out ;
Map tagTables = new HashMap() ;
/* … */
final public void characters
( final char ch
, final int start
, final int len )
if ( doWhere ) // we are inside a view
final String text = new String( ch, start, len ).trim();
if( text.length() > 0 ) os.println(text);
The inheriting class (which was the original) implements an abstract method called handleViewWhereClause (trips off the tongue) that sets the doWhere boolean so that the text will be echoed out to the output stream. But silly me, I had left the instance variables in it when I factored it out. This class was setting its local attribute of the same name and the parent class was blithely ignoring it. Here endeth the lesson.
Making laptop screen fonts clearer in XP
Right click on the desktop. Select appearance, check effects, check cleartype on font smoothing. Got it from an O’Rielly book XP Pro : The missing manual. I might even buy it rather than looking at it in PC World, but probably not from them. I haven’t paid the retail price for a computer book in ages and I’m not about to start now. There’s also one on setting up WiFi which looked OK, but I haven’t had a problem with WiFi: just read the manual.
Blessings and good health all.