Tuesday, October 23, 2012

MC Complete's Guide for the Perplexed, Part 1: Prayer

Daniel: I don’t get this whole prayer business.

Isaac: Prayer is praise, requests, and thanks.  What is there not to get?

Daniel: What about the requests?  What is the sense in asking Hashem to do things for me?  Doesn’t He already know what I want?

Isaac: Yes, he knows what you want.  But most of the time, you don’t ask for the things you want.

Daniel: I don’t?  What do you mean?

Isaac: Every Jew has his own specific set of desires.  But we all say the same Shmone Esrei.

Daniel: That may be, but how does that solve anything?  Doesn’t Hashem know what I’m going to say?

Isaac: Of course not.

Daniel: What?  What do you mean?

Isaac: Hashem knows the text of the Shmone Esrei very well.  He knows it by heart.  But he doesn’t know whether you are going to say it.

Daniel: Wait a minute.  Are you saying that God doesn’t know the future?

Isaac: No, it has nothing to do with that.  All I mean to say is that if you say the Shmoneh Esrei you say it, and if you don’t say it, you don’t say it.  God’s knowledge of the future, as well as His knowledge of the text, is irrelevant.

Daniel: Are you saying that Hashem want me to pray so that I focus on the needs of the community rather than my own?

Isaac: Exactly.  Better to pray for the needs of the community and take care of yourself, than to pray for your own needs and take care of the community.

Daniel: OK fine, let’s take one of the blessings of the Shmoneh Esrei.  Let’s take Refaenu.  In Refaenu, I ask Hashem -- we all ask Hashem -- to heal the sick Jews.

Isaac: Right.

Daniel: Does my prayer make it more likely that Hashem will heal the sick Jews?

Isaac: Hashem will heal the sick Jews.  We know that for certain.

Daniel: Well, I suppose we know (almost) for certain that He will heal some, but we also know for certain that He won’t heal them all, at least until the Moshiach comes.

Isaac: And maybe not even then.

Daniel: OK, so does my prayer make it more likely that a greater percentage of the sick Jews will be healed?

Isaac: We don’t know.

Daniel: I mean, on what basis does Hashem decide what percent will be healed?  What factors enter into these kinds of decisions?  What motivates Hashem?  What is He trying to achieve?  Why did he make people sick in the first place?

Isaac: We don’t know.

Daniel: So what is the significance of my prayer?

Isaac: Hashem cares about you.  You are asking Him to heal the sick Jews.  He will decide what percentage, based on His own calculations.  That’s all we know, and all we need to know.

Daniel: OK, I don’t know if you answered my question, but you certainly confused me enough that I no longer remember what my question was.

Tuesday, October 16, 2012

Mocks: A Guest Post by Zach Lloyd

So, you wrote a test that uses mocks where you could have used real dependencies...

I have a few major issues with this style of test:

  • It tests implementation, not behavior.  Why should a test care what methods are called within a function being tested so long as the function behaves in accordance with its contract?  With these kinds of tests it’s often possible to change a function to use a completely equivalent implementation, and yet the test fails after the change.  In the extreme, test cases like this end up purely mimicking the implementation of the method under test (e.g. if the method being tested calls x(), y(), z() on its dependency, then you will see that exact same sequence of calls in the mock setup).  This ends up testing nothing at all.
  • You can't even write a test with mocks like this without looking into the implementation of the class under test, which adds a lot of complexity to test writing and maintenance.
  • It takes me a non-trivial amount of mental effort to read one of these test cases with mocks -- much more than reading regular code.
  • I've never believed the argument that it's somehow bad to test real code.  Unless the dependency is truly on something that's hard to test reliably (like a network), I think you absolutely should be testing the real dependency by default.  I know the testing people disagree with this, but I don't particularly care.  The tests should be on an environment as similar to the real application as possible IMO.

I do feel pretty strongly that tests that use mocks like this are bad, but I'll leave it up to you whether you want to change it.

Wednesday, September 5, 2012

Quantum Theology

IMAO, the biggest philosophical problem of Quantum Mechanics is the “measurement problem”.  According to Quantum Mechanics, “measurement”, or “observation”, collapses the wavefunction of a particle.  Particles behave one way when we are looking, and a very different way as soon as we divert our gaze.

(For more background on the quantum measurement problem, see my blog post  http://mccomplete.blogspot.de/2012/07/decoherence-and-flying-fish.html .)

It’s almost as if there are two worlds: the visible world and the hidden world.

I want to call attention to two differences between the visible world and the hidden world:

In the visible world, any given particle at any given time is in one, and only one, place.  But in the hidden world, at any given time, any given particle can be in more than one place.

The behavior of the hidden world is almost absurd.  If a particle is in two places at the same time, it shouldn’t be one particle anymore.  It should be two particles.  But it isn’t, it’s still only one.

In my arrogant opinion, this is a kind of miracle.  In conventional miracles, isolated events defy the laws of nature.  But in the quantum miracle, the laws of nature defy the laws of logic.

The hidden world is absurd and miraculous.  The visible world, on the other hand, is coherent.

There are miracles happening constantly all around us, but we can’t see them.  They’re hidden from us.

Now for the second difference between the visible world and the hidden world:

The hidden world is deterministic and the visible world is nondeterministic.  The hidden world is entirely governed by natural law; the visible world is influenced probabilitsically by natural law, but it is, in a sense, chaotic, lawless.  So the world behaves lawfully, but the lawfulness is hidden from us.  When we look, all we see is lawlessness.

Maybe Divine Providence is like this.  Maybe the world is lawful and just, but the lawfulness is hidden.  Maybe behind the veil of coherence, good things happen to good people, but when we look, all we see is lawlessness, chance, indifference.

Shiluach Haken, Part 2: The Reward for Mitzvot

In the end of Masechet Chullin, the Gemara tells the tragic story of a father who told his young son to climb up a tree and get some eggs.  The boy climbed up the tree, sent away the mother bird, lost his footing, and fell to his death.

The boy had performed two mitzvot: honoring his father, and sending away the mother bird.   The Torah promises a long life as a reward for both mitzvot.

Elisha ben Abuya declared, “There is no justice and no Judge,” and went off the derech.

Rebbe Akiva declared, “There is no reward for mitzvot in this world, but in the next world, there is reward.”

On the other hand, every morning after the blessings of the Torah, we recite the Mishna of Elu Devarim.  Elu devarim says that there are mitzvot that bear fruit in this world, while the principal is saved for us in the next world.  (One of the mitzvot listed in Elu Devarim is honoring parents.)

I think that the mitzvot have a component of prudence.  Following the mitzvot is often the most responsible way to act.  Sometimes the mitzvot good advice about how to act wisely and achieve our own self-interest.  For instance, if you do acts of chessed, the recipients will sometimes return the favor, and the members of the community will like you and give you honor and support.  The study of Torah pays off in thinking skills and self-control.

But the mitzvot are not all about prudence.  The mitzvot have a component that transcends prudence.  They have a component of compassion, of honesty, of humility, of yirat Hashem.

Sometimes all these core values overlap with rational self-interest.  But since they are distinct values, there is also a set difference, where following the mitzvot is not the best way to optimize for self interest.  Thus, burial of the dead is called “chessed shel emet”, because the recipient can never repay you.

When the mitzvot call for self-sacrifice, the reward may be in the next world.  When the mitzvot call for prudence, the reward may be(partly) in this world.

Prudence is probabilistic.  Statistically speaking, on average, people who honor their parents do better than those who neglect to do so.  But prudence gives no guarantees.  Tragically, there are those who honor their parents and get hurt nonetheless.  Rebbe Akiva teaches us that these people will be rewarded in the world to come.

Wednesday, August 29, 2012

Shiluach Haken, Part One: Save the Pigeons?

What is the rationale behind the mitzvah of shiluach haken, sending away the mother bird?

The Rambam, in "Guide for the Perplexed", explains that we are enjoined to send away the mother bird as an act of compassion, to spare her the anguish of seeing her children taken away for the slaughter.

This approach strikes me as very strange.  Is sending away the mother bird really an act of compassion?  Does the bird really experience less anguish when she is sent away than when her children are taken before her eyes?  Clearly, she is trying to protect her children -- why does it matter whether you send her away or whether you take the children?

The Ramban, in his commentary on the Torah, gives a different explanation.  He says that by sending away the mother bird, we are saving the species, even as we are consuming the individuals.

So according to the Ramban, “send away the mother bird” should be understood as “spare the mother bird”.  When you find a bird’s nest inhabited by a mother and children, don’t eat all the birds; eat the children, and leave the mother alone.

I like the Ramban’s approach, but I don’t think it should be understood as the expression of a “caretaker” environmentalism, which would enjoin us to protect endangered species for the sake of biodiversity.  I think that the reason we are supposed to protect “species” (really, populations) of kosher birds is so that we will be able to go on eating the individuals.  We are supposed to send away the mother bird so that she can make more baby birds for us to eat.  It’s sustainable hunting, essentially.

Similarly, the original mitzva of "bal tashchit" prohibits cutting down trees under some circumstances, but the prohibition explicitly applies only to trees with human-edible fruit. The Torah is not concerned with botanical diversity, but with sustainable consumption of natural resources. (Thanks to my father for pointing this out!)


The sabbatical year may also be related in part to sustainable farming. The sabbatical year demonstrates the Divine ownership of the land, but it also allows the land to "rest".

Don't get me wrong, though. I don’t mean to say that the Torah is indifferent to the suffering of animals.  The Torah clearly cares about animal suffering.  That consideration has its own dedicated mitzva, “tzaar baalei chayim”, the prohibition of causing needless suffering to animals.  But shiluach haken is not about compassion.  It’s about the tragedy of the commons.

For a more thorough treatment of the intellectual history of shiluach haken, please see the wonderful paper by Rabbi Natan Slifkin, available here: http://www.rationalistjudaism.com/2010/08/shiluach-hakein-transformation-of.html

Wednesday, August 8, 2012

Empricism with a Formalist Face: A Platonic Dialogue by MC Complete

Stewart: Enough of epistemology.  Let’s get down to brass tacks.  What is a number?

Daniel: A number is the outcome of a measurement.  Take the expression “7 + 5 = 12”.  This expression is an empirical prediction (or, if you are a hard core skeptic, an empirical generalization).  I could test it by putting seven apples and five oranges in a basket and counting them.  Counting is an empirical process that yields the result, 12.  The assumption that I started with -- that there are seven apples and five oranges -- means that when I count the apples I get 7, and when I count the oranges I get 5.

Stewart: Hmmm.  Interesting, but doesn’t that just beg the question?  You said “I get 12” -- but what *is* 12?  What do you get?

Daniel: 12 has a written form and an auditory signature, which vary, of course, according to language.  It’s a linguistic token.

Stewart: But that’s formalism.  I thought that you were an empiricist regarding math.

Daniel: It’s formalism with an empiricist heart, or maybe empiricism with a formalist face.  Numbers are linguistic tokens that are the return value of an empirical procedure.  Linguistic tokens are sense data, among other things.

Stewart: Interesting that you drew on deductivism in your last post, which is a branch of formalism.  I see how you’re advocating a compromise position between formalism and empiricism.

Daniel: Compromise?  I prefer to call it The Great Synthesis.

The Empiricist Strikes Back: A Platonic Dialogue by MC Complete

Daniel: Don’t get me wrong, Stewart, I’m not a hard core empiricist.  But they empiricists were right about some things.

Stewart: What do you have in mind?

Daniel: Math, for example.

Stewart: Really?  You think math is the crown jewel of empricism?  Very well then, I’ll play your game.  Tell me, Daniel, what are we to make of the Euclidean postulate that between any two points one can draw a straight line?

Daniel: What’s the problem?  Take out a sheet of paper and a pencil, make two dots anywhere, then connect them.  Bang!  Straight line.

Stewart:  But it’s not a breadthless line.

Daniel: Breadthless?  Who said anything about breadthless?

Stewart: John Stuart Mill.  He said that lines are “limit concepts”.

Daniel: Yeah, that whole “limit concepts” strategy was a big mistake.  Lines aren’t limit concepts.  They’re just very thin.

Stewart: And what about the postulate that all lines can be bisected by a perpendicular line?

Daniel: That’s empirical too -- as long as you interpret it correctly.  What it really means is that all sufficiently long lines can be bisected that way.  Between you and me, if a line is really too short to be bisected, it’s not much of a line, is it?  It’s more of a dot, wouldn’t you say?

Stewart: And what about heartbeats?  How can you empirically justify the proposition that 2 heartbeats plus 3 heartbeats equals 5 heartbeats?

Daniel: That’s easy.  Take an MP3 file with 5 heartbeats.  I can play that file and count 1, 2, 3, 4, 5 -- and then I can play the file again and count 1, 2, 1, 2, 3.

Stewart: And what is 500 red marbles plus 500 blue marbles?

Daniel: Oh, about 1000 marbles, I’d say.

Stewart: “About” 1000?  You seem to have anticipated my line of argument.

Daniel: You were going to say that if I counted the marbles, I probably wouldn’t come up with exactly 1000.

Stewart: Yes, that’s exactly what I was going to say.  How did you know?

Daniel: First of all, I read your book.  Second of all, I’m the one writing the dialogue.  Anyway, here’s my point.  Arithmetic with big numbers, like geometry and arithmetic with continuous quantities, is only approximate.  I mean you have to reinterpret the propositions to be approximate propositions.  So we usually say 500 + 500 = 1000, but what we really mean is 500 + 500 is about equal to 1000.

Stewart: And what about infinity?

Daniel: Infinity?  What’s the big deal with infinity?

Stewart: Well, imagine a universe with only 100 objects.

Daniel: OK.

Stewart: In such a universe, is the proposition “75 * 2 = 150” true or false?

Daniel: Good question.  First of all, let’s agree that the proposition “75 * 2 = 150” is the outcome of applying the arithmetic algorithms.

Stewart: OK.

Daniel: And the arithmetic algorithms themselves work in the Hundredverse -- for all actual quantities that we can test.

Stewart: OK.

Daniel: So the expression “75 * 2 = 150” is kind of an “if then” statement -- it means that if we had a set of 75 objects that we could double, we’d expect the result to be 150.  Since there is no such set in the Hundredverse, the “if” part is not satisfiable.

Stewart: That sounds kind of like deductivism.

Daniel: I think it is a kind of deductivism, but traditional deductivism is agnostic about the justification for the axioms.  I think the justification is empirical.

Stewart: And what is that justification?  Enumerative induction?  The web of knowledge?

Daniel: Neither.  The justification for math is more or less the same as the justification for physics: experiment.

Stewart: But mathematicians don’t do experiments.

Daniel: They don’t need to.  The physicists do the experiments for them.  In order to predict the outcome of a physics experiment you need physics *and* math -- so the success of the experiment justifies both kinds of inputs.

Stewart: And what about mathematical induction?  And the completeness axiom?

Daniel: I’m not smart enough to know if these mathematical tools are used in physics or not, but I would have to go with Quine here.  If they are used in physics, they are justified by the experiments that test them.  If not, they are toys and curiosities.  Of course, sometimes a caterpillar of pleasure can become a butterfly of knowledge.  This happens in physics too, for example in the case of relativity.

Stewart: And you would also go with Quine in rejecting the certainty and necessity of mathematics?

Daniel: Yes.  As you say in your account of Quineinism, “We cannot conceve of 7 + 5 being anything other than 12.  This, however, is a psychological feature of human beings”.