As a software developer approaching mid-forties I'm keenly following this question on Quora about older programmers losing interest. For those that don't know, Quora is a question and answers site that that I enjoy reading, though in my opinion it really shouldn't be asking people to log in to view things (didn't that die out in the nineties?)
Do people lose interest in programming as they age
At times I've felt like I was losing interest but it always came back. Stresses of family and work life play a big part in your declining "mojo" but when things get back on an even keel, if you ever had a passion for it at all, you will rediscover it. Disinterest and frustration in office politics or being the victim of bad management can seriously dampen your enthusiasm and make you think you no longer enjoy what you do but that's an environmental factor and one you can change if necessary.
I could happily program all day for myself but it can be a chore to do it for a company, especially if that company is one where software is but a means to an end and not its reason d'être (or "core domain" to borrow a DDD phrase). The truth is, you can lose interest in any subject at any age.
I think the trick to keeping the flame alive is:
a) to take a break from time to time
b) learn to filter out the office negativity
c) find new things to learn.
Personally, I struggle with a and b far more then c.
polyglot programmer - passionate, opinionated, cynic, realist