All the above. Derailleur gears have many virtues but being able to change gear when not moving is not one of them. Changing down on the rear cassette involves the chain climbing on to a bigger sprocket with more teeth so needs the wheel to be turning freely. If you have two or more chainrings on the front and you stop with the chain on one of the bigger ones it is theoretically easier to change down at the front when you lift the back wheel as the chain is dropping on to a smaller cog assisted by the derailleur chain tensioner. It still needs a bit of coordination whichever way you do it.
If you get into the habit of spinning rather than stomping the pedals you are more likely to be in a lower gear so less likely to be caught out. As mentioned above, a bit of anticipation goes a long way, and after a while you will just get into the habit of knocking it down a gear or so before you stop, or reading the road so you are already in a low enough gear to keep going on an approaching hill. Even experienced cyclists might get caught out by short sharp hills on an unfamiliar winding road, or a vehicle stopping unexpectedly to let an unseen cat cross the road but these become rarer as you get used to your gear system. It's mostly about anticipation.