Archive for October, 2009

Book Review: Medical Ethics: A Very Short Introduction

Friday, October 30th, 2009

medical_ethicsThe “Very Short Introductions” series is by and large very good, but I have two concerns. Firstly, books in the series are often more strongly opinionated than one might like in a general introduction.

Secondly, I worry that the books don’t really form introductions to a subject at all, but rather “bluffer’s guides”, that are the first and last book a person picks up on the subjct. To pick one subject I’m reasonably familiar with, I have a long-standing suspicion that teaching mathematics to a casual audience is worse than useless. Even when the reader is an active student of the subject, these books can be used to bypass study rather than to inspire it (at least according to anecdotal evidence from my fellow students).

Happily, neither of these concerns is a significant problem for Medical Ethics: A Very Short Introduction. The author allows his opinions to show through, but is admirably even-handed, even generous in setting out contrasting views.

As regards being an introduction to the subject, this book fulfils its remit very effectively. The area covered is broad enough, and the background information great enough, that the book does little more than scratch the surface on important topics such as euthanasia, genetics and mental health. The necessary background in logic and philosophical rigor isn’t neglected either, with a brief section cleverly slipped in once the reader’s appetite has been whetted by a few philosophical conundrums.

I have very little to criticise about this book. It did feel terribly constrained in what it covered, and stylistically it felt like a longer book cut short to fit the publisher’s requirements rather than a perfectly-turned short book. No sooner had I started to get interested in a topic than the chapter ended—but then of course this is exactly what an introduction should be.

Closures in the real world: Part 3

Wednesday, October 28th, 2009

After I wrote my last post about closures, I was fairly clear about how a closure can extend the lifetime of an apparent stack variable:
Closures

What looks like a stack variable isn’t actually a stack variable, it’s an implicit reference to a member variable on an implicitly-defined class representing the closure.

But then another question occurred to me. Closures can extend the lifetime of an otherwise stack-local value type because the value itself lives in the closure and is referenced in the local stack frame. But what if the same variable is referenced in two different closures? Which closure object gets to own the variable, and which gets a reference?

Consider the following example (the same principle applies to my previous example, but this makes the point clearer):

class Program
{
   private static Func<int> MakeAClosure()
   {
      int x = 0;

      Func<int> incrementByOne =
         delegate()
         {
            x += 1;
            return x;
         };

      Func<int> incrementBySix =
         delegate()
         {
            x += 6;
            return x;
         };

      Random rnd = new Random();
      if ((rnd.Next() % 2) == 0)
      {
         return incrementByOne;
      }
      else
      {
         return incrementBySix;
      }
   }

   static void Main(string[] args)
   {
      Func<int> myFunc = MakeAClosure();

      for (int i = 0; i < 10; i++)
      {
         Console.WriteLine("{0}", myFunc());
      }
   }
 }

In this case, two closures are constructed. The apparent stack variable x is not a stack variable, but a reference into one of the closure objects. But which one? The compiler doesn’t know which closure will be returned until runtime, and in any case changes made in one closure (or on the “stack”) ought to affect the other closure.

This diagram shows how things worked in my head, and illustrates the problem:

Closures2

Fortunately, you can see what’s really happening without too much digging into the disassembly:

disassembly

The ugly naming doesn’t help, but note that within the Program class there is a nested class <>c__DisplayClass2.  As we saw before, this is the way that closures are implemented. However, the crucial thing is that there’s only one class at work here, and it holds both closure functions within it (they are the functions called <MakeAClosure>b__x). The fact that we’re returning one of a possible two different closures is actually an illusion: whatever return condition happens we return the entire class and both closure functions. Presumably we somehow also return some sort of reference indicating which of the functions to call when the closure is dereferenced later.

Nick Griffin on Question Time

Saturday, October 24th, 2009

Before I make any comment about the recent events involving the British National Party, I should make it clear where I stand: I do not support the BNP. I believe that many of the claims made by Nick Griffin (for example, holocaust denial) are factually incorrect. I do not believe that their policies offer any substantive solutions to the problems facing our country, and many of their policies would be actively harmful to our society.

Having said that, I’m saddened to see people who would presumably describe themselves as liberals fighting with the police in order to prevent a politician from speaking his mind. It seemed a shame that some of the people who had applied to be in the audience of Question Time (which is after all a debate programme) were unwilling to let Mr. Griffin speak in his turn without shouting him down.

At the very least, Mr. Griffin’s brand of clearly-worded racism can be answered directly, as I believe it should be. This is in contrast to the “dog-whistle” crypto-racism that marred the last UK election, and which may well still exist in parts of the mainstream parties.

What bothers me most about the whole affair is the lack of faith in open debate that has been displayed by some of those on the left. Is the ideal of free speech really so easily abandoned? Do people not believe that, when ideas are pitted against one another in debate, that the right idea will win out and that both sides can be enlightened? If we are secure in our belief that racism is wrong, why can we not back our ideas up calmly and rationally, by pointing out the flaw in their arguments?

Postscript

A few hours after writing this, I stumbled across the following quotation, which seemed apposite:

Let me add a certain virile reply recorded by De Quincey (Writings XI, 226). Someone flung a glass of wine in the face of a gentleman during a theological or literary debate. The victim did not show any emotion, and said to the offender: “This, sir, is a digression: now, if you please, for the argument.” (The author of that reply, a certain Dr. Henderson, died in Oxford around 1787, without leaving us any memory other than those just words: a sufficient and beautiful immortality.)

J. L. Borges, The Art of Verbal Abuse, 1933