Here’s something I think a lot of people don’t think on: 40 years old is mid-career. If you expect to retire at 60 (likely 65 these days) and you start working at 20: 40 is smack dab in the middle of your career. I think that notion gets lost when we talk about ageism in tech and then people talk about 40-somethings.
A lot of programmers who are 35+ can struggle to find further opportunities as the more senior you are the less available those opportunities are and the more expensive you are. Lots of companies only want young people who are naive and have limited distractions outside of work. So, really, programming as a field is front loaded and the longer you stay in the business over 35 then the luckier you have been. But make…
The older I get, the more I think it is not the company itself but middle-managers.
Managers with an authoritarian streak will have trouble handling experienced developers that objects to non-optimal designs and processes.
It is much easier for such a manager to handle young naïve developers that gladly accept to work 5 times as many hours as a good design needs.
Software don't work well with an "do as I say, no matter how stupid it is" approach. I think that is why Silicon Valley (and Europe) has much greater success writing software than asia/India.