Where I live (Norway), these laws came thanks to unions. When I graduated, all developer jobs I was offered had a noncompete clause in the contract. These were wide and potentially career-altering if enforced, barring you from doing basically any kind of work for long stretches of time. All companies when pushed basically said "ohh, we seldom enforce them, only for upper management", but still they insisted on them being there.
Luckily my union, Tekna, helped squish most of these in 2015. They can no longer be general, they have to name specific companies and areas you can't work for if you ask. And pay full salary while enforced. So now they're basically non-existent for individual contributors / devs, except for maybe naming the main competitor if you work for a niche company.