For entertainment, bored soldiers in the Afrika Korps would draw a circle of gasoline around a scorpion they'd capture.  They'd light the gasoline on fire and watch as the enraged, confused, helpless pest stung itself to death.
The always reliable David Brooks of the New York Times just keeps cranking them out.  Here's today's thumbsucker.

Brooks's record of deep thought is not a good one. Historically, his columns tend to report either that the earth is flat or that snow is cold with equal certainty and authority, based on how the summaries of other people's opinions that he's been reading square up with what he already believes. (I would bet you folding money that Brooks hasn't read an actual book by Gertrude Himmelfarb in twenty years.)  Today's column reports with great concern that there's a very cold snow blanketing the flat earth.

tl;dr: I don't like him.

What I observe in the twentysomethings I know: their big epistemological and moral struggles appear to stem from the absence of authority - not of a specific authority, but of the idea of authority. George W.S. Trow captured this almost twenty years ago in his essay "Collapsing Dominant," where he described the reaction of his young friends to seeing J. J. Hunsecker in Sweet Smell of Success: they wanted more of that. They recognized that Hunsecker's a monster, sure, but what they saw in the movie is something that has vanished from the modern landscape:  a world in which there could be an authority like that.

I think this comes from a lot of different sources. The largest is that authority has eroded because the people who once had it betrayed themselves as corrupt. (There's an idea you won't see David Brooks conjuring with.) It long ago became difficult to ignore the fact that the mainstream maintains itself by shitting on the margins, and that it will sacrifice its stated principles to do so in a heartbeat. If you know people in the margins, ignoring this becomes impossible - and young people are a lot closer to the margins today than I think they've ever been. For the most part, young people don't look at the controversy over gay marriage as embodying a moral dilemma; they see it as people who have power trying to deny it to people who don't. They see all manner of politicized issues - abortion, the war on drugs, anti-terrorism - in the same light.

The hostility to the idea of authority is central to their worldview. They embrace Wikipedia specifically because they know that it can't be trusted. Nobody gets disillusioned when an article in Wikipedia turns out to be biased; what do you expect from something that's communally authored? Wikipedia doesn't promise anyone that it's correct; all that it promises is that it's correctable. I don't think it's possible to overstate the importance of this idea to people who have grown up with no authorities that they can trust.

You can see this at work in the attitude towards music piracy. The old way of looking at things is: It's not okay to steal. The new way of looking at things is: The only reason that you even think of piracy is "stealing" is that the lawyers and PR people hired by a small handful of incredibly rich thieves are manipulating law and public opinion.

Which underscores a really, really important aspect of this attitude, and another thing you won't hear David Brooks introduce into the discussion:  They're not wrong.

Enhanced by Zemanta
This is really not a programming blog.  (It's scarcely a blog at all; I see that I haven't made a posting in about 11 months.)  But in the last couple of days I've run across some pretty bad misinformation about how to use the HierarchicalDataTemplate to create menus in WPF, misinformation that makes it seem much, much harder than it actually is.  The problem's exacerbated by the fact that Microsoft's documentation on the HierarchicalDataTemplate is of the gosh-it-magically-works variety, which doesn't really help you if you're trying to troubleshoot problems.

It's actually much easier to do this than a lot of people seem to think - at least, "easy" in WPF terms, which is to say, "utterly baffling until you begin identifying with your torturers."

Here's the story:

Just as a DataTemplate is a template for generating content controls, a HierarchicalDataTemplate is a template for generating headered controls.  

A headered control has two key properties:  Header and Items.  The Header property is a content control, and the Items property is an items control.  When a HierarchicalDataTemplate is applied to an object, it creates a headered control, uses the template to populate the control's Header, and then populates the control's Items by applying the HierarchicalDataTemplate to the child objects that have been specified by binding to the template's ItemsSource.

A trivial HierarchicalDataTemplate looks like this:

    <HierarchicalDataTemplate ItemsSource="{Binding Children}">
      <TextBlock Text="{Binding Text}"/>

This creates a headered control, sets its header to a TextBlock containing the source item's Text property, and then populates its Items by applying a template to each object in the source item's Children property.

The first time you start to work with this, you'll probably think to yourself, "Well, I want each item that gets created by this template to be a MenuItem," and make a template that maybe looks something like this:

    <HierarchicalDataTemplate ItemsSource="{Binding Children}">
      <MenuItem Header="{Binding Text}" Command="{Binding Command}"/>

You are now in a world of hurt.  

When you use a template to create items in a ListBox, you don't put a ListBoxItem in the data template, because you know (or should know, at least), that the ListBox generates the item container for you.  That is, this:

    <ListBox ItemsSource="{Binding Items}"/>

is going to generate a ListBoxItem for every object in the Items collection, and then use whatever data template it can find to produce the ListBoxItems' content. 

Well, so the Menu does this too.  A Menu like this:

    <Menu ItemsSource="{Binding Items}"/>

will create a MenuItem for every object in the Items collection.  And it will create a MenuItem for each of the child items in the HierarchicalDataTemplate's ItemsSource.  And so on down the hierarchy.

So if you put a MenuItem in your template, like I did in the seeminly simple example above, what will be created is an invisible MenuItem that has no header, and no command - but that does contain a MenuItem.  It will behave oddly, to say the least.

Well, okay, but then how do you set the command binding on the menu item?  Here is where things start to break down in the other examples you can find online.  If you look at this example, by the normally reliable Karl Shiflett, you'll find all of this code-behind that hooks into the content's Loaded event and navigates the visual tree to find the MenuItem that just got created and set its Command to the DataContext's Command property.  You do not need to do this.  You can do everything you need to do in XAML.

Just as you would in an ordinary data template that produces a ListBoxItem, you can set properties on the MenuItem that the HierarchicalDataTemplate produces, by using the ItemContainerStyle:

      <Style TargetType="MenuItem">
        <Setter Property="Command" Value="{Binding Command}"/>

That style gets applied to every MenuItem that the template generates and sets its Command correctly.  Now everything just works.

Another common issue when creating dynamic menus is creating item separators.  Menus created manually (i.e. in XAML) can contain a heterogenous mix of MenuItem and Separator objects, and look right.  But if you're using a HierarchicalDataTemplate, every item created is a MenuItem.  And if you simply make that MenuItem contain a Separator object, it looks wrong.

What you have to do instead is swap out the control template for those menu items.  This is easy to do:  just set a DataTrigger in the ItemContainerStyle that sets the Template property if the source object's IsSeparator (or whatever) property is set.

This is already getting pretty long-winded, and so i'll just point you to the fully-worked example project I built, which shows how to create fairly elaborate hierarchical menus entirely via data binding.


| | Comments (0)
I was walking down 24th Street the Monday or Tuesday after Michael Sanchez was shot at 24th and Shotwell.  It was about 11pm, and there was a group of young men and women all gathered around the corner store, drinking beer and talking.  On the wall of the store were dozens of photographs and notes, and there were candles and flowers arrayed on the ground.  I was just thinking that it seemed like a pretty sketchy crowd when I noticed a black-and-white had just parked on the other side of Shotwell.

The cop who got out of it was incredibly imposing:  very tall, black, totally bald, hugely broad shoulders, ramrod-straight back.  His uniform looked like he had just been ironing it in the car.  He slowly walked across the street, and I was sure that he was there to tell the group that it was time to get on its way.

But that's not what he did.  He didn't talk to them at all.  He went down on one knee, produced a candle of his own, lit it, and set it down with the others.  Then he went back to his car.

Lies, damn lies, statistics, and what the hell?

| | Comments (0) | TrackBacks (0)

Global Health Magazine is a publication of the Global Health Council, an NGO devoted to health issues around the world (particularly women and children's health issues, HIV/AIDS, infectious diseases, and health systems).  

If you poke around in their kicky web site, you'll come across this shocking graphic:

Are you shocked?  I'm shocked.

First off, the purpose of a pie chart is to represent relative portions of a whole, not comparative scalar quantities. If one wedge is made bigger, another is necessarily made smaller, and the whole pie represents 100%. This chart suggests, bizarrely, that one way we could reduce the amount of bad things happening in Jordan would be to collect statistics for more countries, since adding countries to this graph would make Jordan's slice smaller.

This is compounded by the fact that the wedges converge on a point that's not in the center, and the shape of the pie is not circular. So, Serbia and Georgia's wedges should be the same size, since one represents 6.2% and one represents 6.9%. Are they? Well, first off, what's their size, anyway? Is it the angle the two sides describe? Is it the surface area? In a circular pie chart whose wedges converge on the same point, these two things are one and the same; not so in this chart. I think that it may be the angle, and not the area, that represents the number, which is unfortunate because Serbia's wedge is noticeably larger than Georgia's.

Actually, now that I compare Rwanda and Jordan, I think that the person who drew this is just an idiot, because there's no way of looking at those two areas that makes one nearly twice as big as the other.

And now, another issue: What do Vietnam, Laos, Georgia, and Iraq have in common? What about Serbia and India? Nepal and Honduras? Well, nothing, or at least, nothing that makes any sense in the context of this chart. So why are Serbia and India black? Why are Nepal and Honduras red?

Let's not even get into the information-destroying jagged lines and concentric arcs.

And now let's move beyond the terrible, terrible graphic design to ask another question: why aren't Tajikistan, Kosovo, Guatemala, and Nigeria on this chart? Is this a graph of the 16 countries with the highest percentages of women who believe it's OK for their husband to hit them? Or is it just a sampling of third-world countries? I'd suspect the latter - I mean, not that I have it in for Sudan, but given that they're a Muslim country in sub-Saharan Africa, I'd think their numbers would be closer to Ethiopia's or Jordan's than to Serbia's or Belize's. But really, who can fucking say?

And wait, I'm not done yet. There's one more thing that bugs me about this. Why is Laos labelled as "Lao PDR"? Yes, the long form of the country's name is "Lao People's Democratic Republic," but I don't see "HK" in front of Jordan or "SR" after Vietnam. What's up with that?

The answer to that last question, at least, can be found in the source data, which for some reason singles out Laos for this weird special treatment. And while there are dozens of countries with percentages higher than Serbia's (so much for the top-16 theory), there's no data for Sudan. Too bad, Janjaweed wives, no statistical recognition for you!

Also, this data is even sketchier than I thought it is. The source for the chart is an appendix to a UNICEF report. Nothing wrong with that, except that as the data set makes clear, these numbers come from five completely different studies, which sort of makes the already suspect three significant figures even more so. Not that anybody involved with making this chart gave a shit, but would it have killed them to pick numbers from the same study?

Rather damningly, the biggest, most dramatic number on the chart - Jordan's 90% - is the only number in the entire data set whose source is not a study but a preliminary report on a study.

And finally, there's the little matter of changing the meaning of the data. This report doesn't list the percentage of women who think it's OK for their husbands to hit them. It lists the percentage of "girls and women aged 15–49 who responded that a husband or partner is justified in hitting or beating his wife under certain circumstances." It's like the difference between saying it's OK to steal money and saying it's OK to steal money from thieves.

This is a very bad chart.

That's quite an act you've got there.  What do you call it?
It's always an exercise in futility to try and clarify what you've written after people have read it, but here goes. 

The key phrase - it's buried in the penultimate paragraph, so my bad - is "in my mind." Of course Jackson was human. But he also appeared to be so utterly out of phase with ordinary human existence that he couldn't interact with it in any normal way. His response to the world, in general, seemed like it was intended to lessen his connection with what for want of a better word I'll call "humanity." But he was certainly human, for all that he appeared to be something else. Saying that he was "no longer really being human in any meaningful sense" is hyperbolic, to say the least. It's because he was human that what happened to him seemed so terrible. 

On to the issue of molestation: I used the word "probable" for a reason. I have uncertainty about what actually happened. But at the same time it seems likely to me that if someone's attorneys let him pay millions of dollars to settle a civil suit, they have some reason for not thinking that he's not going to win it. Hence, "probable." But I don't know the truth, and I don't pretend to. 

This brings us to the most important point about all: There is no way, no way in the world, that I know what Michael Jackson was really like. And not in the "we can never really know another human being" sense of not knowing what he was really like, either. Our word "fame" comes from the Latin fama, which originally meant "rumor". Virgil described Fama (the Romans' goddess/personification of rumor) as a hideous feathered creature who had as many eyes, ears, and tongues as she had feathers. 

That's who told me everything I know about Michael Jackson. 

My knowledge of Jackson is not only imperfect, it is also, almost certainly, fundamentally wrong. It's based on the crazy-quilt of public relations, gossip, art, and parody that hung between me and the real Michael Jackson. But even though it's fundamentally wrong, it's also all I have. And even though there's a crazy-quilt of myth hanging between me and the real Michael Jackson, there was a real Michael Jackson, a real person whose real outlines could be perceived through it. 

So why bother? Two reasons. 

First, he was literally inescapable. It was practically impossible to be a normal American growing up in the 1970s and 1980s and not be confronted with the idea of Michael Jackson. This idea was originally crafted with great care. It was the work of many hands. The idea's central objective was to be as known by as many people as possible. The people whose handiwork this idea was (including, it's essential to recognize, Michael Jackson himself) were extremely successful. I have ideas about who Michael Jackson was because it is close to impossible for me not to. 

The second reason is that there was, at the core of this idea, a real person. That real person, what I could make out of him, seemed to be in misery for a very long time. 

The understanding I've fashioned for myself about what caused that misery is, at the very best, contingent. I recognize that. But its contingency is not something to apologize for.  It can't be helped.  As Joan Didion pointed out thirty years ago, we tell ourselves stories to live. This is a strength, in that it lets us endure what she called "the shifting phantasmagoria" of our actual experience. It's also a weakness, because in constructing narratives, we impose an order on the real world that is not necessarily accurate or even present, and it is that distorted order, and not the real world, that we actually understand. The best I can do - the best anyone can do, really - is to remain aware of this process whenever I can, to remain aware that the stories I'm telling myself are, at best, only based on truth, and not the truth themselves.

I think the people who've called this posting "wonderful" (hi Cory!) and "smart" (hi Patrick!) are moved to do so because the narrative I've constructed for myself about Michael Jackson resonates, in some significant way, with the narrative that they've constructed for themselves.  It's not because I'm in touch with the truth about Michael Jackson.  If I'm in touch with any truth, it's the truth of what the emotional and intellectual experience of coping with the idea of Michael Jackson is like.

tl;dr:  It's all shadows on the cave wall.

Some thoughts on Michael Jackson

| | Comments (0)
I'm not really any sadder about Michael Jackson's death than I already was about his life.

It was clear that this was a guy whose Maslovian pyramid took a sharp turn somewhere above "safety needs" and ended up with its tip pointing in a direction nobody else has ever been interested in going.  It's always uncomfortable to see someone who's been ruined by fame; what was distressing about Jackson was that even though he was ruined by fame before his 20th birthday, he kept pressing the lever, and getting rewarded with still more fame, and still more ruination.  Fame ruined him as an artist and it ruined him as a person, and then it kept on ruining him.

In one sense, Neverland is just a point on the same curve that connects Iranistan, San Simeon, and Graceland.  But unlike its predecessors, the overarching sense that I got from everything I ever heard or saw about Neverland is not "this is what happens when you marry too much money to too little taste" but rather "this is an inarticulate expression of uncontained misery."  Also, Barnum and Hearst and Presley held their citadels of damaged self-expression till the day they died:  Jackson lost his.  And he didn't seem too unhappy about losing it, either.

The saddest thing about Jackson was not just that his fame ruined him, it's that it continued ruining him even after he was essentially finished as an artist.  In the last decade of his life he was no longer a great singer or a talented composer or a brilliant choreographer; he was someone who had once been all those things and was now Michael Jackson.  Here was a guy whose entire existence from early childhood had been wrapped up with what happened when he did things that made other people happy and excited. And that was unavailable to him.  He still could make people happy and excited by showing up and having his picture taken, but that's all he had left.

Someone on the WELL used a word about Jackson's probable history as a child molester that made me stop and think:  "unforgiveable."  It strikes me that it never even occurred to me whether or not to forgive Michael Jackson.  In my mind, he was so far away from normative that the question of forgiveness seems totally irrelevant.  Not that his no longer really being human in any meaningful sense justified his actions, or mitigated the harm he did, but that it makes no more sense to judge the morality of his actions than it would to judge Henry Darger's.  Their creepiness, sure. But this was a man (it's a mark of how profoundly damaged Michael Jackson was that it feels strange to call him "a man", just as it feels strange to recognize that when he died he was older than the President of the United States) who spent every day of his life embedded in a matrix of perverse incentives.  The terrain of his personal landscape was unrecognizable. I can understand the choices that my cat makes more deeply than I could understand the ones Jackson made.

His death has made me stop and think, but it hasn't made me mourn a loss. We lost Michael Jackson fifteen years ago.
There's a reason commentators are using words like "bloodbath" and "slaughter."  Though it reminded me more of one of those nightmares where you find yourself in your math class, on the day of the final, and you realize that you've been going to the wrong class all semester: the exam is covered with equations that you can barely recognize, you don't know where to begin, and for the next three hours all you can do is fail.

Cramer walked onto that show ready to defend himself against what Stewart had already accused him of.  He was utterly unprepared for what he got.  Which is strange, because what he got was really just an elaboration of what Stewart said in the original piece about CNBC and Rick Santelli:  this network seems to be in league with the traders against the investors, it's uncritical to the point of appearing collusive, and that if the network actually has a purpose beyond entertainment (and, seemingly, telling the fish how to line up for the sharks), it has manifestly failed.

And Cramer had nothing to say to any of that.  It was weird.  It's like he's never in his life prepared for a midterm by looking at a practice test.  The only thing he was ready to talk about was that sure, his predictions could have been better.  It's like he focused on the one single thing in the original piece that made him look silly, and paid not the slightest bit of attention to anything else.

I actually started to feel bad for him at one point.  Not bad bad, mind you - the clips from his 2006 interview that Stewart kept playing kept that under control.  But he was in zugzwang very early on.  Whatever ammunition he might have had to use in disagreeing with Stewart's criticisms of CNBC he left at home.  His knowledge and experience and common sense, which he did bring with him, gave him nothing he could use to counter Stewart - largely because Stewart's fundamentally right and he knew it.

But if he couldn't disagree with Stewart, agreeing with him was even less of an option.  Agreeing with Stewart would destroy him. 

So he babbled ineffectively.  You would expect that someone with his persona would be irritated if he got interrupted in mid-sentence by a long speech.  But every time that happened to him he looked unperturbed, maybe even relieved.  He was safest when he wasn't talking.

And so he let Stewart talk.  And what Stewart let loose with was, seriously, the clearest and simplest articulation of what has happened to us, of who did what, and to whom, and how it was done, that I've seen anywhere.

C# LRU cache released

| | Comments (0)
Of the small set of people who read this blog, a vanishingly small subset will care about this:

Because I needed an LRU cache in the project I'm working on, and I couldn't find one anywhere, I built one.  Since there's nothing proprietary in the code, and I'd like other developers to look it over and maybe even use it, I've released it as open source.  You can find it at