I'm a programmer in my mid 40s, and sadly I can see that most 40+ programmers generally offer less value to their employers than they did a decade ago. There are reasons for this:
1. Health. This is a big one. By 50 sitting on your ass every work day for 30 years has caught up with you. Hypertension, sleep apnea, diabetes, back pain, etc. You're going to take more sick days, take more time off to see the doctor, and you're going to come to work on drugs that make you tired or a little fuzzy, mentally.
2. Lack of energy. Even if you're healthy at 50 you don't have the same ability to roll with problems that you did when you were 32. You can't put in extra time and maintain productivity. When you get home you don't have the energy to tinker with technical stuff just for the fun of it.
3. Cognitive decline. Nobody likes to think about this, but the reality is for most people cognitive decline starts in your 30s. By 50 it's affecting your productivity. Things that you used to remember for as long as it mattered (like file, class, or machine names) you have to write down now. It takes longer to pick up new technologies and you forget them faster. This translates into lower productivity. Maybe a little lower, maybe a lot.
So even though I'm getting to the age where it affects me, I don't blame companies and individuals for their reluctance to hire older guys. It's based on real-world considerations. If I get laid off will I be able to find another programming job? Probably, but it's going to be a lot more difficult than it would have been 15 or 20 years ago.
I refuse to be bitter about it, though. I had my chance to go into management and decided to keep writing code, even though I knew things would get dicey later.