I think the main reason people switch jobs is to have a sense of control over their careers (and hence their lives). I think it’s also the reason (deep down) why people procrastinate. People hate being told what to do. They will tolerate it for a while when they see that they have a lot to gain. For example, you’re almost broke and you’re just starting to build your career and reputation. You will take shitty jobs and put in 100% effort and focus to improve yourself.
Once you reach a level where you can just coast along, it gets boring, and you get dissatisfied that you have to work on something out of obligation.
People have to know that they have the option to leave any time (that leaving is ok, that no one will blame them if they leave, etc).
At the same time, the company should be so good that they don’t want to leave, even though they totally can.
I’m not even sure if this is possible.
When I think about the ideal company (the kind I would want to some day be able to build), I envision a kind of place where people come to learn everything about the craft (of programming) and the ins and outs and creating products, services, and eventually businesses. A place where people come in as juniors and in a few years “graduate” into their own independent businesses.