As a software developer for as long as I can remember, I'm actually at the top of my game now in my 40s - I can software engineer (plan) off the top of my head, and my tenacity is balanced with a sense of direction I never had as a younger developer. I spend half the time developing and produce 10 times the results (there's still crunch time every so often though).
The trick is to keep your mind active - I have a job that allows me to do a lot of side development projects outside of working hours, and I always take on a new project at least once a year that is out of my comfort zone (if it looks impossible, it's perfect).