I'm closer to 60 than 40, and still get paid good money, mostly for my programming skills and hard work. Of course, that means I've been continually retraining myself for nearly three decades now.
Perhaps if I get caught up in this trend someday myself, I will think differently, but for now, I have trouble getting to bent out of shape over it. However I suspect that if I did get such a layoff, I'd be too busy searching out the next job to loose sleep over the motivations of the layoff.
There are still one heck of a lot of people, of all stripes, programming. And it's ok by me if companies understand that they aren't there to keep people employed - they're there to make a profit.
And when I am hiring, the more competition for my openings the better.
If you get laid off you will send out thousands of resumes, get maybe one or two replies and no interviews. After about a year of that you may have a different opinion.