Great write-up on that subject is in the first chapter of "Mythical Man-Month". Here is small excerpt. 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. I think this delight must be an image of God's delight in making things, a delight…
...that has nothing to do with the problem in my opinion.
Yes, programming is fun in general but then you come in touch with the reality of the job only to find out once again that
1. you are not making things, most of the time you maintain some old crap because nobody wants to spend time and money on building a new better version etc
2. The thing you are working on is useful but you can't really tell how. The damn thing is so big that all your input after years of work is almost invisible to anyone, even on your team
3. Library here, framework there and most of your own code is just a clever way of putting them together. Fascinating at the beginning, a boring routine a few years later
4. okay, sure, that's enjoyable, sometimes too much.
5. Again - works in theory, breaks after the next meeting. "No time to rework and polish. It works somehow and generates money, so go help those guys finish their work. Bad architecture? Hard to maintain? No matter, management sees only frontend anyway"