When is Private not Private?

One of the many things I have always disliked about C++ is the way it handles encapsulation … or rather, the way it doesn’t. Class members marked as “private” certainly don’t seem to have much privacy. The declarations are right there for everyone to see, possibly revealing a lot about how the class is implemented and allowing subtle dependencies to creep in. A simple “#define private public” before including the header file makes private members fully accessible, and yes, I’ve seen it done. Most annoying of all, or perhaps that’s just because I tripped over this one, anyone who includes the class’s header file has to carry along all of the class’s include-file dependencies so that it can resolve types etc. of members it supposedly can’t and definitely shouldn’t use anyway. The effects can range from minor annoyance all the way up to circular-dependency hell. This is just a brain-dead approach to encapsulation.

Another thing I have always disliked about C++ is the fact that a number of “best practices” have been developed to work around warts like this one instead of fixing them. Just knowing the language isn’t enough; now you have to know all of the tips and tricks too unless you want to have more experienced C++ programmers look down their noses at you for falling into one of the language’s many pitfalls. In this case proper encapsulation can be achieved pretty simply by using an externally-visible abstract base class, and then a derived class that actually provides all of the implementation and as a result isolates all of the dependencies away from users of the base class. This works, at the cost of making it impossible to inline even trivial base-class methods and thus hurting performance, but the point is that it shouldn’t even be necessary. Modula supported separate definition and implementation decades ago, so it’s obviously not a hard problem for a modern compiler to deal with the concept. Here in 2005 programmers shouldn’t have to deal with a change that’s purely to a class’s implementation effectively changing its interface as well.

Unusual Tastes

I’ve always known my taste in music was a bit eclectic but I always thought it was the combinations (e.g. Kitaro to Guns ‘n’ Roses) more than the invididual songs/artists. Then again, maybe not. Every once in a while I go to CD Baby and listen around. Their “new arrivals” pages, arranged both by time and by genre, offer a great browsing experience. Usually browsing is all I do, but every once in a while I buy a batch of CDs – why there always seem to be batches that appeal to me all at once instead of just one at a time is another mystery to me, but that’s the way it works. In my latest batch, I was a bit surprised that four out of five were so new and/or obscure that CDDB didn’t know about them yet. Even more surprising was that the one hit wasn’t for Bethany Curve’s Flaxen (even I had heard of BC before); it was for Ether Aura’s Crash. I guess I’m just so far out at sea musically that I’m not even sure where the shore is any more.

In case anyone is curious, the others are Riverine by Autumn’s Grey Solace, Different Stars (2004 Nettwerk version) by Trespassers William, and Wait for Someday by Half Light. All of them are in the shoegaze/dreampop/ethereal area, heavy on the reverb and (except for Crash) seriously down-tempo. Interestingly, Crash is probably my second favorite despite being the oddball of the bunch (or maybe the one non-oddball). So far my favorite is Different Stars, which is also the slowest of a slow lot. “Haunting” is a good way to describe it, unless “soporific” works better for you. As far as I’m concerned it’s great stuff.

Trust in Distributed Filesystems

A while back I posted here about an NSF program called IRIS (Infrastructure for Resilient Internet Systems). More recently, I noticed an IRIS-funded project called Shark, which aims to create a high-performance distributed system based on cooperative caching of data by clients. This is interesting to me in a couple of ways. One is that it’s extremely similar to both of my last two projects at EMC – the one that shipped was a cluster filesystem named HighRoad, and the second (internally “C3D”) was a distributed block layer that would have extended HighRoad from the data center to the geographically-dispersed enterprise (among other potential uses). In fact, it’s immediately obvious to me that several elements of Shark mirror patents that are pending for EMC based on that work, including one that was already granted before the Shark project even existed. I’d probably be more chagrined about that if I didn’t have mixed feelings about EMC seeking those patents in the first place, but in any case that’s not why I’m writing this.

The real point I want to get to is about trust, and is only tangentially related to Shark. Trust is an issue that anyone designing a distributed filesystem (or similar system) has to deal with. What do you trust your peers – by which I mean merely the other nodes with which you communicate – to do or not do? There’s not really one right answer, but it’s very important to ask the question. There are at least four aspects of trust that need to be considered:


A colleague who is traveling in China (hi Matt!) reports that my humble little website is being blocked by the Great Firewall of China. It’s an interesting bit of serendipity because I just happened to mention China in my last post, but the email was sent before that was published so the blockage must be due to something else. I’ll have to check my old logs for hits from there and see which pages were involved.

Fate of Africa

I recently finished slogging through Martin Meredith’s book Fate of Africa, about the history of various African nations since the end of the colonial era to the present. It was a slog not only because it’s so long or because it’s so depressing, but also because it’s so repetitive. Some of this is not Meredith’s fault; he’s repetitive because the history has been repetitive. From Nkomo and Nkrumah and Nyerere through Mengistu and Mobutu and Mugabe (see how the mind numbs already) the story always seems to be the same – strongman comes to power either through a coup or a revolution, makes many promises to reduce corruption and improve political/press freedom, within a year or two reverts to the same kind of cronyism and tribal favoritism as before. Sometimes they’re obvious thugs from the outset. Other times they seem to start with good intentions, but then crumble under the onslaught of poverty and disease and demands from their supporters and the next guy trying to do to them what they did to their predecessor. Either way the result is chaos and misery.

Meredith offers few solutions, either. There’s a desultory “there’s still hope” chapter at the end, but very little evidence of any actual reason for hope. The patterns seem too universal, and one cannot help but wonder why Africa seems particularly susceptible to these problems. Despite the inevitable charge of racism, it’s almost impossible to read this book and not wonder if there’s something about Africa that makes it more susceptible than Asia or Latin America to these sorts of problems. I can think of two reasons, both akin to Jared Diamond’s “accidents of geography” from Guns, Germs and Steel. One is that Africa had the misfortune of being closer to Europe than those other places. Europeans were more inclined toward colonization and exploitation of their southern neighbors than (for example) the Chinese were toward theirs. The Europeans wanted to make the rest of the world more like them, whereas the Chinese have historically been confident with their own position at the center of the universe and content to let everyone else rot. The case of the Chinese admiral who is said to have discovered America but not cared enough to start any sort of colonization effort is a case in point. Even now, aside from some disputes with Taiwan/Japan/Korea, the Powers That Be in China seem to feel they have enough on their plate already and don’t need to acquire more territory from their neighbors. Maybe Africa has just suffered from being plundered rather than ignored, establishing a pattern that persists even in an Africa (largely) ruled by Africans.

The other possibility has to do with tribalism. In Asia and Latin America, the dominant cultures drove out competitors long ago so that even historians have great difficulty finding out much about those competitors. The resulting empires were in most cases large enough to be turned into viable nation-states. In Africa, by contrast, a great many ethnic/cultural groups have existed (or been maintained) at near parity. Whether it’s the Hutu and Tutsi in Rwanda/Burundi/Zaire or the Hausa/Fulani and Yoruba and Igbo in Nigeria or any of a hundred other examples, tribal conflict has been a major contributor to Africa’s sad history. Many of these groups are too small or resource-deprived to form viable nations of their own, or divided across several of Africa’s arbitrary national borders, but large and powerful enough to destabilize the nations they share with others. It’s tempting to think that things would be better if tribal identity were diffused, but that has been tried many times and many ways without yielding a solution to either the moral or practical problems involved. Trying to make the political/economic boundaries match the ethnic/cultural ones hasn’t worked too well either, as the history of the area from which that approach often takes its name (“Balkanization”) reveals all too well. In the end it seems that something even more fundamental than national boundaries will need to change before we can have an Africa free of such strife and deprivation.

Church vs. State

Apparently the IRS has threatened to revoke the tax-exempt status for All Saints Episcopal Church in Pasadena CA because of an anti-Iraq-war sermon. In a way, that’s exactly what they should do. The tax-exempt status granted to churches is like part of a treaty between church and state in which they agree to refrain from meddling in each other’s affairs. When one side violates their part of that treaty, the other part becomes null and void. All Saints engaged in a political act, and thus in my opinion repudiated the agreement under which their tax exemption was granted.

There is a problem here, though. More conservative churches have been quite actively promoting a political agenda for some time. They’re quite obviously driving much of the Supreme Court nomination agenda, for example. Last time I looked, the diocese of Colorado Springs has not received a letter from the IRS, despite repeated acts even more overtly political than those at All Saints. What’s the difference? It’s pretty obvious: in Colorado Springs a church’s political activity supported the current administration’s agenda, while in Pasadena they opposed it. Unequal enforcement of a law is itself a form of injustice. The church in Pasadena should be at risk of losing its tax-exempt status, but so should the church in Colorado Springs (and many others that have acted similarly). When the government tries to enforce tax law against one while giving the other a free pass, they are engaging in a form of religious discrimination and have done more damage to the first amendment than either church.

This is only the latest sign that the Bush administration has zero respect for the Constitution its leader is sworn to uphold, and see it only as a rhetorical tool in support of a completely separate (and conflicting) agenda.

Update, November 9: this item has received a lot of attention from others, but so far the most specific evidence of an IRS double standard seems to be on Mahablog (via Alas, a blog via Mark A.R. Kleiman at Reality-Based Community).

Amy in October

Click below to see the latest batch of Amy pictures.

Got a Secret?

I don’t know how to categorize this, but it’s interesting. PostSecret has postcards from people who have (or claim to have) some sort of deep dark secret that they can only express anonymously. Some of the secrets (e.g. “molested” and “before you died”) are pretty predictable, though no less poignant for that. I think the two most surprising, which make an interesting pair now that I think about it, are “our son” and “not mine.” Like Found, it’s the sort of thing that just makes me marvel at the richness and weirdness of the human experience.

C++ Parsers

Several of the projects I want to pursue some day have to do with automatic examination and/or manipulation of source code. In the past I’ve played with TXL but found that – while it’s tremendously useful in certain circumstances – its focus on transformations between equivalent code is too limiting and the grammars available for my languages of interest (primarily C/C++) are incomplete. For my stack ripper I used the “-fdump-translation-unit” feature of gcc itself, and it mostly worked, but I found that both the format and content of its output were a bit random and buggy. Several other projects, such as GCC-XML and smatch, use basically the same approach – inheriting the same problems and/or requiring patches to specific gcc versions to make the output saner. I’m apparently not the first to go on this kind of search for a decent parser, so maybe there are others will be interested in what I’ve found.

What I’ve found, via andy@nobugs.org (last link above), is Elkhound and Elsa. Elkhound is a parser generator, and Elsa is a C++ created using Elkhound. Both look quite “real” in the sense of being able to handle real C++ (not just an easy-to-implement subset) without choking and of producing parse trees that can not only be examined but can also be manipulated within a program without undue pain (this stuff’s never going to be easy). Here’s what the project page has to say about completeness.

Elsa can parse most C++ “in the wild”. It has been tested with some notable large programs, including Mozilla, Qt, ACE, and itself. I have not tried parsing KDE recently, so that’s the next major goal.

In C mode, Elsa can parse most C programs, including the Linux kernel (our highest-priority C program). It handles most gcc extensions, including K&R function definitions and the “implicit int” rule. There is a good chance it will parse your C program.

As for usability, the tutorial (nice that it even has one) includes an example of using Elsa for a semantic grep that can find uses of a particular identifier without being fooled by similar names and commented-out code and all that other stuff that causes programmers to grumble when they’re using simple text matching for this kind of stuff. This kind of functionality is a key building block for the sorts of things I want to do, and its implementation looks short and straightforward enough that I won’t go totally nuts fighting with my tools.

Overall, Elsa looks like something that could be very useful as a basis for some of my future projects. If you’re thinking of doing anything that involves parsing real code, such as searching for instances of known bugs or adding language features, Elsa might be a really good place to start.

Bad Reviewers

Lucius Shepard is the movie reviewer for the magazine of Fantasy and Science Fiction. I vaguely remember disliking his stories in that magazine twenty years ago, but the pretentious snobbery that was apparent back then has apparently only increased over the years. He never seems to miss an opportunity to set himself above the masses, and Americans in particular, as in these examples from this month’s review.

You know, the kind of values that a goodly number of Americans have a childlike faith in, but that don’t exist outside of Norman Rockwell paintings, Disneyland, and the movies.

Spielberg’s success as a director is chiefly due to the fact that he portrays Americans as we like to see ourselves: a simple, good-hearted people, a little dysfunctional, but boy-oh-biy are we ever endlessly brave and resourceful when aliens threaten our precious kinder.

This month’s review is of Spielberg’s War of the Worlds, starring Tom Cruise. Yes, I know that’s a recipe for cinematic disaster. I’m sure it’s a thoroughly awful movie, fully deserving of some bad press, but the stench of professional jealousy that wafts from Shepard’s review is overpowering. “Here’s how I would have done it,” says Shepard, describing his version in detail toward the end, “but Spielberg did it this other way so I’m going to spoil any surprises that were left in this adaptation.” Along the way, he goes far out of his way to malign Spielberg in ways that have little to do with the movie, with talk about “an old man’s halting instincts” merely the most egregious example.

One can only wonder why Shepard bothers to write reviews of movies he hates for an audience he despises. Then again, maybe I shouldn’t complain because I’m sure I’d be bored to tears hearing about the movies he does like. What’s even more amazing is that F&SF gives this bitter little man the space. Don’t they know that the “grumpy old fart” schtick wears thin after a (very short) while? I don’t want to read movie reviews by Andy Rooney’s oh-so-literate alter ego – emphasis on ego – and I doubt many others do either. They’re doing neither us nor themselves any favors by letting the travesty continue.