I just finished reading Gary Drescher's Good and Real, in which he demystifies a lot of subjects that have long been very muddled. While presenting lucid explanations of physics, time, choice, determinism, and foundations of ethics, he stays well clear of religion through most of the book, touching only briefly in his final chapter:

Finally, many religious individuals attest that their belief in God imparts an optimism that is otherwise beyond reach. This is a subjective matter, but for me the opposite holds. I can accept that we inhabit a world of both splendor and squalor, of comfort and brutality, and that we can work to improve the balance. But if I were convinced that a universe created by an all-powerful, all-loving deity could still be marred by recurrent agony and atrocity, then I would likely surrender in despair. Moreover, the notion that God is necessary for hope implies that life, back in godless reality, is hopeless. But it is not--it most emphatically is not--and I protest both the defeatism that says otherwise, and the escapism that denies the finality of physical reality, for better or worse.

I suspect Gary's wrong here in his counterfactual "if I were convinced..." since if he were to be truly convinced of a religious outlook with an afterlife, he'd do exactly what a lot of religious folk have done: focus all hope of happiness onto an ineffable afterlife, and give up any real hope for this tainted world. If one believes in a perfect, blissful afterlife, then there is no comparable earthly hope available, so the unrealistic dream itself denies the possibility of any other optimism worth having.

Of course, positing an unrealistic ultimate hope in no way blocks the possibility of a realistic optimism--an optimism I share with Drescher.