Rants on software, computing, and any other topic I feel like.

Tuesday, February 22, 2011

Science and Religion

Recently the following article appeared over at Cosmic Variance, a blog I follow. Theologians Lobby Successfully to Change Definition of Evolution Some theologians (Cornell's Huston Smith and Notre Dame's Alvin Plantinga specifically) asked that the following definition of evolution used by the National Association of Biology Teachers be modified to remove the words "unsupervised" and "impersonal".

The diversity of life on earth is the result of evolution: an unsupervised, impersonal, unpredictable and natural process of temporal descent with genetic modification that is affected by natural selection, chance, historical contingencies and changing environments.

I think it's a good idea. I believe in science, I believe in religion and I believe in evolution. But I have a hard time understanding why it’s so important to some scientists to make sure that not only do we not mention God in science, but we must specifically reject him outright. I agree that there is no evidence that God is there. If there were evidence, then it would be pretty easy to believe in God. I’ll accept that. I don’t expect you to believe in God. But since there is also no evidence that he doesn’t exist, then I expect science to leave the topic alone. Let the Atheists discuss the absence of God. Science is about evidence, not belief.

I believe in science because I believe that science is a valid and useful way to discover things about the world. It’s been astoundingly successful at doing so. I don’t feel I can reject it, nor do I want to. I benefit from it every day.

I believe in religion because I believe that religion is a valid and useful way to discover things about the world. I believe that spiritual experiences are real and I can reconcile them with the things I learn from science. It may not be in the way that some scientists may think I should, but I do it all the same.

I believe in evolution because science has shown that there’s little chance that it happened any other way. I’m not going to reject the evidence that is clear as day. However, just like a scientist cannot reject “uncomfortable” evidence when it contradicts a pet theory, I cannot reject my spiritual experiences. They are as real to me as any evidence that science can provide. Are they perhaps nothing more than my brain being affected by too much dopamine? Perhaps. And I may reject them if sufficient evidence is presented to me. But sufficient evidence has not been presented to me. So, until that time, I must reconcile the evidence with which I am presented.

Just because I see some conflicts between science and religion doesn’t mean that I reject either one. General Relativity and Quantum Mechanics have conflicts. I don’t just blindly throw one out. They both have some of the truth. One day, we’ll understand how they fit together. I’m okay with some conflicts. I know they’ll be resolved eventually.

But I do expect you to state conclusions based on good evidence. There is no evidence that God didn’t have some small hand in the evolutionary process. Perhaps evolution is the mechanism by which he created a diverse ecosystem on this planet. That’s what the theologians are asking for. The National Association of Biology Teachers is overstating what science knows about evolution.

The words unsupervised and impersonal are quite problematic. “Unsupervised” implies the absence of some intelligence involved. Well, what is intelligence? Once humans showed up did evolution stop? We can discuss a number of situations where humans had a clear hand in the evolutionary process. What about other possibly intelligent animals? How much intelligence do you need before you’re a “supervisor”? And “impersonal”, which would mean that no person was involved. Well, since humans didn’t show up until pretty late in the game, that’s sorta obvious, but has the same problems as “unsupervised”.

I’m really getting tired of two things in the scientific community. One, the alliance with the atheists which some in science seem to think is the only way it can be. Science and religion can coexist peacefully you know. And two, the accusations of stupidity at anyone who doesn’t accept everything a scientist says without question. I understand you’ve studied your field in more depth than anyone else, but that doesn’t alleviate the need to explain your reasoning to those you’re speaking with.

When I have a scientific discussion, I don’t bring my religion into it since it’s irrelevant to everyone else. Some scientists are atheists and they should do the same. Scientific statements should be scientific. There’s no place for statements that God doesn't exist when there’s no evidence for that statement. If we want the world to accept evolution, then please stop overstating the case for it. The evidence is convincing enough without saying things we don’t really know.

"Is there any conflict between science and religion? There is no conflict in the mind of God, but often there is conflict in the minds of men." — Henry Eyring, developer of the Transition State Theory of Chemical Reactions

Labels: ,

Thursday, February 17, 2011

Calling a constructor or destructor without an object

Now, I have no idea why you'd actually want to call constructors or destructors without an object, since they're really normally meant to be called with objects, but it's something interesting I thought I'd share. It turns out that constructors and destructors aren't really that special in C++. They're just regular functions like almost anything else and can be called that way. You just need to know how to do it.

I'll start with destructors, which may seem backwards, but doing this with destructors is actually easier than with constructors. It's not that much easier, but it makes a bit more sense. Let's start by calling a destructor with an object. We'll get to the no-object case next.

To call a destructor if you have an object, well, just call it:

struct A {
A() { cout << "A()" << endl; }
~A() { cout << "~A()" << endl; }

void main()
A a;
a.~a(); // just call it like anything else

So how do we do this without an object? We need to think about what happens when any member function is called. When the compiler compiles a member function call, all it does differently from a normal function call is to add a pointer to the object as an extra parameter (at the begining) and call the function normally. Now certain compilers even use a different calling convention, but in the end, it's just a modified function call.

So can we get the compiler to make that function call, but not require a real object to pass in? Of course:

A* a = NULL;

or more compactly:


Now, as long as nothing in the destructor actually tries to access the this pointer (by accessing data members for example), then all is well. The destructor is called and no object was ever created.

What is this useful for? I have no idea, but one thought that I had centered around one particularly special behavior of destructors. They automatically call the destructor of the parent class. Every other type of member function doesn't do this. Parent class versions of functions much be explicitly called. In some cases, this can be frustrating, especially in template classes where the parent class may be hard to determine.

In order to call a constructor without creating an object, we can use a special feature of C++ rarely seen outside of things like STL and embedded code, placement new. Placement new is just like new, except that it doesn't allocate memory for you. It leaves the memory allocation up to the programmer. Here's what it looks like normally.

void* ptr = malloc(sizeof(A));
A* a = new (ptr) A();

The syntax is a little funny, but that's okay. All we're doing there is calling the constructor member function using our own pointer (ptr) for the this pointer instead an automatically generated one.

So, using the same trick of using NULL instead of a valid pointer as we did with the destructors, we can do the same with constructors:

A* a = new ((void*) NULL) A();

Except it doesn't work. At least with gcc. The constructor never is called since the this pointer is NULL. Well, no worries, we're not trying to actually do anything with the this pointer, so we just need to pass in something that the compiler thinks is good.

A* a = new ((void*) 1) A();

Let's get rid of the assignment, since we're not going to use that pointer anyway.

new ((void*) 1) A();

And voila, we're calling constructors. No object needed.

One key point here that should be repeated is that none of this will work on destructors or constructors that actually try to dereference the this pointer in any way. The most obvious time this is done is when accessing data members. Another is calling virtual functions, since the virtual function table will need to be referenced. Also, any class hierarchy that includes virtual inheritance won't work since that mechanism uses the this pointer as part of knowing what destructor to call.

Labels: ,

This page is powered by Blogger. Isn't yours?