It's simply not true that middle-aged developers have a hard time finding work due to rampant ageism. If you have advanced skills building high-quality software with technologies that are in demand, your age hardly matters. The smart employers value engineers with years of experience who are more likely to create good products and not make costly mistakes. I've been working for almost 20 years as a professional developer, am now 41 and making the best money of my career developing financial tools for a major investment bank.
Development teams doing high-profile projects that get media attention (as opposed to boring, routine stuff like telecom databases, retail POS terminals, embedded SW for consumer devices, etc) do tend to have more developers who are in their mid-30s or younger. This is generally not because of age bias, it's more likely because younger developers are most familiar with the latest languages and tools. Startups also tend to have young developers since they are more OK with high risk/high reward deals and long hours, and haven't had as much opportunity to get into engineering careers with big companies. Also, after a few decades in the field, many developers eventually get tired of endlessly staring at computer screens and learning new skills every 5-10 years. They move up into management or start new careers. A well-educated, hard-working engineer can easily move into many other less demanding career tracks including finance/investing, marketing, HR, real estate, and non-technical corporate jobs.