Some people laugh when they see my code, because I insist on the (supposedly old-fashioned and unnecessary) practice of using a "wart" to denote Java member variables. For example, I'll write
public class Person {
private String m_name;
private Date m_dob;
...
The laughers usually see this as a hangover from "Hungarian notation", in which the data type of a variable is encoded in its name. The merits of Hungarian notation have been debated endlessly, so I won't go into that here. Besides, my warts are not Hungarian: they're scope warts.
Scope warts prevent scoping errors; perhaps more precisely, they prevent accidental variable hiding. What's wrong with this code?
public class MyVector {
private int size;
private Object[] data;
public int itemCount() { return size; }
...
public void addAll(MyVector v) {
ensureCapacity(itemCount() + v.itemCount());
int size = v.itemCount();
for (int i=0; i<size; ++i) {
data[size++] =v.data[i];
}
}
}
Can you see it? That last line of code is incrementing the local variable "size", but it actually means to increment the member variable. Ooops. The loop will run until it gets an ArrayIndexOutOfBoundsException.
Scope warts would have prevented this. If we rename the member variable "m_size", then there'd be no name collision. Furthermore, collisions like this would never happen. A whole class of sometimes hard-to-find errors would be eliminated at the source.
Other people eschew the warts, but insist that all member variable accesses be made via the "this" reference. I don't like that, personally -- too much discipline. Scope warts require you to name variables a certain way, and then everything else takes care of itself. The "this" solution requires you to do some extra typing every time you access a member -- which is a lot of work. Anytime you ask people to do extra work, you're asking for trouble.
Why do I bring this up today? Because I just closed a bug report from a user. Seems a class I wrote in a moment of weakness -- perhaps just after someone had made fun of my warts -- didn't use scope warts, and contained a bug just like the one described here! So you see, this happens in real life. I'm going to stick with my warts; they've served me well.
Got my Wacom tablet working again today. My one real complaint about Linux is that every time you upgrade the kernel, you have to upgrade all your drivers. For some hardware (in my case, NVIDIA graphics cards and Wacom tablets) that means you either need to compile them yourself or wait for someone else to do it.
Anyway, as I was testing pressure threshold settings, I drew this picture of Danielle.
I don't belong in this right-turn-only lane. The light turns red and I wedge myself back towards traffic, waiting. The driver I'm butting in front of starts honking furiously. "Same to you, buddy," I think. But the honking keeps up and I finally look at the driver. He looks worried, and makes that hand-cranking gesture that means "I need to talk to you."
He calls through the open window, "I need to get to Baltimore!" Here we are, on Democracy Boulevard in Bethesda; we're not heading to Baltimore.
"The turnoff for the highway was back there a little way."
"I really don't know where I am! Do I want 270 North? 495 South? 495 East? I thought 270 North, but I wasn't sure..."
"No, 270 North is the exact opposite way! You want 495 East, then take 95 North when you get there."
"Thanks!"
"Uhhh... hey, I'm going to cut in front of you now," I said sheepishly.
"But of course!" he says, in his best "Grey Poupon" voice.
Just another day.
My father-in-law is dying. My wife is in Phoenix spending his last days on Earth with him in the hospital. I've stayed behind in Maryland with the two kids. They don't travel well, wouldn't behave in the hospital, and couldn't sit through services, when it comes to that.
I have to occupy their little minds and hands. Today they spent a happy hour in front of our house coloring the sidewalk with chalk. Zachary just scribbles, but he was very engaged. I drew him rocket ships and robots, enormous dinosaurs and dragons. He added scales and smoke and fire. Danielle drew flowers and smiling girls with long hair. She still hopes Pop-Pop will wake up and be OK.
We left the chalk and I took them to the community pool. Danielle swims beautifully, now like a dolphin, now like a shark. Laughing, always laughing. Zachary is shy and watches from the sidelines. He won't let you take off his size 18-24 month shirt in public. He doesn't like to get his clothes wet.
When we returned home, Danielle spotted a new smiling face, drawn with our abandonded white chalk, amongst her pink and purple ladies. Next to the round Have-A-Nice-Day face, an anonymous neighborhood child had scrawled "Hi" in a shaky but triumphant hand.
Exit, stage right. Enter, stage left. Laughing.