Archives January 2011

Bourne Shell Introspection

So I was thinking about how to refactor our custom Linux and Solaris init scripts at work. The way FreeBSD does it is to have the scripts in /etc/rc.d define variables with the commands to execute, e.g.,

start_cmd='/usr/sbin/foobard'
stop_cmd='kill `cat /var/run/foobar.pid`'

run_rc_command "$1"

where $1 is “start”, “stop”, or whatever, and run_rc_command is a function loaded from an external file. It can check whether $stop_cmd is defined, and if not, take some default action.

This is great and all, but I was wondering whether it would be possible to check whether a given shell function exists. That way, a common file could implement a generic structure for starting and stopping daemons, and the daemon-specific file could just set the specifics by defining do_start and do_stop functions.

The way to do this in Perl is to iterate over the symbol table of the package you’re looking for, and seeing whether each entry is a function. The symbol table for Foo::Bar is %Foo::Bar::; for the main package, it’s %::. Thus:

while (my ($k, $v) = each %::)
{
	if (defined())
	{
		print "$k is a functionn";
	}
}

sub test_x() {}
sub test_y() {}
sub test_z() {}

But I didn’t know how to do it in the Bourne shell.

Enter type, which tells you exactly that:

#!/bin/sh

# List of all known commands
STD_CMDS="start stop restart status verify"
MORE_CMDS="graceful something_incredibly_daemon_specific"

do_start="This is a string, not a function"

do_restart() {
	echo "I ought to restart something"
}

do_graceful() {
	echo "I am so fucking graceful"
}

for cmd in ${STD_CMDS} ${MORE_CMDS}; do
	if type "do_$cmd" >/dev/null 2>&1; then
		echo "* do_$cmd is defined"
	else
		echo "- do_$cmd is not defined"
	fi
done

And yes, this works not just in bash, but in the traditional, bourne-just-once shell, on every platform that I care about.

So yay, it turns out that the Bourne shell has more introspection than
I thought.

Beneficial Mutations: a Reductio ad Absurdum

1) Premise: there are no beneficial mutations; all mutations lead to decay, disease, or death.

2) From (1), some mutations cause death.

3) Presumably, some mutations cause death at a very early age, or even in utero.

4) When young children die, they go directly to heaven.

5) Going to heaven is the best possible outcome.

6) Therefore, there are beneficial mutations. QED.

(Hat tip to the skunk-dicks at Irreligiosophy.)

Here Come the Religious Bigots

I mentioned earlier that there’s a bill in the Maryland legislature to allow gay marriage. So wouldn’t you know it, that’s bringing out the religious anti-equality brigade.

Via FSTDT, I learn about Protect Marriage Maryland, a group affiliated with NOM (at least, according to Yahoo! News; this fact appears neither on NOM’s nor PMM’s site, as far as I can tell. It’s almost as if they’re embarrassed to be associated with each other).

It’s just a holding page for now, but it says:

Protect Maryland Marriage is a Political Action Committee (PAC) formed to preserve the current Maryland Family Law §2-201 which states that “Only a marriage between a man and a woman is valid in this State.” The following sections go on to state that “A man may not marry his: grandmother; mother; daughter; sister; or granddaughter,” and that “A woman may not marry her: grandfather; father; son; brother; or grandson,” nor may they marry their in-laws, nieces, nephews, or similar family relations by marriage. All of this will be threatened if the marriage law is changed to benefit one small but vocal and well-funded sexual minority.

Oh, goody. A slippery-slope argument. We haven’t had one of those in, oh, fifteen minutes. If Adam and Steve are given the same legal rights as Joe and Mary, then it’s only a matter of time before daughters are having sex with their father, eating bacon is sanctioned by the state, and men are allowed to trim their beards! Who will save us from such defiance of God’s law?

We believe there is value in preserving the traditional definition of marriage, and that efforts to change this definition do violence to the family structure

Pray explain to me how allowing two men or two women to marry would affect existing marriages, or prevent me from marrying a woman?

and the reality that children do best when raised in a stable family with the love, attention, and physical presence of their biological mother and father.

I hear this argument a lot, and it basically comes down to stereotyping.

Let’s say, for the sake of argument, that the premise is true; that the optimal environment for children is for them to be raised by their loving and attentive biological parents. Let’s say that children raised this way have a 95% chance of completing college, of holding down a steady job, of not having any serious mental problems, of staying out of prison, of not becoming addicted to any drugs, and of maintaining a healthy body weight. All of that.

Let’s say that children of gay parents, children of divorced parents, children of gay parents, children of adoptive parents, children of parents who live together but aren’t married, all do worse than the optimum.

Let’s grant all that, for the sake of argument.

So what?

Should we tell unmarried couples that, because the odds are against them, they shouldn’t even have a shot at trying to raise normal, well-adjusted kids? Is that really the argument? “You probably won’t get an A+, so you shouldn’t be allowed to try”?

Because if that’s the argument, shouldn’t we forbid interracial marriages again, if those don’t last as long as intraracial marriages? Should we forbid marriages between members of different religions, for the same reason? Should divorce be forbidden once a couple has children? Should straight married couples be forbidden from adopting children?

Should we note that most world-class mathematicians are men, and forbid universities from admitting women into their math programs?

We believe that the current marriage law enshrines this reality. While some families may not always be able to provide such opportunities to every child, keeping the current law is the best way to respect the natural family, the rights of a biological mother and father to be able to raise their own children, to educate their children and teach them their own religious values–not the religious values of the state

The state doesn’t — or at least shouldn’t — have religious values. It should be neutral. That’s what the first amendment is all about, remember? Freedom of religion and freedom from religion?

Or is “teach […] the religious value of the state” code for “acknowledging that there are people of other religions, or none, and they have the same rights as we do”? If so, first amendment again.

–and to provide the model for an ideal family for children to be raised in.

For this argument to carry any weight, everyone who is currently allowed to get a marriage certificate in Maryland has to be put in the “ideal family” category. This includes serial divorcés, people who don’t like or want children, and so on, and so forth.

We are a non-partisan group composed of many faiths, different races, and all types of citizens who are concerned for the future of our state, our country, and our world being threatened

Our world is being threatened by gay marriage? Oh, puh-leeze. Quit whining and stop exaggerating. Don’t you know that hyperbole will melt the earth’s crust and unleash flocks of flying demon-hippos to piss on the heads of the godly?

by those who seek to force moral, law-abiding citizens to embrace or accept behavior that most of us find contrary to the tenets of our deepest religious & philosophical beliefs. The first Amendment to the U.S. Constitution guarantees that Congress will not violate our FREEDOM OF RELIGION. We firmly believe that as citizens of Maryland, our state legislature should do the same.

And you know what? Having the state grant marriage certificates will do nothing to stop churches from marrying whomever they like, or refusing to marry whomever they like. If you want to marry a man’s dog to his garden rake, go ahead (just don’t expect them to get a marriage certificate). And likewise, you can continue to be as bigoted as you like. Just don’t expect the state to impose your religious views on others.

The first amendment gives you the right to practice your religion. It does not give you the right to inflict it on others. You do not have the right not to be offended.

Here’s a video from ProtectMarriageMD’s YouTube channel:

[youtube http://www.youtube.com/watch?v=7NLPCkk9-YQ&w=560&h=345]

Note how they’re not even pretending that this isn’t motivated by religion.

Deconversion Story

Over on YouTube, Evid3nc3 has a movie about his deconversion:

[youtube http://www.youtube.com/watch?v=mSy1-Q_BEtQ&w=560&h=345]

I say it’s a movie because at nearly three hours (and counting; it isn’t finished yet), it’s really a documentary movie. But I think it’s well worth the time to watch it: for one thing, instead of just talking into a camera for three hours, he uses graphics to illustrate his points and to provide references.

For another, he covers the fact that religion “degrades gracefully”, as they say in systems parlance: there are multiple components, but none are essential (kind of the opposite of “irreducible complexity”). For instance, the phone system and power grid have lots of interconnected nodes, so that if, say, a station in Chicago breaks down, the rest of the system is unaffected: you can still make calls from Los Angeles to Mobile. The sound quality might suffer, or the system might only be able to handle a smaller load, but calls will still go through.

Likewise, there are a number of elements supporting religion: the morality it provides, the power of prayer, the influence of other believers, and so on. Even if you knock one of these out, e.g., by demonstrating that creationism is bunk, the other elements remain. Evid3nc3 goes through these and shows how each one, in turn, crumbled when he examined it closely.

His story also resonates with me because we both started out the same way: by trying to figure out the whole “God” thing, but also preferring truth over comforting fiction. Of course, big parts of his journey are different from mine, but the endpoints are similar.

On the Set with Religious Arguments

(This article was originally posted at Secular Perspectives.)

Have you ever watched a movie where some people are stuck in a broom closet or a train compartment, and wondered “Gee, I wonder how they managed to fit the camera operator in there with all those people”?

The trick, of course, is that they don’t: there’s a set with four walls that make the closet, and they remove one of the walls to allow the camera to shoot the scene. Then they can replace that wall and remove a different one, to shoot the scene from another angle.

All of these pieces of film are then edited together so that as you’re watching the movie as it cuts back and forth from one shot to the next, you’re also seeing scenery and props jumping in and out of existence (with the occasional revealing mistake — glasses inexplicably filling up, cigarettes magically growing longer and shorter, and so forth).

A similar phenomenon goes on in arguments and claims about gods: they may stand up on their own, but put together, they end up being mutually-exclusive. For instance, someone might say that religious morality is better than secular morality because God decides what the rules are, what is right and wrong. Regardless of what you think of this argument, at least it’s straightforward and internally consistent. That same person might then claim that God didn’t like the idea of Jesus’ sacrifice, but a blood sacrifice was necessary to atone for humanity’s sins.

But wait a second! Doesn’t God make the rules? If so, why didn’t he set them up in such a way that humanity’s sins could be forgiven without sacrificing his son? Between the two arguments, a stagehand in the theist’s mind came in and removed the “God makes the rules” part of the mental scenery, in order to make the “a blood sacrifice was necessary” argument work.

It isn’t hard to find similar examples: the Bible is God’s word and should be treated as, well, as gospel; except when there are contradictions, in which case mere humans had a lot of editorial control. God can’t reveal himself directly, because if we saw him in all his radiant glory, we’d have no choice but to love and obey him, and he doesn’t want to violate our free will; except that Adam and Eve (to say nothing of Satan) saw him and had conversations with him, and still managed to disobey him.

If you were raised religious, or have spent any time around religious people, you’ve probably picked up dozens or hundreds of such tidbits, that can’t all be true at the same time. This is perhaps best illustrated by the old observation that if Yahweh really did all the stuff in Genesis, and the gospels are true, and the doctrine of the trinity is true, then God sacrificed himself to himself in order to exploit a loophole in the rules he set up, that would allow him to forgive humans and not send them to the hell that he created, as punishment for being the imperfect beings he created.

Other arguments, like the problem of evil and the Euthyphro dilemma, highlight such inconsisties as well.

But if we’re serious about trying to figure out how the world works, we need to look at it from different, sometimes unexpected angles. You wouldn’t buy a house after having only seen photographs of it: how would you know the pictures weren’t carefully staged to hide the mold in the basement, or the fact that the east wall is missing? You would insist on walking around freely, seeing the property from different angles, peeking underneath cabinets, behind utility panels, and inside crawl spaces.

Science thrives on this sort of investigation. You can start by learning about gravity, which says that all matter attracts each other, note that rocks and water are both matter, and infer the existence of tides. A few years ago, scientists figured out that humans began wearing clothes 170,000 years ago by studying the evolution of body lice.

Of course, science also discards a lot of hypotheses, even cherished ones, like the possibility of faster-than-light travel, or the predictability of Newtonian mechanics. But such is the cost of building a solid edifice of knowledge.

And in the end, a movie set might be gorgeous, and a wonderful place to visit, but I wouldn’t want to live in one.

Gay Marriage Advancing in Maryland?

WaPo is reporting that a bill to allow same-sex marriage was introduced in the Maryland House and Senate.

It’s just a bill, yes it’s only a bill, and it’s sitting… um, in Annapolis-il? But still, I’m cautiously optimistic that it can pass. And if it does, that it won’t be overturned by referendum. Then again, I didn’t think Prop 8 would pass, so this isn’t a done deal.

Of course, Maryland has an argument that California doesn’t: gay couples can just catch the Metro or MARC train down to DC and get married there. I’m guessing that Annapolis would prefer if the money spent on weddings (and I don’t even want to think how much two wedding dresses cost) were spent in-state.

The same argument applies to Northern Virginia, but there’s the massive red southern part of the state (not to mention a comically-reactionary attorney general) holding them back. But once Maryland enacts marriage equality, Delaware might start worrying about its own wedding industry.

Adam and Bobo?

Anti-gay-rights activists, when they’re not busy being worried about all the buttsecks going on without them, are fond of pointing out that God made Adam and Eve, not Adam and Steve. Clearly, men are supposed to fuck women, not other men.

Except, remember why God made Eve in the first place?:

18 The LORD God said, “It is not good for the man to be alone. I will make a helper suitable for him.”

19 Now the LORD God had formed out of the ground all the beasts of the field and all the birds of the air. He brought them to the man to see what he would name them; and whatever the man called each living creature, that was its name.

20 So the man gave names to all the livestock, the birds of the air and all the beasts of the field. But for Adam no suitable helper was found.

<p .21 So the LORD God caused the man to fall into a deep sleep; and while he was sleeping, he took one of the man's ribs and closed up the place with flesh.

22 Then the LORD God made a woman from the rib he had taken out of the man, and he brought her to the man.

In other words, Eve was Plan B. The original idea, apparently, was for Adam to stick his dick in one or more of the animals. Literally get some pussy, if you will.

So I don’t see why the homophobes are so upset at the thought of two dudes getting it on. At least they’re dating inside their own species.

New Venue

I’ve been invited to be a contributor at Secular Perspectives, a blog associated with the Washington Area Secular Humanists.

My first piece is up now, and begins thus:

Have you ever watched a movie where some people are stuck in a broom closet or a train compartment, and wondered “Gee, I wonder how they managed to fit the camera operator in there with all those people”?

The trick, of course, is that they don’t: there’s a set with four walls that make the closet, and they remove one of the walls to allow the camera to shoot the scene. Then they can replace that wall and remove a different one, to shoot the scene from another angle.

All of these pieces of film are then edited together so that as you’re watching the movie as it cuts back and forth from one shot to the next, you’re also seeing scenery and props jumping in and out of existence (with the occasional revealing mistake — glasses inexplicably filling up, cigarettes magically growing longer and shorter, and so forth).

A similar phenomenon goes on in arguments and claims about gods.

Walking in A Winter Wonderland

The snow that was pelting Atlanta earlier has finally made it up here. It’s still at the “ooh, isn’t that pretty!” stage, rather than the “oh, no, not more goddamn snow” stage, so I went for a walk in it.

Yes, the world shrouded in snow and silence was beautiful. But what struck me is that I unconsciously started walking differently.

I usually walk differently in the snow; that part isn’t surprising. What I found surprising is that apparently I’ve internalized my snow gait to the point where I didn’t need to consciously turn it on. Huh.

Normally, when I walk on dry ground, my heel hits the ground first, followed by the ball. My legs don’t bend much.

But when I’m walking on snow, my whole foot hits the ground at the same time. I also bend my knees so that my foot comes down straight, rather than at an angle. It’s a bit like an elephant or a Star Wars AT-AT, where the thigh moves the most, and the shin hangs vertically down from there. As you can imagine, my steps are shorter and I don’t walk as quickly.

It all has to do with coefficients of friction. Plural. For those who have forgotten High School physics, there are two coefficients of friction between two given surfaces: the static one, and the dynamic one. Dynamic friction refers to how hard it is to rub the two surfaces against each other. Static friction refers to when the surfaces are motionless, and how hard it is to get one of them moving.

If you’ve ever received a box of equipment (say, a new computer) and tried pushing it across the floor, you may have noticed that pushing it along the floor is easier than getting it to move in the first place. That’s because when it’s just lying there, you have to overcome static friction to get it to move. When it’s already moving, and you want it to keep moving, you have to overcome dynamic friction. And the dynamic friction coefficient is typically lower than the static one.

Normally, when you’re walking, this doesn’t matter a lot: when your sole hits dry pavement, both the static and dynamic coefficients of friction are high enough that you can trust them to hold your foot in place and allow you to push against the ground for the next step. But on snow or ice, there’s a very real danger of slipping, falling into traffic, and having your head squished by a passing car.

In this light, I think my snow gait makes sense: hitting the ground with my entire foot at once means there’s more surface to take advantage of what little friction there is (though on the other hand (foot?), my body weight is distributed over a larger area, so there’s less friction per square centimeter; I don’t know how this affects things).

Putting my foot straight down means that it’s not moving with respect to the ground when it hits, which in turn means that I’m taking advantage of the static friction coefficient, which is higher than the dynamic one, to keep from slipping. And the “elephant walk” bit is just so that I can put my foot down vertically.

[youtube http://www.youtube.com/watch?v=4B_8DY30xDg&fs=1&hl=en_US]

So now that you know how to safely walk on slippery surfaces, go out there and enjoy the snow.

Snakes on A Euclidian Plane

Via A., here’s a cool video about doodling in math class, that somehow keeps circling back to knot theory:

[youtube http://www.youtube.com/watch?v=heKK95DAKms&fs=1&hl=en_US]

This should be required viewing for anyone who doesn’t see what the appeal of math is, or who thinks math is only about numbers and formulas.

My favorite line is the one about the two snakes who can’t talk to each other because one only speaks parseltongue, and the other only Python.