Quoting the book,
Why is programming fun? What delights may its practitioner expect as his reward?
First is the sheer joy of making things. As the child delights in his mud pie, so the adult enjoys building things, especially things of his own design […]
Second is the pleasure of making things that are useful to other people. Deep within, we want other to use our work and to find it helpful. […]
Third is the fascination of fashioning complex puzzle-like objects of interlocking moving parts and watching them work in subtle cycles, playing out the consequences of principles built in from the beginning. […]
Fourth is the joy of always learning, which springs from the nonrepeating nature of the task. In one way or another the problem is ever new, and its solver learns something: sometimes practical, sometimes theoretical, and sometimes both.
Finally, there is the delight of working in such a tractable medium. The programmer, like the poet, works only slightly removed from the pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination. Few media of creating are so flexible, so easy to polish and rework, so readily capable of realizing grand conceptual structures. (As we shall see later, this very tractability has its own problems.)
Frederick P. Brooks, Jr in the “The Mythical Man-Month”
Update: J.M. Beas did an awesome take on this subject on his blog (Spanish)