While I’ve no doubt that age discrimination does exist, when you see people who are former programmers at 40 (or 30 for that matter) it’s often just that they started out in programming but got bored of it and moved on to other careers. Or gradually became managers rather than programmers.
Statistics may certainly show that programmers skew young, but its not always due to being forced out, or denied opportunities, because of age.