What is the function of religion?

Recently this article touched off a furor for its author.

I consider it to be a very well thought-out dissection of why people cling to the power of religion. Essentially people are motivated by tribal identity and a need to belong - even when the entry costs for belonging are irrational, sadistic, and/or evil.

To be fair, I think he runs a bit to vitriolic success at the end, but the interesting idea that snagged my attention is this parallel:

We want the benefits of scientific progress, but are afraid to leave behind the voodoo dolls, sense of belonging and legitimation that religion offers. In parallel Friedman suggested that the sense of cognitive dissonance in Islamic culture hinges on “We want to be powerful, yet we fear outside influence” (not realizing that playing well in the outside world is the secret to economic and political power in our age).

As the author said: Wanting our cake and eating it too.