This really seems like a detail that should be emphasized. One famous man uttered a very quotable line that was more reflective of his mood at the time than of some universal truth. I don't get how the culture of science sometimes has this tendency to fetishize things like youth or pedigree. I guess it's the classic fallacy of confusing averages with maximums or of thinking that summary statistics preclude the possibility of individuals with unusual characteristics.
Makes all of us (since we will all be 30+ one day if not alright) happy to know that Einstein wasted a lot of time trying extremely hard to disprove quantum mechanics because "God doesn't play dice with the universe."
I think you'll find many mathematicians agree with it.
For example, The Abel Prize [1] does interviews with their award winners every year and quite often they are asked about this question, and most of them agree that as a mathematician your peak "mathematical powers" so to speak and energy are at their highest in your 20s and 30s, while afterwards you have to rely more on experience to make up for it as you grow older.
Curious how much of this is truth. I am sure in your 20s or 30s your brain functions better per say, but how much decline is there really and how fast? And surely experience does make up for it in most fields.
I read Hardy's book when I was in my late 20s, as an aspiring scientist. I do remember coming across this quote and thinking it did not apply to software. Last forward 20ish years, and I think it is absolutely true for me. I used to be a code monk/guru in my younger days .. having responsibilities has truly blunted this. The opportunity cost of any project feels too much. Beyond that, I feel I am less foolish and this is problematic. In my younger days, I was code first, and think later. This resulted in things getting built and iterated on. Now, I think a bit too much and this slows down (or completely eliminates) the building part. I also remember a quote from John Carmack about how with unlimited pizza and soda, you can build anything. This felt so true in my teens and 20s .. just not attainable for me now. I think having a somewhat high salary has something to do with it too (it makes one scared) to go on adventures. I think none of my points generalize beyond myself but something feels broken inside me ... maybe just burnout from tough jobs, responsibilities, etc. If anyone has insight on how to overcome, I'm all ears.
There's a quote, usually attributed to Einstein: "the only difference between genius and stupidity is that stupidity has no bounds." As you said, you've put limits on yourself to keep yourself from being stupid.
Remove your limits and you'll be as productive (if not more productive) than any 20-something, though you'll probably do stupid things from time-to-time. Don't be afraid of being stupid, after all, it has no bounds... :p
In all seriousness though, just spend an afternoon coding something you wouldn't normally code without thinking about it first. As you get older, it's harder to just cowboy code something without stopping to think about it. With some practice, you can bang out some pretty high quality code very quickly. And then you'll eventually learn when to cowboy it and when to think.