Saturday, March 29, 2008

What are pointers and why should I learn about them? -- Part 1

Recently, my elder daughter had a programming assignment dealing with binary trees. Her class(sic) is based on Java, which does not seem to have the notion of function pointers. Whether it has other pointers seems to be a matter of definitions, but our inability to imagine an "elegant" solution in Java (which I can barely spell) was irksome to me. Hence, while on an airplane, I coded a more elegant (to my eyes) solution in C, and wondered whether it was possible in Python.

I decided it was, and coded it -- but in spite of its elegance, it required a bit of syntactic anti-sugar. In other words, it was semantically pretty but syntactically ugly. I therefore wrote to a Python mailing-list at the office to ask whether there was a less ugly way to do this.

Unfortunately, the problem was misunderstood, and searches for "pointers python" yielded essentially two things: First, several commented that Python doesn't need pointers, if you're trying to use pointers in Python you're not writing Pythonic stuff, you sould write Python (not C) in Python, etc. Second, recent Pythons apparently have a pointer (or pointers?) class that's associated with calling C APIs from Python. It's an acquaintance of c_long, et al.

It is to this first group of commentators, and anyone who agrees with them, that I address the rest of this posting.

The programming assignment was to balance a binary tree. Basically, starting at the root, we do this:

while (nodes_on_left > nodes_on_right+1) {
find rightmost node in left subtree: make it the new root
move old root to be leftmost node in the right subtree
}
while (nodes_on_right > nodes_on_left+1) {
find leftmost node in right subtree: make it the new root
move old root to be rightmost node in the left subtree
}
balance left subtree
balance right subtree
She wrote basically the above in Java, and all the while I was wondering, can't we code it as

#define MOVE_ONE(FROMSIDE,TOSIDE)
find TOSIDE##most node in FROMSIDE subtree: make it new root
move old root to be FROMSIDE##most node in TOSIDE subtree
and then the recursive subroutine can be

while (nodes_on_left > nodes_on_right+1) {
MOVE_ONE(left,right)
}
while (nodes_on_right > nodes_on_left+1) {
MOVE_ONE(right,left)
}
balance left subtree
balance right subtree
or something like this? Apparently not in Java.

I was wrong (what, again??) -- see part 2 where I discover that I've been looking at this all wrong.

Bah, I must work on taxes now; to be continued...

Thursday, March 27, 2008

AirTouch Keyboard

I spilled a drink on my $6.99 used keyboard (a few years old), drowning it. So I bought an AirTouch Flexible Full Sized Keyboard.

Here is what I think: after typing just what you see here, my fingers hurt. It is hard to type with it if you are a touch typist. Two-finger typing is OK, more or less.

I may keep this around as a relatively indestructible spare, for "emergency" use only. Unless you want to buy it from me... I paid about $18 including tax, at Action Surplus. But I don't recommend it.

Tuesday, March 25, 2008

Gas stations near Dulles Airport

If you're returning a rental car to Dulles Airport "near" Washington DC, don't do what I did and go hunting for gas stations at random exits off 267 or whatever. There is a gas station at the airport -- take the access road in the usual way, and head toward the car rental return area. The gas station will be conveniently on your right. I don't think you can possibly miss it.

By the way, google maps does not seem to know what a gas station is in downtown DC either, so that is something else you should not copy from me. They said there was one at a 7-11 at Rhode Island and 14th NW. There's a 7-11 there all right, but no gasoline.

Anyway, as a result of my spectacular mismanagement of gasoline, I didn't get to IAD in time to check my baggage "safely" -- I got a squeal out of the machine and it told me my bag was late. Hand-carried it onto the plane and had to toss a 7-oz toothpaste tube. Well, it was more than half-used anyway.

Monday, March 24, 2008

A prayer for my daughters and nieces

I just found this while looking for something else. It's a prayer of blessing for a new baby girl, but it's something I wish for my (now teen-aged) daughters and my nieces -- my sister's daughters Jana and Karina, as well as my daughters' friends -- who aren't really nieces, but I think of them that way anyway. Here's the prayer:


O God,

All of our instincts tell us to pray for nothing but good things for this child,

But we know that this is self serving and short sighted.

So, we pray that you will give her whatever she needs to be your person.

We pray

You will give her enough joy to make her cheerful and serene

      and enough sorrow to make her big hearted and compassionate;

You will give her enough success to make her confident and hopeful

      and enough failure to keep her humble and dependent on you;

You will give her enough of the cross to make her life Jesus

      and that resurrection power will always be present in her life.

We pray, O God, that you will hold her so close to you side

      that the Evil one cannot touch her.
from Eric Magnusson's blog entry of 2007-04-30

Becoming a slacker

Recently I heard Nouwen's quote:
As I entered into my fifties and was able to realize the unlikelihood of doubling my years, I came face to face with the simple question, "Did becoming older bring me closer to Jesus?"

After twenty-five years of priesthood, I found myself praying poorly, living somewhat isolated from other people, and very much preoccupied with burning issues. Everyone was saying that I was doing really well, but something inside was telling me that my success was putting my own soul in danger. I began to ask myself whether my lack of contemplative prayer, my loneliness, and my constantly changing involvement in what seemed most urgent were signs that the Spirit was gradually being suppressed.
In the Name of Jesus
Along these lines, I just read something about this in Buchanan's provocative Your God Is Too Safe, about disciplines. It comes via John Ortberg, who got it from Dallas Willard:
A discipline is any activity within our power that we engage in to enable us to do what we cannot do by direct effort.
Dallas Willard, The Divine Conspiracy
page 353
I have lately been somewhat of a slacker -- ah, strike "somewhat of"; I have been a slacker when it comes to these disciplines. Why do I not love, why do I not care about people the way Jesus does? Why do I lack power to change myself? Partly because I've not been praying or meditating upon the Scriptures much. I've been studying, writing, teaching, working, so my slackness isn't of that nature. Rather it's been somewhat in the sense that Nouwen writes about -- praying poorly (and too little maybe) for example. And living, as Buchanan says, "in borderland," rather than in the "holy wild." Well, the "wild" business isn't such a good meta4 for me; I'm not a "wild" kind of guy.
(Digression: We spotted Krakauer's Into the Wild at B&N in Baltimore, and the younger teen asked how I liked the movie. "I wanted to slap him," I replied. "He had no right to throw his life away like that.")
But the concept of being more connected to God, of abiding in Christ (as John 15) -- that's something I can see is important and desirable. I want it!

Lord, please let me not sink to be a clod! (poem text here)

Sunday, March 23, 2008

Parking near Baltimore's Inner Harbor

We visited Baltimore's Inner Harbor shortly after dropping the elder teen at BWI, parking here:

View Larger Map
My advice: Don't do that if you're going to be there a few hours, as we were. Instead, try the Pier V garage. This will save you $8-$10.

Now it was a beautiful day (I'll pre-date this to correspond to when we went there) and had a great lunch at McCormick & Schmick (sp?) -- pricey but good food. The weather was wonderful. We also went up to the top of Baltimore's world trade center building and got some great pictures.

Saturday, March 15, 2008

Why did he write this?

I ran across this quote by Harvard biologist Richard Lewontin in a book that came in the mail when the elder teen was considering Calvin College (Grand Rapids, MI). It's refreshing to see someone so forthrightly admit his prejudices, but I wonder what drove him to write it:
Our willingness to accept scientific claims that are against common sense is the key to an understanding of the real struggle between science and the supernatural. We take the side of science in spite of the patent absurdity of some of its constructs, in spite of its failure to fulfill many of its extravagant promises of health and life, in spite of the tolerance of the scientific community for unsubstantiated just-so stories, because we have a prior commitment, a commitment to materialism. It is not that the methods and institutions of science somehow compel us to accept a material explanation of the phenomenal world, but, on the contrary, that we are forced by our a priori adherence to material causes to create an apparatus of investigation and a set of concepts that produce material explanations, no matter how counter-intuitive, no matter how mystifying to the uninitiated. Moreover, that materialism is absolute, for we cannot allow a Divine Foot in the door. The eminent Kant scholar Lewis Beck used to say that anyone who could believe in God could believe in anything. To appeal to an omnipotent deity is to allow that at any moment the regularities of nature may be ruptured, that miracles may happen.
This apparently came from a 1997 issue of The New York Review of Books.

Essentially, he's admitting that his philosophical preferences drive his interpretation of any data turn up. If God Himself were to turn up in the data, in other words, Lewontin would by his own admission be neither willing nor able to recognize the fact.

I think it's silly, but at least Lewontin 'fesses up to his religion. I don't know if Dawkins has 'fessed up to his, but somehow I doubt it.