Choosing between Shanty Town and Village when both are in the Kingdom set?
First, you have a mistake in your question: Shanty can give +2 cards, but sometimes it will only give zero (not the 1 that say in your second sentence).

1) In a standard village+draw engine, the vanilla Village is more useful because you will expect to have other actions in your hand, and so Shanty Town's bonus won't trigger.

2) If there are lots of non-terminals or an easy way to spam +Actions, then Shanty Town becomes more powerful because you have the ability to play the remaining actions in your hand and then use Shanty to trigger the draw.

3) Shanty is useful in early turns for increasing cycling. Shanty Town + Potion is a great opening for Apothecary or University games (less so for Scrying Pool because you'll eventually have lots of actions and not necessarily +Action cards).

4) Finally, Shanty is solid in plain Big Money games. If you have only one or two Shanty Towns in your deck, it is almost guaranteed to be a Lab (which is a $5 card).