This is why open source software at least is good -- it tends to have much longer lifetimes, so chances are decent that your code will still be running decades down the line (so long as you picked the right project).
For example, one of the open source projects that I contributed to most heavily, PyWikiBot, has been around for almost two decades now, and most of my contributions were made ~13-15 years ago, plus some minor maintenance since then, and most of those features I wrote are still in continuous use to this very day by me and many others. And that's just some random tooling library for Wikipedia stuff; imagine how much long-term impact your work would have if you were editing MediaWiki itself, or the Linux kernel, or gcc, or any number of other incredibly widely-used things.
For example, one of the open source projects that I contributed to most heavily, PyWikiBot, has been around for almost two decades now, and most of my contributions were made ~13-15 years ago, plus some minor maintenance since then, and most of those features I wrote are still in continuous use to this very day by me and many others. And that's just some random tooling library for Wikipedia stuff; imagine how much long-term impact your work would have if you were editing MediaWiki itself, or the Linux kernel, or gcc, or any number of other incredibly widely-used things.