I may as well pre-emptively tag this as flamebait, but I will throw out some honest dissent to the idea of (old) age discrimination being as overwhelming as it's portrayed.
I've been in software for 17 years and I have not personally witnessed a single incident of it - not even if I put on my easily-offended hat and really stretch for something that could be interpreted that way. Not a comment during a candidate review, not even an offhand water-cooler crack about "old folks" or whatever. That's obviously not because we engineers are angels - I have heard many, many inappropriate things. But *zero* were ever about being too old, nor have I ever seen any unstated pattern were older engineers were tarred as "not a culture fit." The reverse is not true - it is so common to reject inexperienced candidates that many feel comfortable saying someone is "too young" completely out in the open.
So, where is all of the anti-gray sentiment that I'm repeatedly told is lurking in my future? 40 is on the horizon and I am only in ever-greater demand as an individual contributor thanks to my full-stack independence and the dramatic vacuum of good engineers. In all hiring processes I've ever seen, we were so desperate for anyone with a hair of common sense and reasonable skills that we would have taken someone with three heads if they could crank out good product.
Any reasonable person would be suspicious, given this experience, that all this talk of age discrimination is less of a real problem than an exercise in trying to blame others for letting one's skills fall out of date and becoming un-hireable. True, a young engineer will never get rejected for knowing only COBOL - but there's no excuse for a graying one to have that problem either. If anything, good older engineers should be *more* up-to-date because they can learn new technologies faster (having learned so many before), and are more abreast of useful trends (because their experience lets them discern fads from real evolution).
I feel no pressure to move into management, and plan to code until I am no longer physically able, or financially required, to do so. My advice: double, triple and quadruple down on being the absolute best at what really gets you fired up, and you'll always have a cubicle with your name on it. That's definitely more fulfilling (and often more lucrative) than being a Dilbert-style manager who's only going through the motions.