Maybe naive but I don't really see 40s as ageism territory in general. That said, a lot of people adapt. Go into management. More externally facing roles. Different types of companies.
In my 20s I was told 30 is the end of the line. In my 30s I was told its the 40s. Now the bar is higher.
Maybe I'm part of a large enough cohort of programmers that we continually push ageism out, and due to that it will be 'solved' as we hit our 60s and 70s.
The key is probably that you can't be doing at 40 what you're doing at 20. Whether that means better technical skills, better management skills, better communication skills, just better able to navigate a company and the industry...
It probably does mean that, if someone just wants to code, they probably have a higher bar than people interested in doing a more diverse set of things.