It's like the infield fly rule - seems simple enough, then you think about it and you get a little cross-eyed.
Basically, under normal circumstances, if you want to raise the person who bet out, your raise must equal their bet/raise. So if someone bets or raises $10.00, you can't raise $5.00. you can raise 10 to your whole stack. If you call, the original raiser doesn't get a chance to bet again until the next card is out, so if they didn't raise enough to knock you off a draw, that's their problem.
You can't prevent someone from going all in, though, even if they don't have enough to make a legitimate raise. So, in your scenario, all they could do is raise another $5.00, even though the rule is that you have to raise another $20.00. They can put the $5.00 out, but it is not a raise. The bet becomes $25.00, though and everyone has to match that to stay in the hand. Later betters can still raise if they want, and the dealer will have to make a sidepot. If the original better was thinking, "if anyone comes over the top of this bet, I'm shoving it all in", then he's out of luck, because there was no raise.
The half bet rule and the full bet rule are the same thing, but with different amounts constituting the raise. In your scenario, if the all in had exactly $40.00 and push it it all in, that would be a $20.00 raise and anything less would not be a raise. With the half bet rule, it's a raise if it is half a bet, or $10.00, so if he had $30.00 and that rule was in effect, then he could raise.
The strategy beyond the rules, if there is one, is that you should know what your opponent's stack size is, and you should bet accordingly. Don't bet $20.00 into a $25.00 stack expecting them to raise the additional $5.00 so you can come over the top. Either put them all in with a big enough bet to isolate them or make a bet that is small enough so that when they go all in, it constitutes a raise, and you can come over the top and maybe shove out the other players at the table or build a large side pot, or whatever you are trying to accomplish there.
FWIW, one of the home games I play at totally ignores the raising rule altogether, and I have seen people raise one dollar into a $12.00 bet. WTF. Seriously.