Unfortunately, becoming a developer is a short-term optimal choice that you pay for in the long term.
The 40-year-old physicist has tenure and can work on whatever he wants. As far as his peers are concerned, he's mid-career. The 40-year-old programmer is considering plastic surgery so he can still get hired in the Valley.
The people who become developers find out that they don't have permission to get a day older than 35 unless they can make it into management. And if you were going to be a manager anyway, you might as well have gotten an MBA in your mid-20s, and then you'd be making far more than the developer would even dream of.
Coding was always way more fun than doing 4th year/grad school level physics for me too.
Programming is a lot of fun, but most software jobs aren't programming intensive. The coding is trivial and a high school student could do most of the work. The hard part is dealing with tickets, PMs, and unnecessary meetings.