Your average working programmer isn't retiring at 50, and your brain works just fine at that age. Is this some Silicon Valley cult of youth thing? At my boring old German company I'd say a third of the devs is over 50 or close to it, they're gonna work till retirement like everyone else and they write good code. Hell, you're still physically fit at that age if you take care of yourself. You may not be able to pull five all-nighters in a row, but you're not decrepit just yet lol.
Btw John Carmack is 52 already and the man seems to have the energy of an entire engineering team. I think some people really let age get to their own head.